1 package club.wpia.gigi.pages.admin;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
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;
12 import org.junit.Test;
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;
25 public class TestSEAdminPageUserMailSearch extends ClientTest {
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());
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);
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"));
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);
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"));
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);
59 String res = IOUtils.readURL(uc);
60 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
61 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
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);
71 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
73 String res = IOUtils.readURL(uc);
74 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
75 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
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)));
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);
88 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
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);
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"));
104 public void testWildcardMailSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
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);
112 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example2.org", "UTF-8"), 0);
114 String res = IOUtils.readURL(uc);
115 assertThat(res, containsString(mail));
116 assertThat(res, containsString(mail2));
120 public void testWildcardMailSearchMultipleEmailAddressOneAccount() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
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);
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"));
133 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test3.org", "UTF-8"), 0);
135 String res = IOUtils.readURL(uc);
136 assertThat(res, not(containsString(mail)));
137 assertThat(res, containsString(mail2));
138 assertThat(res, containsString(mail3));
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);
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);
155 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example4.org", "UTF-8"), 0);
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)));
163 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test4.org", "UTF-8"), 0);
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));