add: show more certificates on the "roots" page
[gigi.git] / tests / club / wpia / gigi / pages / admin / TestSEAdminNotificationMail.java
1 package club.wpia.gigi.pages.admin;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
5
6 import java.io.IOException;
7 import java.io.PrintWriter;
8 import java.io.StringWriter;
9 import java.net.MalformedURLException;
10 import java.net.URLEncoder;
11 import java.util.HashMap;
12 import java.util.Locale;
13
14 import org.junit.Test;
15
16 import club.wpia.gigi.GigiApiException;
17 import club.wpia.gigi.dbObjects.Group;
18 import club.wpia.gigi.dbObjects.User;
19 import club.wpia.gigi.localisation.Language;
20 import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage;
21 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
22 import club.wpia.gigi.testUtils.ClientTest;
23 import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
24 import club.wpia.gigi.util.ServerConstants;
25
26 public class TestSEAdminNotificationMail extends ClientTest {
27
28     private int targetID;
29
30     public TestSEAdminNotificationMail() throws IOException, GigiApiException {
31         grant(u, Group.SUPPORTER);
32         cookie = login(email, TEST_PASSWORD);
33         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
34
35         String email = createUniqueName() + "@example.com";
36         String fname = "Först";
37         String lname = "Secönd";
38         targetID = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
39     }
40
41     @Test
42     public void testChangeAccountData() throws MalformedURLException, IOException {
43
44         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "dobd=1&dobm=2&doby=2000&detailupdate", 0);
45
46         // mail to support
47         String message = getMailReceiver().receive().getMessage();
48         assertThat(message, containsString("The DoB was changed"));
49         assertThat(message, containsString("supporter " + u.getPreferredName().toString() + " triggered:"));
50         // mail to user
51         message = getMailReceiver().receive().getMessage();
52         assertThat(message, containsString("The DoB in your account was changed to 2000-02-01."));
53     }
54
55     @Test
56     public void testPasswordReset() throws MalformedURLException, IOException {
57         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "aword=SecretWord&resetPass", 0);
58         TestMail tm;
59         String targetMail = ServerConstants.getSupportMailAddress();
60         do {
61             tm = getMailReceiver().receive();
62         } while ( !tm.getTo().equals(targetMail));
63         assertThat(tm.getMessage(), containsString("A password reset was triggered and an email was sent to user."));
64     }
65
66     @Test
67     public void testGrantUserGroup() throws MalformedURLException, IOException {
68         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDBName(), "UTF-8"), 0);
69
70         StringWriter sw = new StringWriter();
71         PrintWriter pw = new PrintWriter(sw);
72         Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
73
74         // mail to support
75         String message = getMailReceiver().receive().getMessage();
76         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
77         // mail to user
78         message = getMailReceiver().receive().getMessage();
79         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
80     }
81
82     @Test
83     public void testRemoveUserGroup() throws MalformedURLException, IOException {
84         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDBName(), "UTF-8"), 0);
85
86         StringWriter sw = new StringWriter();
87         PrintWriter pw = new PrintWriter(sw);
88         Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
89
90         // mail to support
91         String message = getMailReceiver().receive().getMessage();
92         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
93         // mail to user
94         message = getMailReceiver().receive().getMessage();
95         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
96     }
97
98     @Test
99     public void testGrantSupporterGroup() throws MalformedURLException, IOException {
100         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDBName(), "UTF-8"), 0);
101
102         StringWriter sw = new StringWriter();
103         PrintWriter pw = new PrintWriter(sw);
104         Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
105         User target = User.getById(targetID);
106
107         // mail to support
108         String message = getMailReceiver().receive().getMessage();
109         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
110         // mail to user
111         message = getMailReceiver().receive().getMessage();
112         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
113         // mail to board
114         message = getMailReceiver().receive().getMessage();
115         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted for '" + target.getPreferredName().toString() + "'."));
116     }
117
118     @Test
119     public void testRemoveSupporterGroup() throws MalformedURLException, IOException {
120         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDBName(), "UTF-8"), 0);
121
122         StringWriter sw = new StringWriter();
123         PrintWriter pw = new PrintWriter(sw);
124         Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
125         User target = User.getById(targetID);
126
127         // mail to support
128         String message = getMailReceiver().receive().getMessage();
129         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
130         // mail to user
131         message = getMailReceiver().receive().getMessage();
132         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
133         // mail to board
134         message = getMailReceiver().receive().getMessage();
135         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked for '" + target.getPreferredName().toString() + "'."));
136     }
137
138     @Test
139     public void testRevokeAllCertificates() throws MalformedURLException, IOException {
140         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "revokeall", 1);
141         User user = User.getById(targetID);
142
143         // mail to support
144         String message = getMailReceiver().receive().getMessage();
145         assertThat(message, containsString("All certificates in the account " + user.getPreferredName().toString()));
146         // mail to user
147         message = getMailReceiver().receive().getMessage();
148         assertThat(message, containsString("All certificates in your account have been revoked."));
149     }
150 }