1 package club.wpia.gigi.dbObjects;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.sql.Timestamp;
10 import club.wpia.gigi.GigiApiException;
11 import club.wpia.gigi.database.GigiPreparedStatement;
12 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
13 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
14 import club.wpia.gigi.dbObjects.Verification.VerificationType;
15 import club.wpia.gigi.testUtils.BusinessTest;
16 import club.wpia.gigi.util.DayDate;
17 import club.wpia.gigi.util.Notary;
19 public class TestVerificationMail extends BusinessTest {
23 private User applicant;
25 private Name firstName;
27 private Name secondName;
29 private Name thirdName;
31 private String message;
33 private void newAgent() throws GigiApiException {
34 agent = User.getById(createVerificationUser("Marianne", "Mustermann", createUniqueName() + "@example.com", TEST_PASSWORD));
37 private void newApplicant() throws GigiApiException {
38 applicant = User.getById(createVerifiedUser("John", "Doe", createUniqueName() + "@example.com", TEST_PASSWORD));
39 firstName = applicant.getPreferredName();
40 secondName = new Name(applicant, new NamePart(NamePartType.FIRST_NAME, "James"), new NamePart(NamePartType.LAST_NAME, "Doe"));
41 thirdName = new Name(applicant, new NamePart(NamePartType.FIRST_NAME, "James"), new NamePart(NamePartType.FIRST_NAME, "John"), new NamePart(NamePartType.LAST_NAME, "Doe"));
44 private void raiseXP(User agentXP, int recurring) throws GigiApiException {
45 for (int i = 0; i < recurring; i++) {
46 String applicantT = createUniqueName() + "@example.com";
47 int applicantId = createVerifiedUser("John", "Doe", applicantT, TEST_PASSWORD);
48 User applicantXP = User.getById(applicantId);
49 applicantXP = User.getById(applicantId);
50 Notary.verify(agentXP, applicantXP, applicantXP.getNames()[0], applicantXP.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
54 private void enterVerification(Name... names) throws GigiApiException {
55 enterVerification(10, names);
58 private void enterVerification(int points, Name... names) throws GigiApiException {
59 Notary.verifyAll(agent, applicant, applicant.getDoB(), points, createUniqueName(), validVerificationDateString(), VerificationType.FACE_TO_FACE, names, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
62 private void enterVerificationInPast(int points, Name name) {
64 try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `when`=? ")) {
65 ps.setInt(1, agent.getId());
66 ps.setInt(2, name.getId());
68 ps.setString(4, "test-location");
69 ps.setString(5, "2010-01-01");
70 ps.setTimestamp(6, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 200));
76 public void testVerificationFirstApplicant() throws GigiApiException {
80 // verify preferred name only
81 enterVerification(firstName);
82 message = applicantMail();
83 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
84 assertThat(message, containsString("John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
86 // verification first two names
89 enterVerification(firstName, secondName);
90 message = applicantMail();
91 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
92 assertThat(message, containsString("John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
93 assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
95 // verification all three names
98 enterVerification(firstName, secondName, thirdName);
99 message = applicantMail();
100 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
101 assertThat(message, containsString("John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
102 assertThat(message, containsString("James Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
103 assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
105 // New verification preferred name
108 enterVerification(firstName);
109 message = applicantMail();
110 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
111 assertThat(message, containsString("John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
113 // verification all three names reaches 50 VP
116 enterVerification(firstName, secondName, thirdName);
117 message = applicantMail();
118 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
119 assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
120 assertThat(message, containsString("James Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
121 assertThat(message, containsString("James John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
122 assertThat(message, containsString(requiresMoreTotal(50)));
124 // verification all three names reaches 60 VP
127 enterVerification(firstName, secondName, thirdName);
128 message = applicantMail();
129 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
130 assertThat(message, containsString("John Doe: with 10 to total 60 Verification Points."));
131 assertThat(message, containsString("James Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
132 assertThat(message, containsString("James John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
133 assertThat(message, containsString(requiresMoreTotal(40)));
135 // verification all three names reaches 70 VP
138 enterVerification(firstName, secondName, thirdName);
139 message = applicantMail();
140 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
141 assertThat(message, containsString("John Doe: with 10 to total 70 Verification Points."));
142 assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
143 assertThat(message, containsString("James John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
144 assertThat(message, containsString(requiresMoreTotal(30)));
146 // verification all three names reaches 80 VP
149 enterVerification(firstName, secondName, thirdName);
150 message = applicantMail();
151 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
152 assertThat(message, containsString("John Doe: with 10 to total 80 Verification Points."));
153 assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points."));
154 assertThat(message, containsString("James John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
155 assertThat(message, containsString(requiresMoreTotal(20)));
157 // verification all three names reaches 90 VP
160 enterVerification(firstName, secondName, thirdName);
161 message = applicantMail();
162 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
163 assertThat(message, containsString("John Doe: with 10 to total 90 Verification Points."));
164 assertThat(message, containsString("James Doe: with 10 to total 70 Verification Points."));
165 assertThat(message, containsString("James John Doe: with 10 to total 60 Verification Points."));
166 assertThat(message, containsString(requiresMoreTotal(10)));
168 // verification all three names reaches 100 VP
171 enterVerification(firstName, secondName, thirdName);
172 message = applicantMail();
173 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
174 assertThat(message, containsString("John Doe: with 10 to total 100 Verification Points."));
175 assertThat(message, containsString("James Doe: with 10 to total 80 Verification Points."));
176 assertThat(message, containsString("James John Doe: with 10 to total 70 Verification Points."));
177 assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
179 // verification all three names reaches 100 VP
182 enterVerification(firstName, secondName, thirdName);
183 message = applicantMail();
184 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
185 assertThat(message, containsString("John Doe: with 10 to total 110 Verification Points."));
186 assertThat(message, containsString("James Doe: with 10 to total 90 Verification Points."));
187 assertThat(message, containsString("James John Doe: with 10 to total 80 Verification Points."));
190 private String requiresMore(int points) {
191 return "To issue client certificates with this name you need " + points + " more Verification Points.";
194 private String requiresMoreTotal(int points) {
195 return "To apply for RA Agent status or code signing ability you need " + points + " more Verification Points.";
199 public void testVerificationSecondApplicant() throws GigiApiException {
202 // verify preferred name only 5 times
204 enterVerification(firstName);
205 message = applicantMail();
208 enterVerification(firstName);
209 message = applicantMail();
212 enterVerification(firstName);
213 message = applicantMail();
216 enterVerification(firstName);
217 message = applicantMail();
220 enterVerification(firstName);
222 message = applicantMail();
223 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
224 assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
225 assertThat(message, containsString(requiresMoreTotal(50)));
227 // verify preferred name second name
229 enterVerification(secondName);
230 message = applicantMail();
231 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
232 assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
233 assertThat(message, containsString(requiresMoreTotal(40)));
235 // verify preferred name second name 4 more times
237 enterVerification(secondName);
238 message = applicantMail();
241 enterVerification(secondName);
242 message = applicantMail();
245 enterVerification(secondName);
246 message = applicantMail();
249 enterVerification(secondName);
250 message = applicantMail();
251 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
252 assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
253 assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
255 // get more than 100 VP in total
257 enterVerification(secondName);
258 message = applicantMail();
259 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
260 assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points."));
264 enterVerification(thirdName);
265 message = applicantMail();
266 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
267 assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
272 public void testVerificationMultiple() throws GigiApiException {
277 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
278 Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
281 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
282 Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
285 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
286 Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
289 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
290 Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
292 // add first Verification in the past result first name 45 VP
295 enterVerificationInPast(10, firstName);
297 // add second Verification result first name 50 VP
298 enterVerification(15, firstName);
299 message = applicantMail();
300 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
301 assertThat(message, containsString("John Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
302 assertThat(message, containsString(requiresMoreTotal(50)));
304 // verify first name to 85 VP
306 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
309 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
312 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
315 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
317 // add first Verification in the past result first name 95 VP
320 enterVerificationInPast(10, firstName);
321 enterVerificationInPast(10, secondName);
323 // add second Verification result first name 100 VP, second name 50 VP
324 enterVerification(15, firstName, secondName);
325 message = applicantMail();
326 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
327 assertThat(message, containsString("John Doe: with 15 to total 100 Verification Points."));
328 assertThat(message, containsString("James Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
329 assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
332 private String applicantMail() {
333 return getMailReceiver().receive(applicant.getEmail()).getMessage();