]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/wot/TestAssuranceMail.java
add: test cases for verification notification mail
[gigi.git] / tests / org / cacert / gigi / pages / wot / TestAssuranceMail.java
1 package org.cacert.gigi.pages.wot;
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 import java.net.URLConnection;
9
10 import org.cacert.gigi.dbObjects.Name;
11 import org.cacert.gigi.dbObjects.User;
12 import org.cacert.gigi.pages.account.MyDetails;
13 import org.cacert.gigi.testUtils.IOUtils;
14 import org.cacert.gigi.testUtils.ManagedTest;
15 import org.junit.Test;
16
17 public class TestAssuranceMail extends ManagedTest {
18
19     private String agentM;
20
21     private String applicantM;
22
23     private String cookieAgent;
24
25     private String cookieApplicant;
26
27     private User agent;
28
29     private User applicant;
30
31     private int firstName;
32
33     private int secondName;
34
35     private int thirdName;
36
37     private String message;
38
39     private void newAgent() throws IOException {
40         agentM = createUniqueName() + "@example.com";
41         int agentID = createAssuranceUser("Marianne", "Mustermann", agentM, TEST_PASSWORD);
42         agent = User.getById(agentID);
43         cookieAgent = login(agentM, TEST_PASSWORD);
44
45     }
46
47     private void newApplicant() throws IOException {
48         applicantM = createUniqueName() + "@example.com";
49         int applicantId = createVerifiedUser("John", "Doe", applicantM, TEST_PASSWORD);
50         cookieApplicant = login(applicantM, TEST_PASSWORD);
51         executeBasicWebInteraction(cookieApplicant, MyDetails.PATH, "fname=James&lname=Doe&action=addName", 0);
52         executeBasicWebInteraction(cookieApplicant, MyDetails.PATH, "fname=James+John&lname=Doe&action=addName", 0);
53         applicant = User.getById(applicantId);
54         Name[] names = applicant.getNames();
55         firstName = 0;
56         secondName = 0;
57         thirdName = 0;
58         for (int i = 0; i < names.length; i++) {
59             if (names[i].toString().equals("John Doe")) {
60                 firstName = names[i].getId();
61             }
62             if (names[i].toString().equals("James Doe")) {
63                 secondName = names[i].getId();
64             }
65             if (names[i].toString().equals("James John Doe")) {
66                 thirdName = names[i].getId();
67             }
68         }
69         assertNotEquals(0, firstName);
70         assertNotEquals(0, secondName);
71         assertNotEquals(0, thirdName);
72     }
73
74     private String enterVerification(String query) throws MalformedURLException, IOException {
75         URLConnection uc = TestAssurance.buildupAssureFormConnection(cookieAgent, applicant.getEmail(), true);
76         uc.getOutputStream().write((query + "&date=" + validVerificationDateString() + "&location=" + createUniqueName() + "&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8"));
77         uc.getOutputStream().flush();
78         return IOUtils.readURL(uc);
79
80     }
81
82     @Test
83     public void testVerificationFirstApplicant() throws MalformedURLException, IOException {
84         clearCaches();
85         newApplicant();
86         newAgent();
87
88         // verify preferred name only
89         enterVerification("assuredName=" + firstName);
90         message = getMailReceiver().receive().getMessage();
91         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
92         assertThat(message, containsString("John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
93
94         // verification first two names
95         newAgent();
96
97         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName);
98         message = getMailReceiver().receive().getMessage();
99         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
100         assertThat(message, containsString("John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
101         assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
102
103         // verification all three names
104         newAgent();
105
106         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
107         message = getMailReceiver().receive().getMessage();
108         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
109         assertThat(message, containsString("John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
110         assertThat(message, containsString("James Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
111         assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
112
113         // New verification preferred name
114         newAgent();
115
116         enterVerification("assuredName=" + firstName);
117         message = getMailReceiver().receive().getMessage();
118         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
119         assertThat(message, containsString("John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
120
121         // verification all three names reaches 50 VP
122         newAgent();
123
124         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
125         message = getMailReceiver().receive().getMessage();
126         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
127         assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
128         assertThat(message, containsString("James Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
129         assertThat(message, containsString("James John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
130         assertThat(message, containsString(requiresMoreTotal(50)));
131
132         // verification all three names reaches 60 VP
133         newAgent();
134
135         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
136         message = getMailReceiver().receive().getMessage();
137         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
138         assertThat(message, containsString("John Doe: with 10 to total 60 Verification Points."));
139         assertThat(message, containsString("James Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
140         assertThat(message, containsString("James John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
141         assertThat(message, containsString(requiresMoreTotal(40)));
142
143         // verification all three names reaches 70 VP
144         newAgent();
145
146         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
147         message = getMailReceiver().receive().getMessage();
148         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
149         assertThat(message, containsString("John Doe: with 10 to total 70 Verification Points."));
150         assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
151         assertThat(message, containsString("James John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
152         assertThat(message, containsString(requiresMoreTotal(30)));
153
154         // verification all three names reaches 80 VP
155         newAgent();
156
157         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
158         message = getMailReceiver().receive().getMessage();
159         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
160         assertThat(message, containsString("John Doe: with 10 to total 80 Verification Points."));
161         assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points."));
162         assertThat(message, containsString("James John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
163         assertThat(message, containsString(requiresMoreTotal(20)));
164
165         // verification all three names reaches 90 VP
166         newAgent();
167
168         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
169         message = getMailReceiver().receive().getMessage();
170         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
171         assertThat(message, containsString("John Doe: with 10 to total 90 Verification Points."));
172         assertThat(message, containsString("James Doe: with 10 to total 70 Verification Points."));
173         assertThat(message, containsString("James John Doe: with 10 to total 60 Verification Points."));
174         assertThat(message, containsString(requiresMoreTotal(10)));
175
176         // verification all three names reaches 100 VP
177         clearCaches();
178         newAgent();
179
180         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
181         message = getMailReceiver().receive().getMessage();
182         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
183         assertThat(message, containsString("John Doe: with 10 to total 100 Verification Points."));
184         assertThat(message, containsString("James Doe: with 10 to total 80 Verification Points."));
185         assertThat(message, containsString("James John Doe: with 10 to total 70 Verification Points."));
186         assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
187
188         // verification all three names reaches 100 VP
189         newAgent();
190
191         enterVerification("assuredName=" + firstName + "&assuredName=" + secondName + "&assuredName=" + thirdName);
192         message = getMailReceiver().receive().getMessage();
193         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
194         assertThat(message, containsString("John Doe: with 10 to total 110 Verification Points."));
195         assertThat(message, containsString("James Doe: with 10 to total 90 Verification Points."));
196         assertThat(message, containsString("James John Doe: with 10 to total 80 Verification Points."));
197     }
198
199     private String requiresMore(int points) {
200         return "To issue client certificates with this name you need " + points + " more Verification Points.";
201     }
202
203     private String requiresMoreTotal(int points) {
204         return "To apply for RA Agent status or code signing ability you need " + points + " more Verification Points.";
205     }
206
207     @Test
208     public void testVerificationSecondApplicant() throws MalformedURLException, IOException {
209         clearCaches();
210         newApplicant();
211
212         // verify preferred name only 5 times
213         newAgent();
214         enterVerification("assuredName=" + firstName);
215         message = getMailReceiver().receive().getMessage();
216
217         newAgent();
218         enterVerification("assuredName=" + firstName);
219         message = getMailReceiver().receive().getMessage();
220
221         newAgent();
222         enterVerification("assuredName=" + firstName);
223         message = getMailReceiver().receive().getMessage();
224
225         newAgent();
226         enterVerification("assuredName=" + firstName);
227         message = getMailReceiver().receive().getMessage();
228
229         newAgent();
230         enterVerification("assuredName=" + firstName);
231
232         message = getMailReceiver().receive().getMessage();
233         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
234         assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
235         assertThat(message, containsString(requiresMoreTotal(50)));
236
237         clearCaches();
238
239         // verify preferred name second name
240         newAgent();
241         enterVerification("assuredName=" + secondName);
242         message = getMailReceiver().receive().getMessage();
243         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
244         assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
245         assertThat(message, containsString(requiresMoreTotal(40)));
246
247         // verify preferred name second name 4 more times
248         newAgent();
249         enterVerification("assuredName=" + secondName);
250         message = getMailReceiver().receive().getMessage();
251
252         newAgent();
253         enterVerification("assuredName=" + secondName);
254         message = getMailReceiver().receive().getMessage();
255
256         newAgent();
257         enterVerification("assuredName=" + secondName);
258         message = getMailReceiver().receive().getMessage();
259
260         newAgent();
261         enterVerification("assuredName=" + secondName);
262         message = getMailReceiver().receive().getMessage();
263         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
264         assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
265         assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
266
267         // get more than 100 VP in total
268         newAgent();
269         enterVerification("assuredName=" + secondName);
270         message = getMailReceiver().receive().getMessage();
271         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
272         assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points."));
273
274         // verify third name
275         newAgent();
276         enterVerification("assuredName=" + thirdName);
277         message = getMailReceiver().receive().getMessage();
278         assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
279         assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
280
281     }
282 }