1 package org.cacert.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.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;
23 public class TestSEAdminPageUserMailSearch extends ClientTest {
25 public TestSEAdminPageUserMailSearch() throws IOException {
26 grant(email, Group.SUPPORTER);
27 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
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);
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"));
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);
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"));
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);
56 String res = IOUtils.readURL(uc);
57 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
58 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
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);
68 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
70 String res = IOUtils.readURL(uc);
71 assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
72 assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
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)));
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);
85 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
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);
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"));
101 public void testWildcardMailSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
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);
109 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example2.org", "UTF-8"), 0);
111 String res = IOUtils.readURL(uc);
112 assertThat(res, containsString(mail));
113 assertThat(res, containsString(mail2));
117 public void testWildcardMailSearchMultipleEmailAddressOneAccount() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
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);
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"));
130 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test3.org", "UTF-8"), 0);
132 String res = IOUtils.readURL(uc);
133 assertThat(res, not(containsString(mail)));
134 assertThat(res, containsString(mail2));
135 assertThat(res, containsString(mail3));
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);
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);
152 URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example4.org", "UTF-8"), 0);
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)));
160 uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test4.org", "UTF-8"), 0);
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));