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.UnsupportedEncodingException;
8 import java.net.MalformedURLException;
9 import java.net.URLConnection;
10 import java.net.URLEncoder;
12 import org.cacert.gigi.dbObjects.Group;
13 import org.cacert.gigi.pages.admin.support.FindUserPage;
14 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
15 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
16 import org.cacert.gigi.testUtils.ClientTest;
17 import org.cacert.gigi.testUtils.IOUtils;
18 import org.cacert.gigi.util.ServerConstants;
19 import org.junit.Test;
21 public class TestSEAdminPageUserMailSearch extends ClientTest {
23 public TestSEAdminPageUserMailSearch() throws IOException {
24 grant(email, Group.SUPPORTER);
25 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
29 public void testFulltextMailSearch() throws MalformedURLException, UnsupportedEncodingException, IOException {
30 String mail = createUniqueName() + "@example.com";
31 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
33 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
34 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
38 public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
39 String mail = createUniqueName() + "@example.tld";
40 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
42 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
43 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
47 public void testWildcardMailSearchMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException {
48 String mail = createUniqueName() + "@example.org";
49 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
50 String mail2 = createUniqueName() + "@example.org";
51 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
52 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
54 String res = IOUtils.readURL(uc);
55 assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
56 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
60 public void testWildcardMailSearchSingleChar() throws MalformedURLException, UnsupportedEncodingException, IOException {
61 String mail = createUniqueName() + "@example.org";
62 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
63 String mail2 = createUniqueName() + "@fxample.org";
64 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
66 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
68 String res = IOUtils.readURL(uc);
69 assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
70 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
74 public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
75 URLConnection uc = post(FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
76 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
80 public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
81 URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
83 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));