]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/wot/TestAssurance.java
Add the race condition test case.
[gigi.git] / tests / org / cacert / gigi / pages / wot / TestAssurance.java
index 73d60cadfb1ff51da7cdbb10412627122cc1afc8..b81a433390d431c6914ae86b796a513573795d1b 100644 (file)
@@ -6,10 +6,13 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import org.cacert.gigi.IOUtils;
+import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Before;
 import org.junit.Test;
@@ -70,43 +73,58 @@ public class TestAssurance extends ManagedTest {
        }
        @Test
        public void testAssureForm() throws IOException {
-               String error = getError("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1");
+               String error = getError("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, error.startsWith("</div>"));
        }
+
+       @Test
+       public void testAssureFormRace() throws IOException, SQLException {
+               URLConnection uc = buildupAssureFormConnection();
+               PreparedStatement ps = DatabaseConnection.getInstance().prepare(
+                               "UPDATE `users` SET email='changed' WHERE id=?");
+               ps.setInt(1, assuree);
+               ps.execute();
+               uc.getOutputStream()
+                               .write(("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10")
+                                               .getBytes());
+               uc.getOutputStream().flush();
+               String error = fetchStartErrorMessage(IOUtils.readURL(uc));
+               assertTrue(error, !error.startsWith("</div>"));
+       }
        @Test
-       public void testAssureFormFufure() throws IOException {
+       public void testAssureFormFuture() throws IOException {
                SimpleDateFormat sdf = new SimpleDateFormat("YYYY");
                int year = Integer.parseInt(sdf.format(new Date(System
                                .currentTimeMillis()))) + 2;
                String error = getError("date="
                                + year
-                               + "-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1");
+                               + "-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
        }
        @Test
        public void testAssureFormNoLoc() throws IOException {
-               String error = getError("date=2000-01-01&location=a&certify=1&rules=1&CCAAgreed=1&assertion=1");
+               String error = getError("date=2000-01-01&location=a&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
-               error = getError("date=2000-01-01&location=&certify=1&rules=1&CCAAgreed=1&assertion=1");
+               error = getError("date=2000-01-01&location=&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
        }
 
        @Test
        public void testAssureFormInvalDate() throws IOException {
-               String error = getError("date=20000101&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1");
+               String error = getError("date=20000101&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
-               error = getError("date=&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1");
+               error = getError("date=&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
        }
        @Test
        public void testAssureFormBoxes() throws IOException {
-               String error = getError("date=2000-01-01&location=testcase&certify=0&rules=1&CCAAgreed=1&assertion=1");
+               String error = getError("date=2000-01-01&location=testcase&certify=0&rules=1&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
-               error = getError("date=2000-01-01&location=testcase&certify=1&rules=&CCAAgreed=1&assertion=1");
+               error = getError("date=2000-01-01&location=testcase&certify=1&rules=&CCAAgreed=1&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
-               error = getError("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=a&assertion=1");
+               error = getError("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=a&assertion=1&points=10");
                assertTrue(error, !error.startsWith("</div>"));
-               error = getError("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=z");
+               error = getError("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=z&points=10");
                assertTrue(error, !error.startsWith("</div>"));
        }
        private String getError(String query) throws MalformedURLException,