]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
fix: several testcases to the new configuration/structure
[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.SupportUserDetailsPage;
17 import org.cacert.gigi.testUtils.ClientTest;
18 import org.cacert.gigi.testUtils.IOUtils;
19 import org.cacert.gigi.util.ServerConstants;
20 import org.junit.Test;
21
22 public class TestSEAdminPageUserMailSearch extends ClientTest {
23
24     public TestSEAdminPageUserMailSearch() throws IOException {
25         grant(email, Group.SUPPORTER);
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         URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
33         uc.addRequestProperty("Cookie", cookie);
34         String csrf = getCSRF(uc, 0);
35
36         uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
37         uc.addRequestProperty("Cookie", cookie);
38         uc.setDoOutput(true);
39         OutputStream os = uc.getOutputStream();
40         os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
41                 + "process&email=" + URLEncoder.encode(mail, "UTF-8")).getBytes("UTF-8"));
42         os.flush();
43         assertEquals("https://" + ServerConstants.getWwwHostNamePort() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
44     }
45
46     @Test
47     public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
48         String mail = createUniqueName() + "@example.tld";
49         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
50         URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
51         uc.addRequestProperty("Cookie", cookie);
52         String csrf = getCSRF(uc, 0);
53
54         uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
55         uc.addRequestProperty("Cookie", cookie);
56         uc.setDoOutput(true);
57         OutputStream os = uc.getOutputStream();
58         os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
59                 + "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8")).getBytes("UTF-8"));
60         os.flush();
61         assertEquals("https://" + ServerConstants.getWwwHostNamePort() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
62     }
63
64     @Test
65     public void testWildcardMailSearchMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException {
66         String mail = createUniqueName() + "@example.org";
67         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
68         String mail2 = createUniqueName() + "@example.org";
69         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
70         URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
71         uc.addRequestProperty("Cookie", cookie);
72         String csrf = getCSRF(uc, 0);
73
74         uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
75         uc.addRequestProperty("Cookie", cookie);
76         uc.setDoOutput(true);
77         OutputStream os = uc.getOutputStream();
78         os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
79                 + "process&email=" + URLEncoder.encode("%@example.org", "UTF-8")).getBytes("UTF-8"));
80         os.flush();
81         String res = IOUtils.readURL(uc);
82         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
83         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
84     }
85
86     @Test
87     public void testWildcardMailSearchSingleChar() throws MalformedURLException, UnsupportedEncodingException, IOException {
88         String mail = createUniqueName() + "@example.org";
89         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
90         String mail2 = createUniqueName() + "@example.org";
91         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
92         URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
93         uc.addRequestProperty("Cookie", cookie);
94         String csrf = getCSRF(uc, 0);
95
96         uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
97         uc.addRequestProperty("Cookie", cookie);
98         uc.setDoOutput(true);
99         OutputStream os = uc.getOutputStream();
100         os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
101                 + "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8")).getBytes("UTF-8"));
102         os.flush();
103         String res = IOUtils.readURL(uc);
104         assertThat(res, containsString(SupportUserDetailsPage.PATH + id));
105         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2));
106     }
107
108     @Test
109     public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
110         URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
111         uc.addRequestProperty("Cookie", cookie);
112         String csrf = getCSRF(uc, 0);
113
114         uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
115         uc.addRequestProperty("Cookie", cookie);
116         uc.setDoOutput(true);
117         OutputStream os = uc.getOutputStream();
118         os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
119                 + "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8")).getBytes("UTF-8"));
120         os.flush();
121         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
122     }
123
124     @Test
125     public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
126         URLConnection uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
127         uc.addRequestProperty("Cookie", cookie);
128         String csrf = getCSRF(uc, 0);
129
130         uc = new URL("https://" + getServerName() + FindUserPage.PATH).openConnection();
131         uc.addRequestProperty("Cookie", cookie);
132         uc.setDoOutput(true);
133         OutputStream os = uc.getOutputStream();
134         os.write(("csrf=" + URLEncoder.encode(csrf, "UTF-8") + "&" //
135                 + "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8")).getBytes("UTF-8"));
136         os.flush();
137         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
138     }
139 }