X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2FdbObjects%2FTestVerificationMail.java;fp=tests%2Fclub%2Fwpia%2Fgigi%2FdbObjects%2FTestVerificationMail.java;h=43efda4a70fc1b5b3c0b3f5fc204fc0f9b9c4339;hp=0000000000000000000000000000000000000000;hb=08c941629aea14473e5c42ab6f5d590be4af4bf8;hpb=c2da35eb9f4b6d3a3c055de1229afe0c07dc47da diff --git a/tests/club/wpia/gigi/dbObjects/TestVerificationMail.java b/tests/club/wpia/gigi/dbObjects/TestVerificationMail.java new file mode 100644 index 00000000..43efda4a --- /dev/null +++ b/tests/club/wpia/gigi/dbObjects/TestVerificationMail.java @@ -0,0 +1,335 @@ +package club.wpia.gigi.dbObjects; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import java.sql.Timestamp; + +import org.junit.Test; + +import club.wpia.gigi.GigiApiException; +import club.wpia.gigi.database.GigiPreparedStatement; +import club.wpia.gigi.dbObjects.Country; +import club.wpia.gigi.dbObjects.Name; +import club.wpia.gigi.dbObjects.NamePart; +import club.wpia.gigi.dbObjects.User; +import club.wpia.gigi.dbObjects.Verification.VerificationType; +import club.wpia.gigi.dbObjects.Country.CountryCodeType; +import club.wpia.gigi.dbObjects.NamePart.NamePartType; +import club.wpia.gigi.testUtils.BusinessTest; +import club.wpia.gigi.util.DayDate; +import club.wpia.gigi.util.Notary; + +public class TestVerificationMail extends BusinessTest { + + private User agent; + + private User applicant; + + private Name firstName; + + private Name secondName; + + private Name thirdName; + + private String message; + + private void newAgent() throws GigiApiException { + agent = User.getById(createVerificationUser("Marianne", "Mustermann", createUniqueName() + "@example.com", TEST_PASSWORD)); + } + + private void newApplicant() throws GigiApiException { + applicant = User.getById(createVerifiedUser("John", "Doe", createUniqueName() + "@example.com", TEST_PASSWORD)); + firstName = applicant.getPreferredName(); + secondName = new Name(applicant, new NamePart(NamePartType.FIRST_NAME, "James"), new NamePart(NamePartType.LAST_NAME, "Doe")); + thirdName = new Name(applicant, new NamePart(NamePartType.FIRST_NAME, "James"), new NamePart(NamePartType.FIRST_NAME, "John"), new NamePart(NamePartType.LAST_NAME, "Doe")); + } + + private void raiseXP(User agentXP, int recurring) throws GigiApiException { + for (int i = 0; i < recurring; i++) { + String applicantT = createUniqueName() + "@example.com"; + int applicantId = createVerifiedUser("John", "Doe", applicantT, TEST_PASSWORD); + User applicantXP = User.getById(applicantId); + applicantXP = User.getById(applicantId); + Notary.verify(agentXP, applicantXP, applicantXP.getNames()[0], applicantXP.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + } + } + + private void enterVerification(Name... names) throws GigiApiException { + enterVerification(10, names); + } + + private void enterVerification(int points, Name... names) throws GigiApiException { + Notary.verifyAll(agent, applicant, applicant.getDoB(), points, createUniqueName(), validVerificationDateString(), VerificationType.FACE_TO_FACE, names, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + } + + private void enterVerificationInPast(int points, Name name) { + + try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `when`=? ")) { + ps.setInt(1, agent.getId()); + ps.setInt(2, name.getId()); + ps.setInt(3, points); + ps.setString(4, "test-location"); + ps.setString(5, "2010-01-01"); + ps.setTimestamp(6, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 200)); + ps.execute(); + } + } + + @Test + public void testVerificationFirstApplicant() throws GigiApiException { + newApplicant(); + newAgent(); + + // verify preferred name only + enterVerification(firstName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40))); + + // verification first two names + newAgent(); + + enterVerification(firstName, secondName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30))); + assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40))); + + // verification all three names + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20))); + assertThat(message, containsString("James Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30))); + assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40))); + + // New verification preferred name + newAgent(); + + enterVerification(firstName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10))); + + // verification all three names reaches 50 VP + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name.")); + assertThat(message, containsString("James Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20))); + assertThat(message, containsString("James John Doe: with 10 to total 20 Verification Points." + "\n" + requiresMore(30))); + assertThat(message, containsString(requiresMoreTotal(50))); + + // verification all three names reaches 60 VP + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 60 Verification Points.")); + assertThat(message, containsString("James Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10))); + assertThat(message, containsString("James John Doe: with 10 to total 30 Verification Points." + "\n" + requiresMore(20))); + assertThat(message, containsString(requiresMoreTotal(40))); + + // verification all three names reaches 70 VP + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 70 Verification Points.")); + assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name.")); + assertThat(message, containsString("James John Doe: with 10 to total 40 Verification Points." + "\n" + requiresMore(10))); + assertThat(message, containsString(requiresMoreTotal(30))); + + // verification all three names reaches 80 VP + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 80 Verification Points.")); + assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points.")); + assertThat(message, containsString("James John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name.")); + assertThat(message, containsString(requiresMoreTotal(20))); + + // verification all three names reaches 90 VP + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 90 Verification Points.")); + assertThat(message, containsString("James Doe: with 10 to total 70 Verification Points.")); + assertThat(message, containsString("James John Doe: with 10 to total 60 Verification Points.")); + assertThat(message, containsString(requiresMoreTotal(10))); + + // verification all three names reaches 100 VP + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 100 Verification Points.")); + assertThat(message, containsString("James Doe: with 10 to total 80 Verification Points.")); + assertThat(message, containsString("James John Doe: with 10 to total 70 Verification Points.")); + assertThat(message, containsString("You can now apply for RA Agent status or code signing ability.")); + + // verification all three names reaches 100 VP + newAgent(); + + enterVerification(firstName, secondName, thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 110 Verification Points.")); + assertThat(message, containsString("James Doe: with 10 to total 90 Verification Points.")); + assertThat(message, containsString("James John Doe: with 10 to total 80 Verification Points.")); + } + + private String requiresMore(int points) { + return "To issue client certificates with this name you need " + points + " more Verification Points."; + } + + private String requiresMoreTotal(int points) { + return "To apply for RA Agent status or code signing ability you need " + points + " more Verification Points."; + } + + @Test + public void testVerificationSecondApplicant() throws GigiApiException { + newApplicant(); + + // verify preferred name only 5 times + newAgent(); + enterVerification(firstName); + message = getMailReceiver().receive().getMessage(); + + newAgent(); + enterVerification(firstName); + message = getMailReceiver().receive().getMessage(); + + newAgent(); + enterVerification(firstName); + message = getMailReceiver().receive().getMessage(); + + newAgent(); + enterVerification(firstName); + message = getMailReceiver().receive().getMessage(); + + newAgent(); + enterVerification(firstName); + + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name.")); + assertThat(message, containsString(requiresMoreTotal(50))); + + // verify preferred name second name + newAgent(); + enterVerification(secondName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("James Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40))); + assertThat(message, containsString(requiresMoreTotal(40))); + + // verify preferred name second name 4 more times + newAgent(); + enterVerification(secondName); + message = getMailReceiver().receive().getMessage(); + + newAgent(); + enterVerification(secondName); + message = getMailReceiver().receive().getMessage(); + + newAgent(); + enterVerification(secondName); + message = getMailReceiver().receive().getMessage(); + + newAgent(); + enterVerification(secondName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("James Doe: with 10 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name.")); + assertThat(message, containsString("You can now apply for RA Agent status or code signing ability.")); + + // get more than 100 VP in total + newAgent(); + enterVerification(secondName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("James Doe: with 10 to total 60 Verification Points.")); + + // verify third name + newAgent(); + enterVerification(thirdName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("James John Doe: with 10 to total 10 Verification Points." + "\n" + requiresMore(40))); + + } + + @Test + public void testVerificationMultiple() throws GigiApiException { + newApplicant(); + + // verify with 35 VP + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + Notary.verify(agent, applicant, applicant.getNames()[1], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + // add first Verification in the past result first name 45 VP + newAgent(); + raiseXP(agent, 5); + enterVerificationInPast(10, firstName); + + // add second Verification result first name 50 VP + enterVerification(15, firstName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name.")); + assertThat(message, containsString(requiresMoreTotal(50))); + + // verify first name to 85 VP + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 10, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + newAgent(); + Notary.verify(agent, applicant, applicant.getNames()[0], applicant.getDoB(), 5, "Test location", validVerificationDateString(), VerificationType.FACE_TO_FACE, Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS)); + + // add first Verification in the past result first name 95 VP + newAgent(); + raiseXP(agent, 5); + enterVerificationInPast(10, firstName); + enterVerificationInPast(10, secondName); + + // add second Verification result first name 100 VP, second name 50 VP + enterVerification(15, firstName, secondName); + message = getMailReceiver().receive().getMessage(); + assertThat(message, containsString("RA-Agent Marianne Mustermann verified your name(s):")); + assertThat(message, containsString("John Doe: with 15 to total 100 Verification Points.")); + assertThat(message, containsString("James Doe: with 15 to total 50 Verification Points." + "\n" + "You can now issue client certificates with this name.")); + assertThat(message, containsString("You can now apply for RA Agent status or code signing ability.")); + } +}