X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Fadmin%2FTestSEAdminPageUserDomainSearch.java;h=a4fb4b437b77d6084087d782ff69c53490d11bad;hp=034feaf707d587002b9df9b9d2721af8c09028fe;hb=db5449730f0f774b43a72a5d553bef34ade30e91;hpb=0fad27fa1dbd119648945ec77cd8e4a1b7965885 diff --git a/tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java b/tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java index 034feaf7..a4fb4b43 100644 --- a/tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java +++ b/tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java @@ -4,10 +4,8 @@ import static org.junit.Assert.*; import static org.junit.Assume.*; import java.io.IOException; -import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; -import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; @@ -15,7 +13,8 @@ import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Domain; import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.User; -import org.cacert.gigi.pages.admin.support.FindDomainPage; +import org.cacert.gigi.pages.admin.support.FindUserByDomainPage; +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; @@ -24,67 +23,42 @@ import org.junit.Test; public class TestSEAdminPageUserDomainSearch extends ClientTest { - public TestSEAdminPageUserDomainSearch() throws IOException { + private Domain d; + + private String domainName; + + private String unique; + + private int tid; + + public TestSEAdminPageUserDomainSearch() throws IOException, GigiApiException { grant(email, Group.SUPPORTER); + assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode()); + + String mail = createUniqueName() + "@example.com"; + tid = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD); + User user = User.getById(tid); + unique = createUniqueName(); + domainName = unique + "pattern.org"; + this.d = new Domain(user, user, domainName); } @Test public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException { - String mail = createUniqueName() + "@example.com"; - int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD); - User user = User.getById(id); - String domainName = createUniqueName() + ".org"; - Domain d = new Domain(user, domainName); - d.insert(); - URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - String csrf = getCSRF(uc, 0); + URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8")); - uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - uc.setDoOutput(true); - OutputStream os = uc.getOutputStream(); - os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" // - + "process&domain=" + URLEncoder.encode(domainName, "UTF-8")).getBytes("UTF-8")); - os.flush(); - assertEquals("https://" + ServerConstants.getWwwHostNamePort() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location")); + assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid, uc.getHeaderField("Location")); } @Test public void testDomainSearchById() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException { - String mail = createUniqueName() + "@example.com"; - int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD); - User user = User.getById(id); - String domainName = createUniqueName() + ".org"; - Domain d = new Domain(user, domainName); - d.insert(); - URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - String csrf = getCSRF(uc, 0); - - uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - uc.setDoOutput(true); - OutputStream os = uc.getOutputStream(); - os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" // - + "process&domain=#" + d.getId()).getBytes("UTF-8")); - os.flush(); - assertEquals("https://" + ServerConstants.getWwwHostNamePort() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location")); + URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId()); + assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid, uc.getHeaderField("Location")); } @Test public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException { - URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - String csrf = getCSRF(uc, 0); - - uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - uc.setDoOutput(true); - OutputStream os = uc.getOutputStream(); - os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" // - + "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8")).getBytes("UTF-8")); - os.flush(); + URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8")); assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc))); } @@ -102,16 +76,7 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest { found = true; } assumeTrue(found); - URLConnection uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - String csrf = getCSRF(uc, 0); - uc = new URL("https://" + getServerName() + FindDomainPage.PATH).openConnection(); - uc.addRequestProperty("Cookie", cookie); - uc.setDoOutput(true); - OutputStream os = uc.getOutputStream(); - os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" // - + "process&domain=#" + id).getBytes("UTF-8")); - os.flush(); + URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id); assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc))); } }