]> WPIA git - gigi.git/commitdiff
adding cca_agree to signup page
authorFelix Dörre <felix@dogcraft.de>
Mon, 23 Jun 2014 16:15:47 +0000 (18:15 +0200)
committerFelix Dörre <felix@dogcraft.de>
Mon, 23 Jun 2014 19:38:21 +0000 (21:38 +0200)
src/org/cacert/gigi/pages/main/Signup.java
tests/org/cacert/gigi/pages/main/RegisterPageTest.java

index 060f82ba20e383ccf39968cf986615370bbc1a7f..b13b374fbae105f5fcb2ed864eed8670e1c632b5 100644 (file)
@@ -97,6 +97,11 @@ public class Signup {
                        outputError(out, req, "Invalid date of birth");
                        failed = true;
                }
+               if (!"1".equals(req.getParameter("cca_agree"))) {
+                       outputError(out, req,
+                                       "You have to agree to the CAcert Community agreement.");
+                       failed = true;
+               }
                if (buildup.getEmail().equals("")) {
                        outputError(out, req, "Email Address was blank");
                        failed = true;
@@ -111,6 +116,10 @@ public class Signup {
                        failed = true;
                }
                // TODO check password strength
+               if (failed) {
+                       out.println("</div>");
+                       return false;
+               }
                try {
                        PreparedStatement q1 = DatabaseConnection.getInstance().prepare(
                                        "select * from `email` where `email`=? and `deleted`=0");
@@ -149,8 +158,14 @@ public class Signup {
                        e.printStackTrace();
                        failed = true;
                }
+               // TODO fast-check mail
+
                out.println("</div>");
-               return failed;
+               if (failed) {
+                       return false;
+               }
+               // TODO start getting to work
+               return true;
        }
        private void outputError(PrintWriter out, ServletRequest req, String text) {
                out.print("<div>");
index 96395a01caffd7807e05c04af4ef19cc1e3d32b0..97e6f8182fdb7e1cd6287c2d4ae5231b7d962446 100644 (file)
@@ -32,61 +32,70 @@ public class RegisterPageTest {
        @Before
        public void setUp() throws Exception {
        }
+       @Test
+       public void testSuccess() throws IOException {
+               String startError = fetchStartErrorMessage("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
+               assertTrue(startError, startError.startsWith("</div>"));
+       }
 
        @Test
        public void testNoFname() throws IOException {
-               testFailedForm("lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910");
+               testFailedForm("lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
        }
        @Test
        public void testNoLname() throws IOException {
-               testFailedForm("fname=a&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910");
+               testFailedForm("fname=a&email=e&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
        }
        @Test
        public void testNoEmail() throws IOException {
-               testFailedForm("fname=a&lname=b&pword1=ap&pword2=ap&day=1&month=1&year=1910");
+               testFailedForm("fname=a&lname=b&pword1=ap&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
        }
 
        @Test
        public void testNoPword() throws IOException {
-               testFailedForm("fname=a&lname=b&email=e&pword2=ap&day=1&month=1&year=1910");
+               testFailedForm("fname=a&lname=b&email=e&pword2=ap&day=1&month=1&year=1910&cca_agree=1");
        }
 
        @Test
        public void testDiffPword() throws IOException {
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap2&day=1&month=1&year=1910");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap2&day=1&month=1&year=1910&cca_agree=1");
        }
 
        @Test
        public void testNoDay() throws IOException {
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&month=1&year=1910");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&month=1&year=1910&cca_agree=1");
        }
        @Test
        public void testNoMonth() throws IOException {
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&year=1910");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&year=1910&cca_agree=1");
        }
        @Test
        public void testNoYear() throws IOException {
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&cca_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");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=0&month=1&year=1910");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=a&month=1&year=1910");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=40&month=1&year=1910&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=0&month=1&year=1910&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=a&month=1&year=1910&cca_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");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=0&year=1910");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=-1&year=1910");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=a&year=1910");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=20&year=1910&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=0&year=1910&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=-1&year=1910&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=a&year=1910&cca_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");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=100");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=a");
-               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=-1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=0&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=100&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=a&cca_agree=1");
+               testFailedForm("fname=a&lname=b&email=e&pword1=ap&pword2=ap&day=1&month=1&year=-1&cca_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&cca_agree=a");
        }
 
        @Test
@@ -127,18 +136,29 @@ public class RegisterPageTest {
                long uniq = System.currentTimeMillis();
                registerUser("RegisterTest", "User", "testmail" + uniq + "@cacert.org",
                                "registerPW");
-               registerUser("RegisterTest", "User", "testmail" + uniq + "@cacert.org",
-                               "registerPW");
+               try {
+                       registerUser("RegisterTest", "User", "testmail" + uniq
+                                       + "@cacert.org", "registerPW");
+                       throw new Error(
+                                       "Registering a user with the same email needs to fail.");
+               } catch (AssertionError e) {
+
+               }
        }
 
        private static void testFailedForm(String query) throws IOException {
+               String startError = fetchStartErrorMessage(query);
+               assertTrue(startError, !startError.startsWith("</div>"));
+       }
+       private static String fetchStartErrorMessage(String query)
+                       throws IOException {
                String d = runRegister(query);
                String formFail = "<div class='formError'>";
                int idx = d.indexOf(formFail);
                assertNotEquals(-1, idx);
                String startError = d.substring(idx + formFail.length(), idx + 100)
                                .trim();
-               assertTrue(startError, !startError.startsWith("</div>"));
+               return startError;
        }
 
        public static void registerUser(String firstName, String lastName,
@@ -146,15 +166,18 @@ public class RegisterPageTest {
                try {
                        String query = "fname=" + URLEncoder.encode(firstName, "UTF-8")
                                        + "&lname=" + URLEncoder.encode(lastName, "UTF-8")
-                                       + "&email=" + URLEncoder.encode(firstName, "UTF-8")
+                                       + "&email=" + URLEncoder.encode(email, "UTF-8")
                                        + "&pword1=" + URLEncoder.encode(password, "UTF-8")
                                        + "&pword2=" + URLEncoder.encode(password, "UTF-8")
-                                       + "&day=1&month=1&year=1910";
+                                       + "&day=1&month=1&year=1910&cca_agree=1";
+                       String data = fetchStartErrorMessage(query);
+                       assertTrue(data, data.startsWith("</div>"));
                } catch (UnsupportedEncodingException e) {
-                       e.printStackTrace();
+                       throw new Error(e);
+               } catch (IOException e) {
+                       throw new Error(e);
                }
        }
-
        private static String runRegister(String param) throws IOException {
                HttpURLConnection uc = (HttpURLConnection) registerService
                                .openConnection();