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