]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java
add: defense-in-depth mechanism to prevent unauthorized adding of groups
[gigi.git] / tests / org / cacert / gigi / pages / admin / TestSEAdminNotificationMail.java
1 package org.cacert.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.net.MalformedURLException;
8
9 import org.cacert.gigi.GigiApiException;
10 import org.cacert.gigi.dbObjects.Group;
11 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
12 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
13 import org.cacert.gigi.testUtils.ClientTest;
14 import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
15 import org.cacert.gigi.util.ServerConstants;
16 import org.junit.Test;
17
18 public class TestSEAdminNotificationMail extends ClientTest {
19
20     private int targetID;
21
22     public TestSEAdminNotificationMail() throws IOException, GigiApiException {
23         grant(u, Group.SUPPORTER);
24         cookie = login(email, TEST_PASSWORD);
25         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
26
27         String email = createUniqueName() + "@example.com";
28         String fname = "Först";
29         String lname = "Secönd";
30         targetID = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
31     }
32
33     @Test
34     public void testChangeAccountData() throws MalformedURLException, IOException {
35
36         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "dobd=1&dobm=2&doby=2000&detailupdate", 0);
37
38         String message = getMailReceiver().receive().getMessage();
39         assertThat(message, containsString("The account data was changed."));
40         assertThat(message, containsString("supporter " + u.getPreferredName().toString() + " triggered:"));
41
42     }
43
44     @Test
45     public void testPasswordReset() throws MalformedURLException, IOException {
46         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "aword=SecretWord&resetPass", 0);
47         TestMail tm;
48         String targetMail = ServerConstants.getSupportMailAddress();
49         do {
50             tm = getMailReceiver().receive();
51         } while ( !tm.getTo().equals(targetMail));
52         assertThat(tm.getMessage(), containsString("A password reset was triggered and an email was sent to user."));
53     }
54
55     @Test
56     public void testGrantUserGroup() throws MalformedURLException, IOException {
57         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=supporter", 0);
58
59         String message = getMailReceiver().receive().getMessage();
60         assertThat(message, containsString("The group permission supporter was granted."));
61     }
62
63     @Test
64     public void testRemoveUserGroup() throws MalformedURLException, IOException {
65         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=supporter", 0);
66
67         String message = getMailReceiver().receive().getMessage();
68         assertThat(message, containsString("The group permission supporter was revoked."));
69     }
70
71     @Test
72     public void testRevokeCertificates() throws MalformedURLException, IOException {
73         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "revokeall", 1);
74
75         String message = getMailReceiver().receive().getMessage();
76         assertThat(message, containsString("All certificates in the account have been revoked."));
77
78     }
79 }