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;
24 public class TestSEAdminPageUserMailSearch extends ClientTest {
26 public TestSEAdminPageUserMailSearch() throws IOException, GigiApiException {
27 grant(u, Group.SUPPORTER);
28 cookie = login(email, TEST_PASSWORD);
29 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
33 public void testFulltextMailSearch() throws MalformedURLException, UnsupportedEncodingException, IOException {
34 String mail = createUniqueName() + "@example.com";
35 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
37 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
38 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
42 public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
43 String mail = createUniqueName() + "@example.tld";
44 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
46 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
47 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
51 public void testWildcardMailSearchMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException {
52 String mail = createUniqueName() + "@example.org";
53 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
54 String mail2 = createUniqueName() + "@example.org";
55 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
56 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
58 String res = IOUtils.readURL(uc);
59 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
60 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
64 public void testWildcardMailSearchSingleChar() 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() + "@fxample.org";
68 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
70 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
72 String res = IOUtils.readURL(uc);
73 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
74 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
78 public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
79 URLConnection uc = post(FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
80 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
84 public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
85 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
87 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
91 public void testSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
92 String mail = createUniqueName() + "@example1.org";
93 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
94 User testuser = User.getById(id);
95 String mail2 = createUniqueName() + "@example1.org";
96 createVerifiedEmail(testuser, mail2);
98 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail2, "UTF-8"), 0);
99 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
103 public void testWildcardMailSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
105 String mail = createUniqueName() + "@example2.org";
106 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
107 User testuser = User.getById(id);
108 String mail2 = createUniqueName() + "@example2.org";
109 createVerifiedEmail(testuser, mail2);
111 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example2.org", "UTF-8"), 0);
113 String res = IOUtils.readURL(uc);
114 assertThat(res, containsString(mail));
115 assertThat(res, containsString(mail2));
119 public void testWildcardMailSearchMultipleEmailAddressOneAccount() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
121 String mail = createUniqueName() + "@example3.org";
122 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
123 User testuser = User.getById(id);
124 String mail2 = createUniqueName() + "@test3.org";
125 createVerifiedEmail(testuser, mail2);
126 String mail3 = createUniqueName() + "@test3.org";
127 createVerifiedEmail(testuser, mail3);
129 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example3.org", "UTF-8"), 0);
130 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
132 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test3.org", "UTF-8"), 0);
134 String res = IOUtils.readURL(uc);
135 assertThat(res, not(containsString(mail)));
136 assertThat(res, containsString(mail2));
137 assertThat(res, containsString(mail3));
141 public void testWildcardMailSearchMultipleEmailAddressMultipleAccounts() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
142 String mail = createUniqueName() + "1@example4.org";
143 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
144 User testuser = User.getById(id);
145 String mail2 = createUniqueName() + "@test4.org";
146 createVerifiedEmail(testuser, mail2);
148 String mail3 = createUniqueName() + "2@example4.org";
149 int id2 = createVerifiedUser("Först", "Secönd", mail3, TEST_PASSWORD);
150 User testuser2 = User.getById(id2);
151 String mail4 = createUniqueName() + "@test4.org";
152 createVerifiedEmail(testuser2, mail4);
154 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example4.org", "UTF-8"), 0);
156 String res = IOUtils.readURL(uc);
157 assertThat(res, containsString(mail));
158 assertThat(res, not(containsString(mail2)));
159 assertThat(res, containsString(mail3));
160 assertThat(res, not(containsString(mail4)));
162 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test4.org", "UTF-8"), 0);
164 res = IOUtils.readURL(uc);
165 assertThat(res, not(containsString(mail)));
166 assertThat(res, containsString(mail2));
167 assertThat(res, not(containsString(mail3)));
168 assertThat(res, containsString(mail4));