]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/wot/TestAssurance.java
UPD: use more advanced hamcrest matchers where possible.
[gigi.git] / tests / org / cacert / gigi / pages / wot / TestAssurance.java
index 94f194a3a7bd7aa1a330e30c1f67e8e4b86d6fd5..03e499df6143e903ca0707897b6c295994758338 100644 (file)
@@ -1,5 +1,8 @@
 package org.cacert.gigi.pages.wot;
 
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
@@ -11,6 +14,7 @@ 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.testUtils.IOUtils;
@@ -18,8 +22,6 @@ import org.cacert.gigi.testUtils.ManagedTest;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
-
 public class TestAssurance extends ManagedTest {
 
     private String assurerM;
@@ -45,23 +47,23 @@ public class TestAssurance extends ManagedTest {
     @Test
     public void testAssureSearch() throws IOException {
         String loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1910");
-        assertTrue(loc, loc.endsWith(AssurePage.PATH + "/" + assuree));
+        assertTrue(loc, loc.contains("type=\"checkbox\" name=\"CCAAgreed\""));
     }
 
     @Test
     public void testAssureSearchEmail() throws IOException {
         String loc = search("email=1" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1910");
-        assertNull(loc);
+        assertTrue(loc, !loc.contains("type=\"checkbox\" name=\"CCAAgreed\""));
     }
 
     @Test
     public void testAssureSearchDob() throws IOException {
         String loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=2&month=1&year=1910");
-        assertNull(loc);
+        assertTrue(loc, !loc.contains("type=\"checkbox\" name=\"CCAAgreed\""));
         loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=2&year=1910");
-        assertNull(loc);
+        assertTrue(loc, !loc.contains("type=\"checkbox\" name=\"CCAAgreed\""));
         loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1911");
-        assertNull(loc);
+        assertTrue(loc, !loc.contains("type=\"checkbox\" name=\"CCAAgreed\""));
     }
 
     private String search(String query) throws MalformedURLException, IOException, UnsupportedEncodingException {
@@ -69,17 +71,16 @@ public class TestAssurance extends ManagedTest {
         URLConnection uc = u.openConnection();
         uc.setDoOutput(true);
         uc.addRequestProperty("Cookie", cookie);
-        uc.getOutputStream().write((query).getBytes());
+        uc.getOutputStream().write(("search&" + query).getBytes());
         uc.getOutputStream().flush();
 
-        String loc = uc.getHeaderField("Location");
-        return loc;
+        return IOUtils.readURL(uc);
     }
 
     @Test
     public void testAssureForm() throws IOException {
         String error = getError("date=2000-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
-        assertTrue(error, error.startsWith("</div>"));
+        assertNull(error);
     }
 
     @Test
@@ -148,6 +149,32 @@ public class TestAssurance extends ManagedTest {
         assertTrue(error, !error.startsWith("</div>"));
     }
 
+    @Test
+    public void testAssureListingValid() throws IOException {
+        String uniqueLoc = createUniqueName();
+        String error = getError("date=2000-01-01&location=" + uniqueLoc + "&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
+        assertNull(error);
+        String cookie = login(assureeM, TEST_PASSWORD);
+        URLConnection url = new URL("https://" + getServerName() + MyPoints.PATH).openConnection();
+        url.setRequestProperty("Cookie", cookie);
+        String resp = IOUtils.readURL(url);
+        resp = resp.split(Pattern.quote("</table>"))[0];
+        assertThat(resp, containsString(uniqueLoc));
+    }
+
+    @Test
+    public void testAssurerListingValid() throws IOException {
+        String uniqueLoc = createUniqueName();
+        String error = getError("date=2000-01-01&location=" + uniqueLoc + "&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10");
+        assertNull(error);
+        String cookie = login(assurerM, TEST_PASSWORD);
+        URLConnection url = new URL("https://" + getServerName() + MyPoints.PATH).openConnection();
+        url.setRequestProperty("Cookie", cookie);
+        String resp = IOUtils.readURL(url);
+        resp = resp.split(Pattern.quote("</table>"))[1];
+        assertThat(resp, containsString(uniqueLoc));
+    }
+
     private String getError(String query) throws MalformedURLException, IOException {
         URLConnection uc = buildupAssureFormConnection(true);
         uc.getOutputStream().write((query).getBytes());
@@ -157,9 +184,12 @@ public class TestAssurance extends ManagedTest {
     }
 
     private URLConnection buildupAssureFormConnection(boolean doCSRF) throws MalformedURLException, IOException {
-        URL u = new URL("https://" + getServerName() + AssurePage.PATH + "/" + assuree);
+        URL u = new URL("https://" + getServerName() + AssurePage.PATH);
         URLConnection uc = u.openConnection();
         uc.addRequestProperty("Cookie", cookie);
+        uc.setDoOutput(true);
+        uc.getOutputStream().write(("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes());
+
         String csrf = getCSRF(uc);
         uc = u.openConnection();
         uc.addRequestProperty("Cookie", cookie);