]> WPIA git - gigi.git/blob - 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
1 package org.cacert.gigi.pages.admin;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
5
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;
11
12 import org.cacert.gigi.dbObjects.Group;
13 import org.cacert.gigi.pages.admin.support.FindUserByEmailPage;
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;
20
21 public class TestSEAdminPageUserMailSearch extends ClientTest {
22
23     public TestSEAdminPageUserMailSearch() throws IOException {
24         grant(email, Group.SUPPORTER);
25         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
26     }
27
28     @Test
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);
32
33         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
34         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
35     }
36
37     @Test
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);
41
42         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
43         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
44     }
45
46     @Test
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, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
53
54         String res = IOUtils.readURL(uc);
55         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
56         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
57     }
58
59     @Test
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);
65
66         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
67
68         String res = IOUtils.readURL(uc);
69         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
70         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
71     }
72
73     @Test
74     public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
75         URLConnection uc = post(FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
76         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
77     }
78
79     @Test
80     public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
81         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
82
83         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
84     }
85 }