]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
95b9ec7468f616eb5c9ccabd7ca3bedc8da0b535
[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.OutputStream;
8 import java.io.UnsupportedEncodingException;
9 import java.net.MalformedURLException;
10 import java.net.URL;
11 import java.net.URLConnection;
12 import java.net.URLEncoder;
13
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;
22
23 public class TestSEAdminPageUserMailSearch extends ClientTest {
24
25     public TestSEAdminPageUserMailSearch() throws IOException {
26         grant(email, Group.SUPPORTER);
27         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
28     }
29
30     @Test
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);
34
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"));
37     }
38
39     @Test
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);
43
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"));
46     }
47
48     @Test
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);
55
56         String res = IOUtils.readURL(uc);
57         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
58         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
59     }
60
61     @Test
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);
67
68         URLConnection uc = post(cookie, FindUserPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
69
70         String res = IOUtils.readURL(uc);
71         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
72         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
73     }
74
75     @Test
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);
80
81         uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
82         uc.addRequestProperty("Cookie", cookie);
83         uc.setDoOutput(true);
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"));
87         os.flush();
88         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
89     }
90
91     @Test
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);
94
95         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
96     }
97 }