]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java
del: Remove unused code
[gigi.git] / tests / org / cacert / gigi / pages / admin / TestSEAdminPageDetails.java
index 228528b7074cafaa338ef8628603a8f504be739e..08541decf47f3eab2102b125983263b2d0eb4fff 100644 (file)
@@ -4,13 +4,15 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URLConnection;
+import java.sql.Timestamp;
 import java.util.Locale;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.EmailAddress;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.ObjectCache;
@@ -20,6 +22,7 @@ import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
 import org.cacert.gigi.testUtils.ClientTest;
 import org.cacert.gigi.testUtils.IOUtils;
+import org.cacert.gigi.util.DayDate;
 import org.junit.Test;
 
 public class TestSEAdminPageDetails extends ClientTest {
@@ -35,7 +38,7 @@ public class TestSEAdminPageDetails extends ClientTest {
         String fname = "Först";
         String lname = "Secönd";
         int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
-        URLConnection uc = get(SupportUserDetailsPage.PATH + id);
+        URLConnection uc = get(SupportUserDetailsPage.PATH + id + "/");
         uc.setDoOutput(true);
         String res = IOUtils.readURL(uc);
         assertThat(res, containsString(fname));
@@ -57,13 +60,13 @@ public class TestSEAdminPageDetails extends ClientTest {
         ea = EmailAddress.getById(ea.getId());
         assertTrue(ea.isVerified());
 
-        String res = IOUtils.readURL(get(SupportUserDetailsPage.PATH + id));
+        String res = IOUtils.readURL(get(SupportUserDetailsPage.PATH + id + "/"));
         assertEquals(2, countRegex(res, Pattern.quote(email)));
         assertEquals(1, countRegex(res, Pattern.quote(email2)));
 
         User.getById(id).updateDefaultEmail(ea);
         clearCaches();
-        res = IOUtils.readURL(get(SupportUserDetailsPage.PATH + id));
+        res = IOUtils.readURL(get(SupportUserDetailsPage.PATH + id + "/"));
         assertEquals(1, countRegex(res, Pattern.quote(email)));
         assertEquals(2, countRegex(res, Pattern.quote(email2)));
     }
@@ -78,33 +81,76 @@ public class TestSEAdminPageDetails extends ClientTest {
 
         assertEquals(0, logCountAdmin(id));
         assertEquals(0, logCountUser(clientCookie));
-        // chaniging both leads to 2 entries
-        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "dobd=1&dobm=2&doby=2000&detailupdate", 0));
+        // changing both leads to 2 entries
+        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id + "/", "dobd=1&dobm=2&doby=2000&detailupdate", 0));
         assertEquals(1, logCountAdmin(id));
         assertEquals(1, logCountUser(clientCookie));
 
         // Sending same data keeps same
-        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "dobd=1&dobm=2&doby=2000&detailupdate", 0));
+        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id + "/", "dobd=1&dobm=2&doby=2000&detailupdate", 0));
         assertEquals(1, logCountAdmin(id));
         assertEquals(1, logCountUser(clientCookie));
 
         // changing one leads to one entry
-        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "dobd=1&dobm=3&doby=2000&detailupdate", 0));
+        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id + "/", "dobd=1&dobm=3&doby=2000&detailupdate", 0));
         assertEquals(2, logCountAdmin(id));
         assertEquals(2, logCountUser(clientCookie));
 
         // changing one leads to one entry
-        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "dobd=2&dobm=3&doby=2000&detailupdate", 0));
+        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id + "/", "dobd=2&dobm=3&doby=2000&detailupdate", 0));
         assertEquals(3, logCountAdmin(id));
         assertEquals(3, logCountUser(clientCookie));
 
         // changing none -> no entry
-        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "dobd=2&dobm=3&doby=2000&detailupdate", 0));
+        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id + "/", "dobd=2&dobm=3&doby=2000&detailupdate", 0));
         assertEquals(3, logCountAdmin(id));
         assertEquals(3, logCountUser(clientCookie));
 
     }
 
+    @Test
+    public void testUserDetailsMyPoints() throws MalformedURLException, IOException {
+        String email = createUniqueName() + "@example.com";
+        String fname = "Först";
+        String lname = "Secönd";
+        int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
+        String clientCookie = login(email, TEST_PASSWORD);
+
+        // try to open mypoints as user
+        HttpURLConnection uc = get(clientCookie, SupportUserDetailsPage.PATH + id + "/points");
+
+        assertEquals(403, uc.getResponseCode());
+
+        // enter verification and open mypoints as supporter
+
+        makeAssurer(this.id);
+        String location = createUniqueName();
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `when`=? ")) {
+            ps.setInt(1, this.id);
+            ps.setInt(2, User.getById(id).getPreferredName().getId());
+            ps.setInt(3, 10);
+            ps.setString(4, location);
+            ps.setString(5, "2010-01-01");
+            ps.setTimestamp(6, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 200));
+            ps.execute();
+        }
+
+        uc = get(cookie, SupportUserDetailsPage.PATH + id + "/points");
+
+        String res = IOUtils.readURL(uc);
+        assertThat(res, containsString("Support User Points"));
+        assertThat(res, containsString(location));
+
+        // remove ticket number and try to access mypoints from supporter
+        // account
+        assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "deleteTicket=action", 0).getResponseCode());
+
+        uc = get(cookie, SupportUserDetailsPage.PATH + id + "/points");
+
+        assertEquals(403, uc.getResponseCode());
+
+    }
+
     private int logCountAdmin(int id) throws IOException {
         return getLogEntryCount(IOUtils.readURL(get(History.SUPPORT_PATH.replace("*", Integer.toString(id)))));
     }
@@ -127,13 +173,4 @@ public class TestSEAdminPageDetails extends ClientTest {
         return c;
     }
 
-    private String getFname(String res) {
-        Pattern p = Pattern.compile("<span class='fname'>([^<]*)</span>");
-        Matcher m = p.matcher(res);
-        if (m.find()) {
-            return m.group(1);
-        }
-        return null;
-    }
-
 }