]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
upd: rename file to match the function FindUserBy Email/Domain
[gigi.git] / tests / org / cacert / gigi / pages / admin / TestSEAdminPageUserMailSearch.java
index 23b551e7c134c544b324c407dc4fe187716e044a..593d9e9c119f2a25e806e5479af7220b66d60616 100644 (file)
@@ -4,15 +4,14 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 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;
 
 import org.cacert.gigi.dbObjects.Group;
-import org.cacert.gigi.pages.admin.support.FindUserPage;
+import org.cacert.gigi.pages.admin.support.FindUserByEmailPage;
+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;
@@ -23,23 +22,15 @@ public class TestSEAdminPageUserMailSearch extends ClientTest {
 
     public TestSEAdminPageUserMailSearch() throws IOException {
         grant(email, Group.SUPPORTER);
+        assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
     }
 
     @Test
     public void testFulltextMailSearch() throws MalformedURLException, UnsupportedEncodingException, IOException {
         String mail = createUniqueName() + "@example.com";
         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode(mail, "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+
+        URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
     }
 
@@ -47,17 +38,8 @@ public class TestSEAdminPageUserMailSearch extends ClientTest {
     public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
         String mail = createUniqueName() + "@example.tld";
         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+
+        URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
     }
 
@@ -67,17 +49,8 @@ public class TestSEAdminPageUserMailSearch extends ClientTest {
         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
         String mail2 = createUniqueName() + "@example.org";
         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode("%@example.org", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
+
         String res = IOUtils.readURL(uc);
         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
@@ -87,19 +60,11 @@ public class TestSEAdminPageUserMailSearch extends ClientTest {
     public void testWildcardMailSearchSingleChar() throws MalformedURLException, UnsupportedEncodingException, IOException {
         String mail = createUniqueName() + "@example.org";
         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
-        String mail2 = createUniqueName() + "@example.org";
+        String mail2 = createUniqueName() + "@fxample.org";
         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+
+        URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
+
         String res = IOUtils.readURL(uc);
         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
@@ -107,33 +72,14 @@ public class TestSEAdminPageUserMailSearch extends ClientTest {
 
     @Test
     public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 
     @Test
     public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
-        URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        String csrf = getCSRF(uc, 0);
-
-        uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        uc.setDoOutput(true);
-        OutputStream os = uc.getOutputStream();
-        os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
-                + "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8")).getBytes("UTF-8"));
-        os.flush();
+        URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
+
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
 }