X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Fwot%2FTestAssurance.java;h=f519fb4e4744c4cbab15a775200efc3d3228f0d0;hb=0d1d3c357c8274c519270abc61b668bff637c40a;hp=3db48d65e65abdcfefdb4d1a28464b7cb3ad300a;hpb=6b2e44980e51485db1a4e1e62b3db0d00d2bec10;p=gigi.git diff --git a/tests/org/cacert/gigi/pages/wot/TestAssurance.java b/tests/org/cacert/gigi/pages/wot/TestAssurance.java index 3db48d65..f519fb4e 100644 --- a/tests/org/cacert/gigi/pages/wot/TestAssurance.java +++ b/tests/org/cacert/gigi/pages/wot/TestAssurance.java @@ -1,5 +1,6 @@ package org.cacert.gigi.pages.wot; +import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import java.io.IOException; @@ -9,13 +10,12 @@ 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 java.util.regex.Pattern; -import org.cacert.gigi.database.DatabaseConnection; +import org.cacert.gigi.pages.account.MyDetails; import org.cacert.gigi.testUtils.IOUtils; import org.cacert.gigi.testUtils.ManagedTest; import org.junit.Before; @@ -38,7 +38,7 @@ public class TestAssurance extends ManagedTest { assurerM = createUniqueName() + "@cacert-test.org"; assureeM = createUniqueName() + "@cacert-test.org"; assurer = createAssuranceUser("a", "b", assurerM, TEST_PASSWORD); - assuree = createAssuranceUser("a", "c", assureeM, TEST_PASSWORD); + assuree = createVerifiedUser("a", "c", assureeM, TEST_PASSWORD); cookie = login(assurerM, TEST_PASSWORD); } @@ -101,11 +101,24 @@ public class TestAssurance extends ManagedTest { } @Test - public void testAssureFormRace() throws IOException, SQLException { + public void testAssureFormRaceName() throws IOException, SQLException { + testAssureFormRace(true); + } + + @Test + public void testAssureFormRaceDoB() throws IOException, SQLException { + testAssureFormRace(false); + } + + public void testAssureFormRace(boolean name) throws IOException, SQLException { URLConnection uc = buildupAssureFormConnection(true); - PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `users` SET email='changed' WHERE id=?"); - ps.setInt(1, assuree); - ps.execute(); + + String assureeCookie = login(assureeM, TEST_PASSWORD); + String newName = "lname=" + (name ? "c" : "a") + "&fname=a&mname=&suffix="; + String newDob = "day=1&month=1&year=" + (name ? 1910 : 1911); + + assertNull(executeBasicWebInteraction(assureeCookie, MyDetails.PATH, newName + "&" + newDob + "&processDetails", 0)); + 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)); @@ -114,7 +127,7 @@ public class TestAssurance extends ManagedTest { @Test public void testAssureFormFuture() throws IOException { - SimpleDateFormat sdf = new SimpleDateFormat("YYYY"); + 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&points=10"); assertTrue(error, !error.startsWith("")); @@ -158,7 +171,7 @@ public class TestAssurance extends ManagedTest { url.setRequestProperty("Cookie", cookie); String resp = IOUtils.readURL(url); resp = resp.split(Pattern.quote(""))[0]; - assertTrue(resp.contains(uniqueLoc)); + assertThat(resp, containsString(uniqueLoc)); } @Test @@ -171,7 +184,7 @@ public class TestAssurance extends ManagedTest { url.setRequestProperty("Cookie", cookie); String resp = IOUtils.readURL(url); resp = resp.split(Pattern.quote(""))[1]; - assertTrue(resp.contains(uniqueLoc)); + assertThat(resp, containsString(uniqueLoc)); } private String getError(String query) throws MalformedURLException, IOException {