X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2Fpages%2Fwot%2FTestVerification.java;h=dcc61fc070cf66d857ec173546001b527c415e01;hp=eaff941c43d43de5c9d1f63ff6ddde0d8642b513;hb=bb3f2922c28e31def60ea7be34a8c5015ca18bb1;hpb=ca40eec05f7b3e6bd02014c30448af786aace969 diff --git a/tests/club/wpia/gigi/pages/wot/TestVerification.java b/tests/club/wpia/gigi/pages/wot/TestVerification.java index eaff941c..dcc61fc0 100644 --- a/tests/club/wpia/gigi/pages/wot/TestVerification.java +++ b/tests/club/wpia/gigi/pages/wot/TestVerification.java @@ -9,6 +9,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URLConnection; import java.net.URLEncoder; +import java.security.GeneralSecurityException; import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; @@ -22,6 +23,7 @@ import org.junit.Test; import club.wpia.gigi.GigiApiException; import club.wpia.gigi.database.GigiPreparedStatement; +import club.wpia.gigi.dbObjects.CATS.CATSType; import club.wpia.gigi.dbObjects.Country; import club.wpia.gigi.dbObjects.Group; import club.wpia.gigi.dbObjects.User; @@ -40,19 +42,22 @@ public class TestVerification extends ManagedTest { private int applicantName; + private int applicantId; + private String cookie; @Before - public void setup() throws IOException { + public void setup() throws IOException, GeneralSecurityException, GigiApiException, InterruptedException { clearCaches(); agentM = createUniqueName() + "@example.org"; applicantM = createUniqueName() + "@example.org"; createVerificationUser("a", "b", agentM, TEST_PASSWORD); - int applicantId = createVerifiedUser("a", "c", applicantM, TEST_PASSWORD); + applicantId = createVerifiedUser("a", "c", applicantM, TEST_PASSWORD); applicantName = User.getById(applicantId).getPreferredName().getId(); - cookie = login(agentM, TEST_PASSWORD); + User users[] = User.findByEmail(agentM); + cookie = cookieWithCertificateLogin(users[0]); } private Matcher isVerificationForm() { @@ -101,6 +106,7 @@ public class TestVerification extends ManagedTest { String body = executeSuccess("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); assertThat(body, containsString("10")); assertThat(body, containsString(applicantM)); + getMailReceiver().receive(applicantM); } @Test @@ -157,7 +163,7 @@ public class TestVerification extends ManagedTest { String applicantCookie = login(applicantM, TEST_PASSWORD); String newDob = "day=1&month=1&year=" + ( !succeed ? 1911 : 1910); - + loginCertificate = null; assertNull(executeBasicWebInteraction(applicantCookie, MyDetails.PATH, newDob + "&action=updateDoB", 0)); uc.getOutputStream().write(("verifiedName=" + applicantName + "&date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8")); @@ -165,6 +171,7 @@ public class TestVerification extends ManagedTest { String error = fetchStartErrorMessage(IOUtils.readURL(uc)); if (succeed) { assertNull(error); + getMailReceiver().receive(applicantM); } else { assertTrue(error, !error.startsWith("")); assertThat(error, containsString("changed his personal details")); @@ -186,11 +193,13 @@ public class TestVerification extends ManagedTest { c.add(Calendar.HOUR_OF_DAY, 12); executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + getMailReceiver().receive(applicantM); } @Test public void testVerifyFormPastInRange() throws IOException { executeSuccess("date=" + validVerificationDateString() + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + getMailReceiver().receive(applicantM); } @Test @@ -202,6 +211,7 @@ public class TestVerification extends ManagedTest { c.add(Calendar.DAY_OF_MONTH, 1); executeSuccess("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + getMailReceiver().receive(applicantM); } @Test @@ -236,9 +246,11 @@ public class TestVerification extends ManagedTest { @Test public void testVerifyListingValid() throws IOException, GigiApiException { String uniqueLoc = createUniqueName(); - execute("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + getMailReceiver().receive(applicantM); String cookie = login(applicantM, TEST_PASSWORD); + loginCertificate = null; URLConnection url = get(cookie, Points.PATH); String resp = IOUtils.readURL(url); resp = resp.split(Pattern.quote(""))[1]; @@ -250,7 +262,10 @@ public class TestVerification extends ManagedTest { public void testAgentListingValid() throws IOException, GigiApiException { String uniqueLoc = createUniqueName(); executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + getMailReceiver().receive(applicantM); + String cookie = login(agentM, TEST_PASSWORD); + loginCertificate = null; URLConnection url = get(cookie, Points.PATH); String resp = IOUtils.readURL(url); resp = resp.split(Pattern.quote(""))[2]; @@ -295,8 +310,7 @@ public class TestVerification extends ManagedTest { } @Test - public void testMultipleVerification() throws IOException { - + public void testMultipleVerification() throws IOException, GeneralSecurityException, GigiApiException, InterruptedException { User users[] = User.findByEmail(agentM); int agentID = users[0].getId(); @@ -317,6 +331,7 @@ public class TestVerification extends ManagedTest { // enter second entry String uniqueLoc = createUniqueName(); executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); + getMailReceiver().receive(applicantM); // enter third entry on the same day URLConnection uc = get(cookie, VerifyPage.PATH); @@ -332,8 +347,8 @@ public class TestVerification extends ManagedTest { } @Test - public void testRANotificationSet() throws IOException, GigiApiException { - getMailReceiver().clearMails(); + public void testRANotificationSet() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException { + getMailReceiver().assertEmpty(); User users[] = User.findByEmail(agentM); assertTrue("user RA Agent not found", users != null && users.length > 0); @@ -341,25 +356,21 @@ public class TestVerification extends ManagedTest { User u = users[0]; u.grantGroup(u, Group.VERIFY_NOTIFICATION); clearCaches(); - cookie = login(agentM, TEST_PASSWORD); - - String targetMail = u.getEmail(); + cookie = cookieWithCertificateLogin(users[0]); // enter verification String uniqueLoc = createUniqueName(); executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); - TestMail tm; + getMailReceiver().receive(applicantM); - do { - tm = getMailReceiver().receive(); - } while ( !tm.getTo().equals(targetMail)); + TestMail tm = getMailReceiver().receive(agentM); assertThat(tm.getMessage(), containsString("You entered a verification for the account with email address " + applicantM)); } @Test public void testRANotificationNotSet() throws IOException, GigiApiException { - getMailReceiver().clearMails(); + getMailReceiver().assertEmpty(); User users[] = User.findByEmail(agentM); assertTrue("user RA Agent not found", users != null && users.length > 0); @@ -367,16 +378,48 @@ public class TestVerification extends ManagedTest { User u = users[0]; u.revokeGroup(u, Group.VERIFY_NOTIFICATION); clearCaches(); - cookie = login(agentM, TEST_PASSWORD); // enter verification String uniqueLoc = createUniqueName(); executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10"); - TestMail tm; - - tm = getMailReceiver().receive(); + TestMail tm = getMailReceiver().receive(applicantM); assertThat(tm.getMessage(), not(containsString("You entered a verification for the account with email address " + applicantM))); } + + @Test + public void testVerifyWithoutCertLogin() throws IOException { + cookie = login(agentM, TEST_PASSWORD); + loginCertificate = null; + assertEquals(403, get(cookie, VerifyPage.PATH).getResponseCode()); + } + + @Test + public void testVerifyWithoutValidChallenge() throws IOException, GigiApiException { + cookie = cookieWithCertificateLogin(User.getById(applicantId)); + add100Points(applicantId); + insertRAContract(applicantId); + addChallengeInPast(applicantId, CATSType.AGENT_CHALLENGE); + assertEquals(403, get(cookie, VerifyPage.PATH).getResponseCode()); + addChallenge(applicantId, CATSType.AGENT_CHALLENGE); + assertEquals(200, get(cookie, VerifyPage.PATH).getResponseCode()); + } + + @Test + public void testVerifyValidTTPChallenge() throws IOException, GigiApiException { + grant(User.getByEmail(agentM), Group.TTP_AGENT); + grant(User.getById(applicantId), Group.TTP_APPLICANT); + cookie = cookieWithCertificateLogin(User.getById(applicantId)); + cookie = cookieWithCertificateLogin(User.getByEmail(agentM)); + + // test without valid challenge + String content = search("email=" + URLEncoder.encode(applicantM, "UTF-8") + "&day=1&month=1&year=1910"); + assertThat(content, containsString("you need to pass the TTP RA Agent Challenge")); + + // test with valid challenge + addChallenge(User.getByEmail(agentM).getId(), CATSType.TTP_AGENT_CHALLENGE); + content = search("email=" + URLEncoder.encode(applicantM, "UTF-8") + "&day=1&month=1&year=1910"); + assertThat(content, not(containsString("you need to pass the TTP RA Agent Challenge"))); + } }