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 {
26 public void testSuccess() throws IOException {
27 long uniq = System.currentTimeMillis();
28 registerUser("ab", "b", "correct" + uniq + "@email.de", "ap12UI.'");
29 TestMail tm = waitForMail();
30 String link = tm.extractLink();
31 assertTrue(link, link.startsWith("https://"));
35 public void testNoFname() throws IOException {
36 testFailedForm("lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
40 public void testNoLname() throws IOException {
41 testFailedForm("fname=a&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
45 public void testNoEmail() throws IOException {
46 testFailedForm("fname=a&lname=b&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
50 public void testNoPword() throws IOException {
51 testFailedForm("fname=a&lname=b&email=e&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
55 public void testDiffPword() throws IOException {
56 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap2&day=1&month=1&year=1910&cca_agree=1");
60 public void testNoDay() throws IOException {
61 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&month=1&year=1910&cca_agree=1");
65 public void testNoMonth() throws IOException {
66 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&year=1910&cca_agree=1");
70 public void testNoYear() throws IOException {
71 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&cca_agree=1");
75 public void testInvDay() throws IOException {
76 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=40&month=1&year=1910&cca_agree=1");
77 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=0&month=1&year=1910&cca_agree=1");
78 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=a&month=1&year=1910&cca_agree=1");
82 public void testInvMonth() throws IOException {
83 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=20&year=1910&cca_agree=1");
84 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=0&year=1910&cca_agree=1");
85 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=-1&year=1910&cca_agree=1");
86 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=a&year=1910&cca_agree=1");
90 public void testInvYear() throws IOException {
91 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=0&cca_agree=1");
92 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=100&cca_agree=1");
93 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=a&cca_agree=1");
94 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=-1&cca_agree=1");
98 public void testNoAgree() throws IOException {
99 testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=a");
103 public void testDataStays() throws IOException {
104 long uniq = System.currentTimeMillis();
105 String run = runRegister("fname=fn" + uniq + "&lname=ln" + uniq + "&email=ma" + uniq + "@cacert.org&pword1=pas"
106 + uniq + "&pword2=pas2" + uniq + "&day=1&month=1&year=0");
107 assertTrue(run.contains("fn" + uniq));
108 assertTrue(run.contains("ln" + uniq));
109 assertTrue(run.contains("ma" + uniq + "@cacert.org"));
110 assertTrue(!run.contains("pas" + uniq));
111 assertTrue(!run.contains("pas2" + uniq));
116 public void testCheckboxesStay() throws IOException {
117 String run2 = runRegister("general=1&country=a®ional=1&radius=0");
118 assertTrue(run2.contains("name=\"general\" value=\"1\" checked=\"checked\">"));
119 assertTrue(run2.contains("name=\"country\" value=\"1\">"));
120 assertTrue(run2.contains("name=\"regional\" value=\"1\" checked=\"checked\">"));
121 assertTrue(run2.contains("name=\"radius\" value=\"1\">"));
122 run2 = runRegister("general=0&country=1&radius=1");
123 assertTrue(run2.contains("name=\"general\" value=\"1\">"));
124 assertTrue(run2.contains("name=\"country\" value=\"1\" checked=\"checked\">"));
125 assertTrue(run2.contains("name=\"regional\" value=\"1\">"));
126 assertTrue(run2.contains("name=\"radius\" value=\"1\" checked=\"checked\">"));
130 public void testDoubleMail() throws IOException {
131 long uniq = System.currentTimeMillis();
132 registerUser("RegisterTest", "User", "testmail" + uniq + "@cacert.org", "registerPW'1");
134 registerUser("RegisterTest", "User", "testmail" + uniq + "@cacert.org", "registerPW");
135 throw new Error("Registering a user with the same email needs to fail.");
136 } catch (AssertionError e) {
142 public void testInvalidMailbox() {
143 getMailReciever().setApproveRegex(Pattern.compile("a"));
144 long uniq = System.currentTimeMillis();
146 registerUser("RegisterTest", "User", "testInvalidMailbox" + uniq + "@cacert.org", "registerPW");
147 throw new Error("Registering a user with invalid mailbox must fail.");
148 } catch (AssertionError e) {
153 private void testFailedForm(String query) throws IOException {
154 String startError = fetchStartErrorMessage(runRegister(query));
155 assertTrue(startError, !startError.startsWith("</div>"));