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.User;
16 import club.wpia.gigi.pages.admin.support.FindUserByEmailPage;
17 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
18 import club.wpia.gigi.testUtils.IOUtils;
19 import club.wpia.gigi.testUtils.SEClientTest;
20 import club.wpia.gigi.util.ServerConstants;
21 import club.wpia.gigi.util.ServerConstants.Host;
23 public class TestSEAdminPageUserMailSearch extends SEClientTest {
25 public TestSEAdminPageUserMailSearch() throws IOException, GigiApiException {}
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);
32 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
33 assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
37 public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
38 String mail = createUniqueName() + "@example.tld";
39 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
41 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
42 assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
46 public void testWildcardMailSearchMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException {
47 String mail = createUniqueName() + "@example.org";
48 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
49 String mail2 = createUniqueName() + "@example.org";
50 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
51 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
53 String res = IOUtils.readURL(uc);
54 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
55 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
59 public void testWildcardMailSearchSingleChar() throws MalformedURLException, UnsupportedEncodingException, IOException {
60 String mail = createUniqueName() + "@example.org";
61 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
62 String mail2 = createUniqueName() + "@fxample.org";
63 int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
65 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
67 String res = IOUtils.readURL(uc);
68 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
69 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
73 public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
74 URLConnection uc = post(FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
75 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
79 public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
80 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
82 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
86 public void testSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
87 String mail = createUniqueName() + "@example1.org";
88 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
89 User testuser = User.getById(id);
90 String mail2 = createUniqueName() + "@example1.org";
91 createVerifiedEmail(testuser, mail2);
93 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail2, "UTF-8"), 0);
94 assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
98 public void testWildcardMailSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
100 String mail = createUniqueName() + "@example2.org";
101 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
102 User testuser = User.getById(id);
103 String mail2 = createUniqueName() + "@example2.org";
104 createVerifiedEmail(testuser, mail2);
106 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example2.org", "UTF-8"), 0);
108 String res = IOUtils.readURL(uc);
109 assertThat(res, containsString(mail));
110 assertThat(res, containsString(mail2));
114 public void testWildcardMailSearchMultipleEmailAddressOneAccount() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
116 String mail = createUniqueName() + "@example3.org";
117 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
118 User testuser = User.getById(id);
119 String mail2 = createUniqueName() + "@test3.org";
120 createVerifiedEmail(testuser, mail2);
121 String mail3 = createUniqueName() + "@test3.org";
122 createVerifiedEmail(testuser, mail3);
124 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example3.org", "UTF-8"), 0);
125 assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.SECURE) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
127 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test3.org", "UTF-8"), 0);
129 String res = IOUtils.readURL(uc);
130 assertThat(res, not(containsString(mail)));
131 assertThat(res, containsString(mail2));
132 assertThat(res, containsString(mail3));
136 public void testWildcardMailSearchMultipleEmailAddressMultipleAccounts() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
137 String mail = createUniqueName() + "1@example4.org";
138 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
139 User testuser = User.getById(id);
140 String mail2 = createUniqueName() + "@test4.org";
141 createVerifiedEmail(testuser, mail2);
143 String mail3 = createUniqueName() + "2@example4.org";
144 int id2 = createVerifiedUser("Först", "Secönd", mail3, TEST_PASSWORD);
145 User testuser2 = User.getById(id2);
146 String mail4 = createUniqueName() + "@test4.org";
147 createVerifiedEmail(testuser2, mail4);
149 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example4.org", "UTF-8"), 0);
151 String res = IOUtils.readURL(uc);
152 assertThat(res, containsString(mail));
153 assertThat(res, not(containsString(mail2)));
154 assertThat(res, containsString(mail3));
155 assertThat(res, not(containsString(mail4)));
157 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test4.org", "UTF-8"), 0);
159 res = IOUtils.readURL(uc);
160 assertThat(res, not(containsString(mail)));
161 assertThat(res, containsString(mail2));
162 assertThat(res, not(containsString(mail3)));
163 assertThat(res, containsString(mail4));