X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Fadmin%2FTestSEAdminPageDetails.java;h=44c23535a9bfe5d8c422a754268fe85cbfb63ef3;hp=3cb78b9a10b232b91de888fc500739de040366b9;hb=3b3fb85a74a666a9377549b04be32e8282c58a5b;hpb=330e2b7a3c2e525fee83ee5392df483e1be1f399 diff --git a/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java b/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java index 3cb78b9a..44c23535 100644 --- a/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java +++ b/tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java @@ -4,19 +4,26 @@ 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.URL; 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.pages.account.MyDetails; +import org.cacert.gigi.dbObjects.ObjectCache; +import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.pages.account.History; 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 { @@ -32,38 +39,37 @@ public class TestSEAdminPageDetails extends ClientTest { String fname = "Först"; String lname = "Secönd"; int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD); - URLConnection uc = new URL("https://" + getServerName() + SupportUserDetailsPage.PATH + id).openConnection(); - uc.addRequestProperty("Cookie", cookie); + URLConnection uc = get(SupportUserDetailsPage.PATH + id); uc.setDoOutput(true); String res = IOUtils.readURL(uc); - assertThat(res, containsString("")); - assertThat(res, containsString("")); + assertThat(res, containsString(fname)); + assertThat(res, containsString(lname)); assertThat(res, containsString(email)); } @Test - public void testUserDetailsEdit() throws MalformedURLException, IOException { + public void testUserDetailsEmail() throws MalformedURLException, IOException, GigiApiException { String email = createUniqueName() + "@example.com"; String fname = "Först"; String lname = "Secönd"; int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD); - - String userCookie = login(email, TEST_PASSWORD); - assertEquals("Först", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH)))); - // User can change his name - assertNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0)); - assertEquals("Kurti", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH)))); - // But when assurer - makeAssurer(id); - // User cannot change his name, and the form changed - assertNotNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti2&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0)); - assertNull(getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH)))); - assertEquals("Kurti", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH)))); - - // but support still can - assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti3&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0)); - assertEquals("Kurti3", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH)))); - + String email2 = createUniqueName() + "@example.com"; + EmailAddress ea = new EmailAddress(User.getById(id), email2, Locale.ENGLISH); + getMailReceiver().receive().verify(); + // Refresh email Object + ObjectCache.clearAllCaches(); + ea = EmailAddress.getById(ea.getId()); + assertTrue(ea.isVerified()); + + 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)); + assertEquals(1, countRegex(res, Pattern.quote(email))); + assertEquals(2, countRegex(res, Pattern.quote(email2))); } @Test @@ -76,30 +82,73 @@ 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, "fname=Kurti&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0)); - assertEquals(2, logCountAdmin(id)); - assertEquals(2, logCountUser(clientCookie)); + // 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, "fname=Kurti&lname=Hansel&mname=&suffix=&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)); assertEquals(2, logCountAdmin(id)); assertEquals(2, logCountUser(clientCookie)); // changing one leads to one entry - assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti2&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&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 one leads to one entry - assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti2&lname=Hansel&mname=&suffix=&dobd=2&dobm=2&doby=2000&detailupdate", 0)); - assertEquals(4, logCountAdmin(id)); - assertEquals(4, logCountUser(clientCookie)); - // changing none -> no entry - assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti2&lname=Hansel&mname=&suffix=&dobd=2&dobm=2&doby=2000&detailupdate", 0)); - assertEquals(4, logCountAdmin(id)); - assertEquals(4, logCountUser(clientCookie)); + 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()); } @@ -126,7 +175,7 @@ public class TestSEAdminPageDetails extends ClientTest { } private String getFname(String res) { - Pattern p = Pattern.compile(""); + Pattern p = Pattern.compile("([^<]*)"); Matcher m = p.matcher(res); if (m.find()) { return m.group(1); @@ -134,12 +183,4 @@ public class TestSEAdminPageDetails extends ClientTest { return null; } - private String getFnamePlain(String res) { - Pattern p = Pattern.compile("\\s*First Name: \\s*([^<]*)"); - Matcher m = p.matcher(res); - if (m.find()) { - return m.group(1); - } - return null; - } }