1 package club.wpia.gigi.pages.admin;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
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;
14 import org.junit.Test;
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;
26 public class TestSEAdminNotificationMail extends ClientTest {
30 private String targetEmail;
32 public TestSEAdminNotificationMail() throws IOException, GigiApiException {
33 grant(u, Group.SUPPORTER);
34 cookie = login(email, TEST_PASSWORD);
35 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
37 targetEmail = createUniqueName() + "@example.com";
38 String fname = "Först";
39 String lname = "Secönd";
40 targetID = createVerifiedUser(fname, lname, targetEmail, TEST_PASSWORD);
44 public void testChangeAccountData() throws MalformedURLException, IOException {
46 executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "dobd=1&dobm=2&doby=2000&detailupdate", 0);
49 String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
50 assertThat(message, containsString("The DoB was changed"));
51 assertThat(message, containsString("supporter " + u.getPreferredName().toString() + " triggered:"));
53 message = getMailReceiver().receive(targetEmail).getMessage();
54 assertThat(message, containsString("The DoB in your account was changed to 2000-02-01."));
58 public void testPasswordReset() throws MalformedURLException, IOException {
59 executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "aword=SecretWord&resetPass", 0);
60 getMailReceiver().receive(targetEmail);
61 TestMail tm = getMailReceiver().receive(ServerConstants.getSupportMailAddress());
62 assertThat(tm.getMessage(), containsString("A password reset was triggered and an email was sent to user."));
66 public void testGrantUserGroup() throws MalformedURLException, IOException {
67 executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDBName(), "UTF-8"), 0);
69 StringWriter sw = new StringWriter();
70 PrintWriter pw = new PrintWriter(sw);
71 Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
74 String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
75 assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
77 message = getMailReceiver().receive(targetEmail).getMessage();
78 assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
82 public void testRemoveUserGroup() throws MalformedURLException, IOException {
83 executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDBName(), "UTF-8"), 0);
85 StringWriter sw = new StringWriter();
86 PrintWriter pw = new PrintWriter(sw);
87 Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
90 String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
91 assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
93 message = getMailReceiver().receive(targetEmail).getMessage();
94 assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
98 public void testGrantSupporterGroup() throws MalformedURLException, IOException {
99 executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDBName(), "UTF-8"), 0);
101 StringWriter sw = new StringWriter();
102 PrintWriter pw = new PrintWriter(sw);
103 Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
104 User target = User.getById(targetID);
107 String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
108 assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
110 message = getMailReceiver().receive(targetEmail).getMessage();
111 assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
113 message = getMailReceiver().receive(ServerConstants.getBoardMailAddress()).getMessage();
114 assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted for '" + target.getPreferredName().toString() + "'."));
118 public void testRemoveSupporterGroup() throws MalformedURLException, IOException {
119 executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDBName(), "UTF-8"), 0);
121 StringWriter sw = new StringWriter();
122 PrintWriter pw = new PrintWriter(sw);
123 Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
124 User target = User.getById(targetID);
127 String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
128 assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
130 message = getMailReceiver().receive(targetEmail).getMessage();
131 assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
133 message = getMailReceiver().receive(ServerConstants.getBoardMailAddress()).getMessage();
134 assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked for '" + target.getPreferredName().toString() + "'."));
138 public void testRevokeAllCertificates() throws MalformedURLException, IOException {
139 executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "revokeall", 1);
140 User user = User.getById(targetID);
143 String message = getMailReceiver().receive(ServerConstants.getSupportMailAddress()).getMessage();
144 assertThat(message, containsString("All certificates in the account " + user.getPreferredName().toString()));
146 message = getMailReceiver().receive(targetEmail).getMessage();
147 assertThat(message, containsString("All certificates in your account have been revoked."));