]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
c4bf8b43e1f256f67725847083931410b794a0f5
[gigi.git] / tests / club / wpia / gigi / pages / admin / TestSEAdminPageUserMailSearch.java
1 package club.wpia.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.junit.Test;
13
14 import club.wpia.gigi.GigiApiException;
15 import club.wpia.gigi.dbObjects.Group;
16 import club.wpia.gigi.dbObjects.User;
17 import club.wpia.gigi.pages.admin.support.FindUserByEmailPage;
18 import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage;
19 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
20 import club.wpia.gigi.testUtils.ClientTest;
21 import club.wpia.gigi.testUtils.IOUtils;
22 import club.wpia.gigi.util.ServerConstants;
23 import club.wpia.gigi.util.ServerConstants.Host;
24
25 public class TestSEAdminPageUserMailSearch extends ClientTest {
26
27     public TestSEAdminPageUserMailSearch() throws IOException, GigiApiException {
28         grant(u, Group.SUPPORTER);
29         cookie = login(email, TEST_PASSWORD);
30         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
31     }
32
33     @Test
34     public void testFulltextMailSearch() throws MalformedURLException, UnsupportedEncodingException, IOException {
35         String mail = createUniqueName() + "@example.com";
36         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
37
38         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
39         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
40     }
41
42     @Test
43     public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
44         String mail = createUniqueName() + "@example.tld";
45         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
46
47         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
48         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
49     }
50
51     @Test
52     public void testWildcardMailSearchMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException {
53         String mail = createUniqueName() + "@example.org";
54         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
55         String mail2 = createUniqueName() + "@example.org";
56         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
57         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
58
59         String res = IOUtils.readURL(uc);
60         assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
61         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
62     }
63
64     @Test
65     public void testWildcardMailSearchSingleChar() 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() + "@fxample.org";
69         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
70
71         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
72
73         String res = IOUtils.readURL(uc);
74         assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
75         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
76     }
77
78     @Test
79     public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
80         URLConnection uc = post(FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
81         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
82     }
83
84     @Test
85     public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
86         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
87
88         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
89     }
90
91     @Test
92     public void testSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
93         String mail = createUniqueName() + "@example1.org";
94         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
95         User testuser = User.getById(id);
96         String mail2 = createUniqueName() + "@example1.org";
97         createVerifiedEmail(testuser, mail2);
98
99         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail2, "UTF-8"), 0);
100         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
101     }
102
103     @Test
104     public void testWildcardMailSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
105         clearCaches();
106         String mail = createUniqueName() + "@example2.org";
107         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
108         User testuser = User.getById(id);
109         String mail2 = createUniqueName() + "@example2.org";
110         createVerifiedEmail(testuser, mail2);
111
112         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example2.org", "UTF-8"), 0);
113
114         String res = IOUtils.readURL(uc);
115         assertThat(res, containsString(mail));
116         assertThat(res, containsString(mail2));
117     }
118
119     @Test
120     public void testWildcardMailSearchMultipleEmailAddressOneAccount() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
121         clearCaches();
122         String mail = createUniqueName() + "@example3.org";
123         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
124         User testuser = User.getById(id);
125         String mail2 = createUniqueName() + "@test3.org";
126         createVerifiedEmail(testuser, mail2);
127         String mail3 = createUniqueName() + "@test3.org";
128         createVerifiedEmail(testuser, mail3);
129
130         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example3.org", "UTF-8"), 0);
131         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
132
133         uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test3.org", "UTF-8"), 0);
134
135         String res = IOUtils.readURL(uc);
136         assertThat(res, not(containsString(mail)));
137         assertThat(res, containsString(mail2));
138         assertThat(res, containsString(mail3));
139     }
140
141     @Test
142     public void testWildcardMailSearchMultipleEmailAddressMultipleAccounts() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
143         String mail = createUniqueName() + "1@example4.org";
144         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
145         User testuser = User.getById(id);
146         String mail2 = createUniqueName() + "@test4.org";
147         createVerifiedEmail(testuser, mail2);
148
149         String mail3 = createUniqueName() + "2@example4.org";
150         int id2 = createVerifiedUser("Först", "Secönd", mail3, TEST_PASSWORD);
151         User testuser2 = User.getById(id2);
152         String mail4 = createUniqueName() + "@test4.org";
153         createVerifiedEmail(testuser2, mail4);
154
155         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example4.org", "UTF-8"), 0);
156
157         String res = IOUtils.readURL(uc);
158         assertThat(res, containsString(mail));
159         assertThat(res, not(containsString(mail2)));
160         assertThat(res, containsString(mail3));
161         assertThat(res, not(containsString(mail4)));
162
163         uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test4.org", "UTF-8"), 0);
164
165         res = IOUtils.readURL(uc);
166         assertThat(res, not(containsString(mail)));
167         assertThat(res, containsString(mail2));
168         assertThat(res, not(containsString(mail3)));
169         assertThat(res, containsString(mail4));
170     }
171 }