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;
13 import club.wpia.gigi.dbObjects.Name;
14 import club.wpia.gigi.dbObjects.NamePart;
15 import club.wpia.gigi.dbObjects.User;
16 import club.wpia.gigi.dbObjects.Verification.VerificationType;
17 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
18 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
19 import club.wpia.gigi.testUtils.BusinessTest;
20 import club.wpia.gigi.util.DayDate;
21 import club.wpia.gigi.util.Notary;
23 public class TestVerificationMail extends BusinessTest {
27 private User applicant;
29 private Name firstName;
31 private Name secondName;
33 private Name thirdName;
35 private String message;
37 private void newAgent() throws GigiApiException {
38 agent = User.getById(createVerificationUser("Marianne", "Mustermann", createUniqueName() + "@example.com", TEST_PASSWORD));
41 private void newApplicant() throws GigiApiException {
42 applicant = User.getById(createVerifiedUser("John", "Doe", createUniqueName() + "@example.com", TEST_PASSWORD));
43 firstName = applicant.getPreferredName();
44 secondName = new Name(applicant, new NamePart(NamePartType.FIRST_NAME, "James"), new NamePart(NamePartType.LAST_NAME, "Doe"));
45 thirdName = new Name(applicant, new NamePart(NamePartType.FIRST_NAME, "James"), new NamePart(NamePartType.FIRST_NAME, "John"), new NamePart(NamePartType.LAST_NAME, "Doe"));
48 private void raiseXP(User agentXP, int recurring) throws GigiApiException {
49 for (int i = 0; i < recurring; i++) {
50 String applicantT = createUniqueName() + "@example.com";
51 int applicantId = createVerifiedUser("John", "Doe", applicantT, TEST_PASSWORD);
52 User applicantXP = User.getById(applicantId);
53 applicantXP = User.getById(applicantId);
54 Notary.verify(agentXP, applicantXP, applicantXP.getNames()[0], applicantXP.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
58 private void enterVerification(Name... names) throws GigiApiException {
59 enterVerification(10, names);
62 private void enterVerification(int points, Name... names) throws GigiApiException {
63 Notary.verifyAll(agent, applicant, applicant.getDoB(), points, createUniqueName(), validVerificationDateString(), VerificationType.FACE_TO_FACE, names, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
66 private void enterVerificationInPast(int points, Name name) {
68 try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `when`=? ")) {
69 ps.setInt(1, agent.getId());
70 ps.setInt(2, name.getId());
72 ps.setString(4, "test-location");
73 ps.setString(5, "2010-01-01");
74 ps.setTimestamp(6, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 200));
80 public void testVerificationFirstApplicant() throws GigiApiException {
84 // verify preferred name only
85 enterVerification(firstName);
86 message = getMailReceiver().receive().getMessage();
87 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
88 assertThat(message, containsString("John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
90 // verification first two names
93 enterVerification(firstName, secondName);
94 message = getMailReceiver().receive().getMessage();
95 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
96 assertThat(message, containsString("John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
97 assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
99 // verification all three names
102 enterVerification(firstName, secondName, thirdName);
103 message = getMailReceiver().receive().getMessage();
104 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
105 assertThat(message, containsString("John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
106 assertThat(message, containsString("James Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
107 assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
109 // New verification preferred name
112 enterVerification(firstName);
113 message = getMailReceiver().receive().getMessage();
114 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
115 assertThat(message, containsString("John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
117 // verification all three names reaches 50 VP
120 enterVerification(firstName, secondName, thirdName);
121 message = getMailReceiver().receive().getMessage();
122 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
123 assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
124 assertThat(message, containsString("James Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
125 assertThat(message, containsString("James John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30)));
126 assertThat(message, containsString(requiresMoreTotal(50)));
128 // verification all three names reaches 60 VP
131 enterVerification(firstName, secondName, thirdName);
132 message = getMailReceiver().receive().getMessage();
133 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
134 assertThat(message, containsString("John Doe: with 10 to total 60 Verification Points."));
135 assertThat(message, containsString("James Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
136 assertThat(message, containsString("James John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20)));
137 assertThat(message, containsString(requiresMoreTotal(40)));
139 // verification all three names reaches 70 VP
142 enterVerification(firstName, secondName, thirdName);
143 message = getMailReceiver().receive().getMessage();
144 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
145 assertThat(message, containsString("John Doe: with 10 to total 70 Verification Points."));
146 assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
147 assertThat(message, containsString("James John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10)));
148 assertThat(message, containsString(requiresMoreTotal(30)));
150 // verification all three names reaches 80 VP
153 enterVerification(firstName, secondName, thirdName);
154 message = getMailReceiver().receive().getMessage();
155 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
156 assertThat(message, containsString("John Doe: with 10 to total 80 Verification Points."));
157 assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points."));
158 assertThat(message, containsString("James John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
159 assertThat(message, containsString(requiresMoreTotal(20)));
161 // verification all three names reaches 90 VP
164 enterVerification(firstName, secondName, thirdName);
165 message = getMailReceiver().receive().getMessage();
166 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
167 assertThat(message, containsString("John Doe: with 10 to total 90 Verification Points."));
168 assertThat(message, containsString("James Doe: with 10 to total 70 Verification Points."));
169 assertThat(message, containsString("James John Doe: with 10 to total 60 Verification Points."));
170 assertThat(message, containsString(requiresMoreTotal(10)));
172 // verification all three names reaches 100 VP
175 enterVerification(firstName, secondName, thirdName);
176 message = getMailReceiver().receive().getMessage();
177 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
178 assertThat(message, containsString("John Doe: with 10 to total 100 Verification Points."));
179 assertThat(message, containsString("James Doe: with 10 to total 80 Verification Points."));
180 assertThat(message, containsString("James John Doe: with 10 to total 70 Verification Points."));
181 assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
183 // verification all three names reaches 100 VP
186 enterVerification(firstName, secondName, thirdName);
187 message = getMailReceiver().receive().getMessage();
188 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
189 assertThat(message, containsString("John Doe: with 10 to total 110 Verification Points."));
190 assertThat(message, containsString("James Doe: with 10 to total 90 Verification Points."));
191 assertThat(message, containsString("James John Doe: with 10 to total 80 Verification Points."));
194 private String requiresMore(int points) {
195 return "To issue client certificates with this name you need " + points + " more Verification Points.";
198 private String requiresMoreTotal(int points) {
199 return "To apply for RA Agent status or code signing ability you need " + points + " more Verification Points.";
203 public void testVerificationSecondApplicant() throws GigiApiException {
206 // verify preferred name only 5 times
208 enterVerification(firstName);
209 message = getMailReceiver().receive().getMessage();
212 enterVerification(firstName);
213 message = getMailReceiver().receive().getMessage();
216 enterVerification(firstName);
217 message = getMailReceiver().receive().getMessage();
220 enterVerification(firstName);
221 message = getMailReceiver().receive().getMessage();
224 enterVerification(firstName);
226 message = getMailReceiver().receive().getMessage();
227 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
228 assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
229 assertThat(message, containsString(requiresMoreTotal(50)));
231 // verify preferred name second name
233 enterVerification(secondName);
234 message = getMailReceiver().receive().getMessage();
235 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
236 assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
237 assertThat(message, containsString(requiresMoreTotal(40)));
239 // verify preferred name second name 4 more times
241 enterVerification(secondName);
242 message = getMailReceiver().receive().getMessage();
245 enterVerification(secondName);
246 message = getMailReceiver().receive().getMessage();
249 enterVerification(secondName);
250 message = getMailReceiver().receive().getMessage();
253 enterVerification(secondName);
254 message = getMailReceiver().receive().getMessage();
255 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
256 assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
257 assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));
259 // get more than 100 VP in total
261 enterVerification(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 60 Verification Points."));
268 enterVerification(thirdName);
269 message = getMailReceiver().receive().getMessage();
270 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
271 assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40)));
276 public void testVerificationMultiple() throws GigiApiException {
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(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
290 Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
293 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
294 Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
296 // add first Verification in the past result first name 45 VP
299 enterVerificationInPast(10, firstName);
301 // add second Verification result first name 50 VP
302 enterVerification(15, firstName);
303 message = getMailReceiver().receive().getMessage();
304 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
305 assertThat(message, containsString("John Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
306 assertThat(message, containsString(requiresMoreTotal(50)));
308 // verify first name to 85 VP
310 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
313 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
316 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
319 Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS));
321 // add first Verification in the past result first name 95 VP
324 enterVerificationInPast(10, firstName);
325 enterVerificationInPast(10, secondName);
327 // add second Verification result first name 100 VP, second name 50 VP
328 enterVerification(15, firstName, secondName);
329 message = getMailReceiver().receive().getMessage();
330 assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):"));
331 assertThat(message, containsString("John Doe: with 15 to total 100 Verification Points."));
332 assertThat(message, containsString("James Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name."));
333 assertThat(message, containsString("You can now apply for RA Agent status or code signing ability."));