]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/wot/TestAssurance.java
add: Allow multiple names, name-schemes, multi-name-assurance, etc.
[gigi.git] / tests / org / cacert / gigi / pages / wot / TestAssurance.java
index f104c67e81a7c161f7974bb25799c30b7ae18c48..2a68173d2d7356747084533ba4fda712271f4041 100644 (file)
@@ -10,14 +10,18 @@ import java.net.MalformedURLException;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.regex.Pattern;
 
+import org.cacert.gigi.database.GigiPreparedStatement;
+import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.ManagedTest;
+import org.cacert.gigi.util.DayDate;
 import org.hamcrest.Matcher;
 import org.junit.Before;
 import org.junit.Test;
@@ -28,6 +32,8 @@ public class TestAssurance extends ManagedTest {
 
     private String assureeM;
 
+    private int assureeName;
+
     private String cookie;
 
     @Before
@@ -37,7 +43,8 @@ public class TestAssurance extends ManagedTest {
         assureeM = createUniqueName() + "@cacert-test.org";
 
         createAssuranceUser("a", "b", assurerM, TEST_PASSWORD);
-        createVerifiedUser("a", "c", assureeM, TEST_PASSWORD);
+        int assureeId = createVerifiedUser("a", "c", assureeM, TEST_PASSWORD);
+        assureeName = User.getById(assureeId).getPreferredName().getId();
 
         cookie = login(assurerM, TEST_PASSWORD);
     }
@@ -91,7 +98,7 @@ public class TestAssurance extends ManagedTest {
     @Test
     public void testAssureFormContanisData() throws IOException {
         URLConnection uc = buildupAssureFormConnection(true);
-        uc.getOutputStream().write(("date=2000-01-01&location=testcase&rules=1&assertion=1&points=10").getBytes("UTF-8"));
+        uc.getOutputStream().write(("assuredName=" + assureeName + "&date=2000-01-01&location=testcase&rules=1&assertion=1&points=10").getBytes("UTF-8"));
         uc.getOutputStream().flush();
         String data = IOUtils.readURL(uc);
         assertThat(data, containsString("2000-01-01"));
@@ -116,36 +123,25 @@ public class TestAssurance extends ManagedTest {
         assertEquals(500, uc.getResponseCode());
     }
 
-    @Test
-    public void testAssureFormRaceName() throws IOException, SQLException {
-        testAssureFormRace(true, false);
-    }
-
     @Test
     public void testAssureFormRaceDoB() throws IOException, SQLException {
-        testAssureFormRace(false, false);
-    }
-
-    @Test
-    public void testAssureFormRaceNameBlind() throws IOException, SQLException {
-        testAssureFormRace(true, true);
+        testAssureFormRace(false);
     }
 
     @Test
     public void testAssureFormRaceDoBBlind() throws IOException, SQLException {
-        testAssureFormRace(false, true);
+        testAssureFormRace(true);
     }
 
-    public void testAssureFormRace(boolean name, boolean succeed) throws IOException, SQLException {
+    public void testAssureFormRace(boolean succeed) throws IOException, SQLException {
         URLConnection uc = buildupAssureFormConnection(true);
 
         String assureeCookie = login(assureeM, TEST_PASSWORD);
-        String newName = "lname=" + (name && !succeed ? "a" : "c") + "&fname=a&mname=&suffix=";
-        String newDob = "day=1&month=1&year=" + ( !name && !succeed ? 1911 : 1910);
+        String newDob = "day=1&month=1&year=" + ( !succeed ? 1911 : 1910);
 
-        assertNull(executeBasicWebInteraction(assureeCookie, MyDetails.PATH, newName + "&" + newDob + "&processDetails", 0));
+        assertNull(executeBasicWebInteraction(assureeCookie, MyDetails.PATH, newDob + "&action=updateDoB", 0));
 
-        uc.getOutputStream().write(("date=2000-01-01&location=testcase&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8"));
+        uc.getOutputStream().write(("assuredName=" + assureeName + "&date=2000-01-01&location=testcase&certify=1&rules=1&assertion=1&points=10").getBytes("UTF-8"));
         uc.getOutputStream().flush();
         String error = fetchStartErrorMessage(IOUtils.readURL(uc));
         if (succeed) {
@@ -227,7 +223,7 @@ public class TestAssurance extends ManagedTest {
 
     private String execute(String query) throws MalformedURLException, IOException {
         URLConnection uc = buildupAssureFormConnection(true);
-        uc.getOutputStream().write((query).getBytes("UTF-8"));
+        uc.getOutputStream().write(("assuredName=" + assureeName + "&" + query).getBytes("UTF-8"));
         uc.getOutputStream().flush();
         return IOUtils.readURL(uc);
     }
@@ -250,4 +246,35 @@ public class TestAssurance extends ManagedTest {
         return uc;
     }
 
+    @Test
+    public void testMultipleAssurance() throws IOException {
+
+        User users[] = User.findByEmail(assurerM);
+        int agentID = users[0].getId();
+
+        users = User.findByEmail(assureeM);
+        int applicantID = users[0].getId();
+
+        // enter first entry 200 days in the past
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `when`=? ")) {
+            ps.setInt(1, agentID);
+            ps.setInt(2, applicantID);
+            ps.setInt(3, 10);
+            ps.setString(4, "test-location");
+            ps.setString(5, "2010-01-01");
+            ps.setTimestamp(6, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 200));
+            ps.execute();
+        }
+
+        // enter second entry
+        String uniqueLoc = createUniqueName();
+        executeSuccess("date=2000-01-01&location=" + uniqueLoc + "&certify=1&rules=1&assertion=1&points=10");
+
+        // enter third entry on the same day
+        URLConnection uc = get(cookie, AssurePage.PATH);
+        uc.setDoOutput(true);
+        uc.getOutputStream().write(("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes("UTF-8"));
+        assertThat(IOUtils.readURL(uc), hasError());
+
+    }
 }