X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Fmain%2FRegisterPageTest.java;h=7ab63c7dad9640be859d87d8cd115a4e8db2dd6d;hb=bead06ac89a5fbe282dab187c5d1babbb7dcdf66;hp=542de8b7b4503f451ffc316641fd8bf1969f9999;hpb=6a09b2465ca2b7cef5c27a1fb52bd44110ee8966;p=gigi.git diff --git a/tests/org/cacert/gigi/pages/main/RegisterPageTest.java b/tests/org/cacert/gigi/pages/main/RegisterPageTest.java index 542de8b7..7ab63c7d 100644 --- a/tests/org/cacert/gigi/pages/main/RegisterPageTest.java +++ b/tests/org/cacert/gigi/pages/main/RegisterPageTest.java @@ -4,10 +4,14 @@ import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URLEncoder; +import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.regex.Pattern; +import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.testUtils.InitTruststore; import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Before; @@ -18,10 +22,23 @@ public class RegisterPageTest extends ManagedTest { static { InitTruststore.run(); HttpURLConnection.setFollowRedirects(false); + try { + p = "&pword1=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") + "&pword2=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new Error(e); + } } + 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"; + } @Test public void testSuccess() throws IOException, InterruptedException { @@ -36,29 +53,29 @@ public class RegisterPageTest extends ManagedTest { 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://")); } @Test public void testNoFname() throws IOException { - testFailedForm("lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&tos_agree=1"); + testFailedForm("lname=b" + createBase() + "&day=1&month=1&year=1910&tos_agree=1"); } @Test public void testNoLname() throws IOException { - testFailedForm("fname=a&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&tos_agree=1"); + testFailedForm("fname=a" + createBase() + "&day=1&month=1&year=1910&tos_agree=1"); } @Test @@ -73,63 +90,83 @@ public class RegisterPageTest extends ManagedTest { @Test public void testDiffPword() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap2&day=1&month=1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "2&day=1&month=1&year=1910&tos_agree=1"); } @Test public void testNoDay() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&month=1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&month=1&year=1910&tos_agree=1"); } @Test public void testNoMonth() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&year=1910&tos_agree=1"); } @Test public void testNoYear() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=1&tos_agree=1"); } @Test public void testInvDay() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=40&month=1&year=1910&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=0&month=1&year=1910&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=-1&month=1&year=1910&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=a&month=1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=40&month=1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=0&month=1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=-1&month=1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=a&month=1&year=1910&tos_agree=1"); } @Test public void testInvMonth() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=20&year=1910&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=0&year=1910&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=-1&year=1910&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=a&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=20&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=0&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=-1&year=1910&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=a&year=1910&tos_agree=1"); } @Test public void testInvYear() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=0&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=100&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=a&tos_agree=1"); - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=-1&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=1&year=0&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=1&year=100&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=1&year=a&tos_agree=1"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=1&year=-1&tos_agree=1"); } @Test public void testNoAgree() throws IOException { - testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&tos_agree=a"); + testFailedForm("fname=a&lname=b" + createBase() + "&day=1&month=1&year=1910&tos_agree=a"); + } + + @Test + 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=" + 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 @@ -160,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);