1 package org.cacert.gigi.pages.wot;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.io.IOException;
7 import java.net.MalformedURLException;
8 import java.net.URLConnection;
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;
17 public class TestAssuranceMail extends ManagedTest {
19 private String agentM;
21 private String applicantM;
23 private String cookieAgent;
25 private String cookieApplicant;
29 private User applicant;
31 private int firstName;
33 private int secondName;
35 private int thirdName;
37 private String message;
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);
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();
58 for (int i = 0; i < names.length; i++) {
59 if (names[i].toString().equals("John Doe")) {
60 firstName = names[i].getId();
62 if (names[i].toString().equals("James Doe")) {
63 secondName = names[i].getId();
65 if (names[i].toString().equals("James John Doe")) {
66 thirdName = names[i].getId();
69 assertNotEquals(0, firstName);
70 assertNotEquals(0, secondName);
71 assertNotEquals(0, thirdName);
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);
83 public void testVerificationFirstApplicant() throws MalformedURLException, IOException {
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)));
94 // verification first two names
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)));
103 // verification all three names
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)));
113 // New verification preferred name
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)));
121 // verification all three names reaches 50 VP
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)));
132 // verification all three names reaches 60 VP
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)));
143 // verification all three names reaches 70 VP
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)));
154 // verification all three names reaches 80 VP
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)));
165 // verification all three names reaches 90 VP
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)));
176 // verification all three names reaches 100 VP
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."));
188 // verification all three names reaches 100 VP
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."));
199 private String requiresMore(int points) {
200 return "To issue client certificates with this name you need " + points + " more Verification Points.";
203 private String requiresMoreTotal(int points) {
204 return "To apply for RA Agent status or code signing ability you need " + points + " more Verification Points.";
208 public void testVerificationSecondApplicant() throws MalformedURLException, IOException {
212 // verify preferred name only 5 times
214 enterVerification("assuredName=" + firstName);
215 message = getMailReceiver().receive().getMessage();
218 enterVerification("assuredName=" + firstName);
219 message = getMailReceiver().receive().getMessage();
222 enterVerification("assuredName=" + firstName);
223 message = getMailReceiver().receive().getMessage();
226 enterVerification("assuredName=" + firstName);
227 message = getMailReceiver().receive().getMessage();
230 enterVerification("assuredName=" + firstName);
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)));
239 // verify preferred name second name
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)));
247 // verify preferred name second name 4 more times
249 enterVerification("assuredName=" + secondName);
250 message = getMailReceiver().receive().getMessage();
253 enterVerification("assuredName=" + secondName);
254 message = getMailReceiver().receive().getMessage();
257 enterVerification("assuredName=" + secondName);
258 message = getMailReceiver().receive().getMessage();
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."));
267 // get more than 100 VP in total
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."));
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)));