From: Felix Dörre Date: Tue, 10 Nov 2015 23:30:03 +0000 (+0100) Subject: fix: allow assurance in +12 hours (due to date/timezone issues) X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=7c4d8d1effca280cbb6ac0cc8add1157e484e76b fix: allow assurance in +12 hours (due to date/timezone issues) --- diff --git a/src/org/cacert/gigi/util/Notary.java b/src/org/cacert/gigi/util/Notary.java index a2dfe0f8..3823cf7d 100644 --- a/src/org/cacert/gigi/util/Notary.java +++ b/src/org/cacert/gigi/util/Notary.java @@ -1,7 +1,9 @@ package org.cacert.gigi.util; import java.text.ParseException; +import java.util.Calendar; import java.util.Date; +import java.util.GregorianCalendar; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.DatabaseConnection; @@ -85,7 +87,10 @@ public class Notary { } else { try { Date d = DateSelector.getDateFormat().parse(date); - if (d.getTime() > System.currentTimeMillis()) { + Calendar gc = GregorianCalendar.getInstance(); + gc.setTimeInMillis(System.currentTimeMillis()); + gc.add(Calendar.HOUR_OF_DAY, 12); + if (d.getTime() > gc.getTimeInMillis()) { gae.mergeInto(new GigiApiException("You must not enter a date in the future.")); } } catch (ParseException e) { diff --git a/tests/org/cacert/gigi/pages/wot/TestAssurance.java b/tests/org/cacert/gigi/pages/wot/TestAssurance.java index 134f7427..b6396a17 100644 --- a/tests/org/cacert/gigi/pages/wot/TestAssurance.java +++ b/tests/org/cacert/gigi/pages/wot/TestAssurance.java @@ -12,6 +12,7 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.sql.SQLException; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.regex.Pattern; @@ -140,6 +141,17 @@ public class TestAssurance extends ManagedTest { assertTrue(error, !error.startsWith("")); } + @Test + public void testAssureFormFutureOK() throws IOException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(System.currentTimeMillis()); + c.add(Calendar.HOUR_OF_DAY, 12); + + String error = getError("date=" + sdf.format(new Date(c.getTimeInMillis())) + "&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10"); + assertNull(error); + } + @Test public void testAssureFormNoLoc() throws IOException { String error = getError("date=2000-01-01&location=a&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");