1 package org.cacert.gigi.pages.admin;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.io.IOException;
7 import java.io.OutputStream;
8 import java.io.UnsupportedEncodingException;
9 import java.net.MalformedURLException;
11 import java.net.URLConnection;
12 import java.net.URLEncoder;
14 import org.cacert.gigi.dbObjects.Group;
15 import org.cacert.gigi.pages.admin.support.FindUserPage;
16 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
17 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
18 import org.cacert.gigi.testUtils.ClientTest;
19 import org.cacert.gigi.testUtils.IOUtils;
20 import org.cacert.gigi.util.ServerConstants;
21 import org.junit.Test;
23 public class TestSEAdminPageUserMailSearch extends ClientTest {
25 public TestSEAdminPageUserMailSearch() throws IOException {
26 grant(email, Group.SUPPORTER);
27 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
31 public void testFulltextMailSearch() throws MalformedURLException, UnsupportedEncodingException, IOException {
32 String mail = createUniqueName() + "@example.com";
33 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
35 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
36 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
40 public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
41 String mail = createUniqueName() + "@example.tld";
42 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
44 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
45 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
49 public void testWildcardMailSearchMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException {
50 String mail = createUniqueName() + "@example.org";
51 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
52 String mail2 = createUniqueName() + "@example.org";
53 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
54 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
56 String res = IOUtils.readURL(uc);
57 assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
58 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
62 public void testWildcardMailSearchSingleChar() throws MalformedURLException, UnsupportedEncodingException, IOException {
63 String mail = createUniqueName() + "@example.org";
64 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
65 String mail2 = createUniqueName() + "@fxample.org";
66 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
68 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
70 String res = IOUtils.readURL(uc);
71 assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
72 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
76 public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
77 URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
78 uc.addRequestProperty("Cookie", cookie);
79 String csrf = getCSRF(uc, 0);
81 uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
82 uc.addRequestProperty("Cookie", cookie);
84 OutputStream os = uc.getOutputStream();
85 os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
86 + "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8")).getBytes("UTF-8"));
88 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
92 public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
93 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
95 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));