fix: number-format-exception thrown on assurance entry
authorFelix Dörre <felix@dogcraft.de>
Mon, 4 Jul 2016 08:57:20 +0000 (10:57 +0200)
committerFelix Dörre <felix@dogcraft.de>
Mon, 4 Jul 2016 10:41:27 +0000 (12:41 +0200)
Change-Id: I5625e53d219360687915b80fb26da6aba1353260

src/org/cacert/gigi/pages/wot/AssurePage.java
tests/org/cacert/gigi/pages/wot/TestAssurance.java

index e0cb4a211e57aed40125df653ee99a163283807e..dfd72b7b6966a85536a8c2f5cf7b3dd97fe1c61e 100644 (file)
@@ -2,8 +2,6 @@ package org.cacert.gigi.pages.wot;
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.sql.Date;
-import java.util.Calendar;
 import java.util.HashMap;
 
 import javax.servlet.http.HttpServletRequest;
@@ -73,10 +71,10 @@ public class AssurePage extends Page {
         }
 
         try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `users`.`id`, `verified` FROM `users` INNER JOIN `certOwners` ON `certOwners`.`id`=`users`.`id` WHERE `email`=? AND `dob`=? AND `deleted` IS NULL")) {
+            ds.update(req);
+
             ps.setString(1, req.getParameter("email"));
-            Calendar c = Calendar.getInstance();
-            c.set(Integer.parseInt(req.getParameter("year")), Integer.parseInt(req.getParameter("month")) - 1, Integer.parseInt(req.getParameter("day")));
-            ps.setDate(2, new Date(c.getTimeInMillis()));
+            ps.setDate(2, ds.getDate().toSQLDate());
             GigiResultSet rs = ps.executeQuery();
             int id = 0;
             if (rs.next()) {
@@ -101,11 +99,12 @@ public class AssurePage extends Page {
                     }
                 }
             } else {
-                GigiApiException e = new GigiApiException("I'm sorry, there was no email and date of birth matching" //
+                throw new GigiApiException("I'm sorry, there was no email and date of birth matching" //
                         + " what you entered in the system. Please double check your information.");
-                e.format(out, getLanguage(req));
             }
 
+        } catch (GigiApiException e) {
+            e.format(out, getLanguage(req));
         }
     }
 }
index d626cee0a3e55c18a37c0efd39473df368cc07ae..6a585abd4e1dc64acdae125289cc8bcb596be2b1 100644 (file)
@@ -53,6 +53,12 @@ public class TestAssurance extends ManagedTest {
         assertTrue(loc, !loc.contains("type=\"checkbox\" name=\"tos_agree\""));
     }
 
+    @Test
+    public void testAssureSearchDobInvalid() throws IOException {
+        String loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=mal");
+        assertNotNull(fetchStartErrorMessage(loc));
+    }
+
     @Test
     public void testAssureSearchDob() throws IOException {
         String loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=2&month=1&year=1910");