]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
71dfeaee5071f1f52ad3ac95f172f699eab5a849
[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.GigiApiException;
13 import org.cacert.gigi.dbObjects.Group;
14 import org.cacert.gigi.dbObjects.User;
15 import org.cacert.gigi.pages.admin.support.FindUserByEmailPage;
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, FindUserByEmailPage.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, FindUserByEmailPage.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, FindUserByEmailPage.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, FindUserByEmailPage.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 = post(FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
78         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
79     }
80
81     @Test
82     public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
83         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
84
85         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
86     }
87
88     @Test
89     public void testSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
90         String mail = createUniqueName() + "@example1.org";
91         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
92         User testuser = User.getById(id);
93         String mail2 = createUniqueName() + "@example1.org";
94         createVerifiedEmail(testuser, mail2);
95
96         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail2, "UTF-8"), 0);
97         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
98     }
99
100     @Test
101     public void testWildcardMailSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
102         clearCaches();
103         String mail = createUniqueName() + "@example2.org";
104         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
105         User testuser = User.getById(id);
106         String mail2 = createUniqueName() + "@example2.org";
107         createVerifiedEmail(testuser, mail2);
108
109         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example2.org", "UTF-8"), 0);
110
111         String res = IOUtils.readURL(uc);
112         assertThat(res, containsString(mail));
113         assertThat(res, containsString(mail2));
114     }
115
116     @Test
117     public void testWildcardMailSearchMultipleEmailAddressOneAccount() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
118         clearCaches();
119         String mail = createUniqueName() + "@example3.org";
120         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
121         User testuser = User.getById(id);
122         String mail2 = createUniqueName() + "@test3.org";
123         createVerifiedEmail(testuser, mail2);
124         String mail3 = createUniqueName() + "@test3.org";
125         createVerifiedEmail(testuser, mail3);
126
127         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example3.org", "UTF-8"), 0);
128         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
129
130         uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test3.org", "UTF-8"), 0);
131
132         String res = IOUtils.readURL(uc);
133         assertThat(res, not(containsString(mail)));
134         assertThat(res, containsString(mail2));
135         assertThat(res, containsString(mail3));
136     }
137
138     @Test
139     public void testWildcardMailSearchMultipleEmailAddressMultipleAccounts() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
140         String mail = createUniqueName() + "1@example4.org";
141         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
142         User testuser = User.getById(id);
143         String mail2 = createUniqueName() + "@test4.org";
144         createVerifiedEmail(testuser, mail2);
145
146         String mail3 = createUniqueName() + "2@example4.org";
147         int id2 = createVerifiedUser("Först", "Secönd", mail3, TEST_PASSWORD);
148         User testuser2 = User.getById(id2);
149         String mail4 = createUniqueName() + "@test4.org";
150         createVerifiedEmail(testuser2, mail4);
151
152         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example4.org", "UTF-8"), 0);
153
154         String res = IOUtils.readURL(uc);
155         assertThat(res, containsString(mail));
156         assertThat(res, not(containsString(mail2)));
157         assertThat(res, containsString(mail3));
158         assertThat(res, not(containsString(mail4)));
159
160         uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test4.org", "UTF-8"), 0);
161
162         res = IOUtils.readURL(uc);
163         assertThat(res, not(containsString(mail)));
164         assertThat(res, containsString(mail2));
165         assertThat(res, not(containsString(mail3)));
166         assertThat(res, containsString(mail4));
167     }
168 }