1 package org.cacert.gigi.pages.main;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.HttpURLConnection;
7 import java.util.regex.Pattern;
9 import org.cacert.gigi.testUtils.InitTruststore;
10 import org.cacert.gigi.testUtils.ManagedTest;
11 import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
12 import org.junit.Before;
13 import org.junit.Test;
15 public class RegisterPageTest extends ManagedTest {
18 HttpURLConnection.setFollowRedirects(false);
22 public void setUp() throws Exception {
25 public void testSuccess() throws IOException {
26 long uniq = System.currentTimeMillis();
27 registerUser("ab", "b", "correct" + uniq + "@email.de", "ap12UI.'");
28 TestMail tm = waitForMail();
29 String link = tm.extractLink();
30 assertTrue(link, link.startsWith("https://"));
33 public void testNoFname() throws IOException {
34 testFailedForm("lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
37 public void testNoLname() throws IOException {
38 testFailedForm("fname=a&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
41 public void testNoEmail() throws IOException {
42 testFailedForm("fname=a&lname=b&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
46 public void testNoPword() throws IOException {
47 testFailedForm("fname=a&lname=b&email=e&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
51 public void testDiffPword() throws IOException {
52 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap2&day=1&month=1&year=1910&cca_agree=1");
56 public void testNoDay() throws IOException {
57 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&month=1&year=1910&cca_agree=1");
60 public void testNoMonth() throws IOException {
61 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&year=1910&cca_agree=1");
64 public void testNoYear() throws IOException {
65 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&cca_agree=1");
68 public void testInvDay() throws IOException {
69 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=40&month=1&year=1910&cca_agree=1");
70 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=0&month=1&year=1910&cca_agree=1");
71 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=a&month=1&year=1910&cca_agree=1");
74 public void testInvMonth() throws IOException {
75 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=20&year=1910&cca_agree=1");
76 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=0&year=1910&cca_agree=1");
77 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=-1&year=1910&cca_agree=1");
78 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=a&year=1910&cca_agree=1");
81 public void testInvYear() throws IOException {
82 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=0&cca_agree=1");
83 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=100&cca_agree=1");
84 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=a&cca_agree=1");
85 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=-1&cca_agree=1");
88 public void testNoAgree() throws IOException {
89 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=a");
93 public void testDataStays() throws IOException {
94 long uniq = System.currentTimeMillis();
95 String run = runRegister("fname=fn" + uniq + "&lname=ln" + uniq
96 + "&email=ma" + uniq + "@cacert.org&pword1=pas" + uniq
97 + "&pword2=pas2" + uniq + "&day=1&month=1&year=0");
98 assertTrue(run.contains("fn" + uniq));
99 assertTrue(run.contains("ln" + uniq));
100 assertTrue(run.contains("ma" + uniq + "@cacert.org"));
101 assertTrue(!run.contains("pas" + uniq));
102 assertTrue(!run.contains("pas2" + uniq));
107 public void testCheckboxesStay() throws IOException {
108 String run2 = runRegister("general=1&country=a®ional=1&radius=0");
110 .contains("name=\"general\" value=\"1\" checked=\"checked\">"));
111 assertTrue(run2.contains("name=\"country\" value=\"1\">"));
113 .contains("name=\"regional\" value=\"1\" checked=\"checked\">"));
114 assertTrue(run2.contains("name=\"radius\" value=\"1\">"));
115 run2 = runRegister("general=0&country=1&radius=1");
116 assertTrue(run2.contains("name=\"general\" value=\"1\">"));
118 .contains("name=\"country\" value=\"1\" checked=\"checked\">"));
119 assertTrue(run2.contains("name=\"regional\" value=\"1\">"));
121 .contains("name=\"radius\" value=\"1\" checked=\"checked\">"));
125 public void testDoubleMail() throws IOException {
126 long uniq = System.currentTimeMillis();
127 registerUser("RegisterTest", "User", "testmail" + uniq + "@cacert.org",
130 registerUser("RegisterTest", "User", "testmail" + uniq
131 + "@cacert.org", "registerPW");
133 "Registering a user with the same email needs to fail.");
134 } catch (AssertionError e) {
139 public void testInvalidMailbox() {
140 getMailReciever().setApproveRegex(Pattern.compile("a"));
141 long uniq = System.currentTimeMillis();
143 registerUser("RegisterTest", "User", "testInvalidMailbox" + uniq
144 + "@cacert.org", "registerPW");
146 "Registering a user with invalid mailbox must fail.");
147 } catch (AssertionError e) {
151 private void testFailedForm(String query) throws IOException {
152 String startError = fetchStartErrorMessage(runRegister(query));
153 assertTrue(startError, !startError.startsWith("</div>"));