]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/main/RegisterPageTest.java
[EMPTY] Formatting with configured formatter.
[gigi.git] / tests / org / cacert / gigi / pages / main / RegisterPageTest.java
1 package org.cacert.gigi.pages.main;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.net.HttpURLConnection;
7 import java.util.regex.Pattern;
8
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;
14
15 public class RegisterPageTest extends ManagedTest {
16         static {
17                 InitTruststore.run();
18                 HttpURLConnection.setFollowRedirects(false);
19         }
20
21         @Before
22         public void setUp() throws Exception {
23         }
24
25         @Test
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://"));
32         }
33
34         @Test
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");
37         }
38
39         @Test
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");
42         }
43
44         @Test
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");
47         }
48
49         @Test
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");
52         }
53
54         @Test
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");
57         }
58
59         @Test
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");
62         }
63
64         @Test
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");
67         }
68
69         @Test
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");
72         }
73
74         @Test
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");
79         }
80
81         @Test
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");
87         }
88
89         @Test
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");
95         }
96
97         @Test
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");
100         }
101
102         @Test
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));
112
113         }
114
115         @Test
116         public void testCheckboxesStay() throws IOException {
117                 String run2 = runRegister("general=1&country=a&regional=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\">"));
127         }
128
129         @Test
130         public void testDoubleMail() throws IOException {
131                 long uniq = System.currentTimeMillis();
132                 registerUser("RegisterTest", "User", "testmail" + uniq + "@cacert.org", "registerPW'1");
133                 try {
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) {
137
138                 }
139         }
140
141         @Test
142         public void testInvalidMailbox() {
143                 getMailReciever().setApproveRegex(Pattern.compile("a"));
144                 long uniq = System.currentTimeMillis();
145                 try {
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) {
149
150                 }
151         }
152
153         private void testFailedForm(String query) throws IOException {
154                 String startError = fetchStartErrorMessage(runRegister(query));
155                 assertTrue(startError, !startError.startsWith("</div>"));
156         }
157
158 }