X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Fmain%2FRegisterPageTest.java;h=eba981237f9fd2117a44063f1308ab93b5abb1d1;hb=dea55fb19948e7fa05e4b9369873e96360a5064a;hp=7286f8a9beba78c4c42fe7b1e0338eac316b5aef;hpb=aa5723dbb64ec8efa63909d39ff72364f0a5ee96;p=gigi.git diff --git a/tests/org/cacert/gigi/pages/main/RegisterPageTest.java b/tests/org/cacert/gigi/pages/main/RegisterPageTest.java index 7286f8a9..eba98123 100644 --- a/tests/org/cacert/gigi/pages/main/RegisterPageTest.java +++ b/tests/org/cacert/gigi/pages/main/RegisterPageTest.java @@ -32,7 +32,9 @@ public class RegisterPageTest extends ManagedTest { public static final String p; @Before - public void setUp() throws Exception {} + public void setUp() throws Exception { + clearCaches(); // We do many registers in this test suite. + } private static String createBase() { return createUniqueName() + "@email.de"; @@ -46,23 +48,23 @@ public class RegisterPageTest extends ManagedTest { String defaultSignup = "fname=" + URLEncoder.encode("ab", "UTF-8") + "&lname=" + URLEncoder.encode("b", "UTF-8") + "&pword1=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&pword2=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&day=1&month=1&year=1910&tos_agree=1&mname=mn&suffix=sf&email="; - String query = defaultSignup + URLEncoder.encode("correct3_" + uniq + "@email.de", "UTF-8") + "&general=1&country=1®ional=1&radius=1"; + String query = defaultSignup + URLEncoder.encode("correct3_" + uniq + "@email.de", "UTF-8") + "&general=1&country=1®ional=1&radius=1&name-type=western"; String data = fetchStartErrorMessage(runRegister(query)); assertNull(data); assertSuccessfullRegMail(); - getMailReciever().setEmailCheckError("400 Greylisted"); - getMailReciever().setApproveRegex(Pattern.compile("a")); + getMailReceiver().setEmailCheckError("400 Greylisted"); + getMailReceiver().setApproveRegex(Pattern.compile("a")); query = defaultSignup + URLEncoder.encode("correct4_" + uniq + "@email.de", "UTF-8") + "&general=1&country=1®ional=1&radius=1"; data = fetchStartErrorMessage(runRegister(query)); assertNotNull(data); - assertNull(getMailReciever().poll()); + assertNull(getMailReceiver().poll()); } private void assertSuccessfullRegMail() { - String link = getMailReciever().receive().extractLink(); + String link = getMailReceiver().receive().extractLink(); assertTrue(link, link.startsWith("https://")); } @@ -139,19 +141,32 @@ public class RegisterPageTest extends ManagedTest { public void testTooYoung() throws IOException { Calendar c = GregorianCalendar.getInstance(); c.add(Calendar.YEAR, -User.MINIMUM_AGE + 2); - testFailedForm("fname=a&lname=b&email=" + createUniqueName() + "@email.de" + p + "&day=1&month=1&year=" + c.get(Calendar.YEAR) + "&tos_agree=1"); + testFailedForm("fname=a&lname=b&email=" + createUniqueName() + "@email.de" + p + "&day=" + c.get(Calendar.DAY_OF_MONTH) + "&month=" + (c.get(Calendar.MONTH) + 1) + "&year=" + c.get(Calendar.YEAR) + "&tos_agree=1"); + } + + @Test + public void testTooOld() throws IOException { + Calendar c = GregorianCalendar.getInstance(); + c.add(Calendar.YEAR, -User.MAXIMUM_PLAUSIBLE_AGE); + c.add(Calendar.DAY_OF_MONTH, -1); + testFailedForm("fname=a&lname=b&email=" + createUniqueName() + "@email.de" + p + "&day=" + c.get(Calendar.DAY_OF_MONTH) + "&month=" + (c.get(Calendar.MONTH) + 1) + "&year=" + c.get(Calendar.YEAR) + "&tos_agree=1"); } @Test public void testDataStays() throws IOException { long uniq = System.currentTimeMillis(); - String run = runRegister("fname=fn" + uniq + "&lname=ln" + uniq + "&email=ma" + uniq + "@cacert.org&pword1=pas" + uniq + "&pword2=pas2" + uniq + "&day=1&month=1&year=0"); + String run = runRegister("fname=fn" + uniq + "&lname=ln" + uniq + "&email=ma" + uniq + "@cacert.org&pword1=pas" + uniq + "&pword2=pas2" + uniq + "&day=28&month=10&year=1950"); assertThat(run, containsString("fn" + uniq)); assertThat(run, containsString("ln" + uniq)); assertThat(run, containsString("ma" + uniq + "@cacert.org")); assertThat(run, not(containsString("pas" + uniq))); assertThat(run, not(containsString("pas2" + uniq))); - + // test year + assertThat(run, containsString("name=\"year\" value=\"1950\"")); + // test month + assertThat(run, containsString("")); } @Test @@ -182,7 +197,7 @@ public class RegisterPageTest extends ManagedTest { @Test public void testInvalidMailbox() { - getMailReciever().setApproveRegex(Pattern.compile("a")); + getMailReceiver().setApproveRegex(Pattern.compile("a")); long uniq = System.currentTimeMillis(); try { registerUser("RegisterTest", "User", "testInvalidMailbox" + uniq + "@cacert.org", TEST_PASSWORD); @@ -197,4 +212,31 @@ public class RegisterPageTest extends ManagedTest { assertTrue(startError, !startError.startsWith("")); } + @Test + public void testRegisterWithCountry() throws IOException, InterruptedException { + long uniq = System.currentTimeMillis(); + String email = "country" + uniq + "@email.de"; + + String defaultSignup = "fname=" + URLEncoder.encode("ab", "UTF-8") + "&lname=" + URLEncoder.encode("b", "UTF-8") + "&pword1=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&pword2=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&day=1&month=1&year=1910&tos_agree=1&mname=mn&suffix=sf&email="; + + String query = defaultSignup + URLEncoder.encode(email, "UTF-8") + "&general=1&country=1®ional=1&radius=1&name-type=western&residenceCountry=DE"; + String data = fetchStartErrorMessage(runRegister(query)); + assertNull(data); + User u = User.getByEmail(email); + assertEquals("DE", u.getResidenceCountry().getCountryCode()); + } + + @Test + public void testRegisterWithoutCountry() throws IOException, InterruptedException { + long uniq = System.currentTimeMillis(); + String email = "countryno" + uniq + "@email.de"; + + String defaultSignup = "fname=" + URLEncoder.encode("ab", "UTF-8") + "&lname=" + URLEncoder.encode("b", "UTF-8") + "&pword1=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&pword2=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&day=1&month=1&year=1910&tos_agree=1&mname=mn&suffix=sf&email="; + + String query = defaultSignup + URLEncoder.encode(email, "UTF-8") + "&general=1&country=1®ional=1&radius=1&name-type=western&residenceCountry=invalid"; + String data = fetchStartErrorMessage(runRegister(query)); + assertNull(data); + User u = User.getByEmail(email); + assertEquals(null, u.getResidenceCountry()); + } }