1 package org.cacert.gigi.pages.admin;
3 import static org.junit.Assert.*;
4 import static org.junit.Assume.*;
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.Domain;
14 import org.cacert.gigi.dbObjects.Group;
15 import org.cacert.gigi.dbObjects.User;
16 import org.cacert.gigi.pages.admin.support.FindUserByDomainPage;
17 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
18 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
19 import org.cacert.gigi.testUtils.ClientTest;
20 import org.cacert.gigi.testUtils.IOUtils;
21 import org.cacert.gigi.util.ServerConstants;
22 import org.junit.Test;
24 public class TestSEAdminPageUserDomainSearch extends ClientTest {
28 private String domainName;
30 private String unique;
34 public TestSEAdminPageUserDomainSearch() throws IOException, GigiApiException {
35 grant(email, Group.SUPPORTER);
36 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
38 String mail = createUniqueName() + "@example.com";
39 tid = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
40 User user = User.getById(tid);
41 unique = createUniqueName();
42 domainName = unique + "pattern.org";
43 this.d = new Domain(user, user, domainName);
47 public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
48 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
50 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
54 public void testDomainSearchById() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
55 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId());
56 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
60 public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
61 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8"));
62 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
66 public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
67 int id = (int) (Math.random() * 10000);
69 boolean found = false;
71 while (Domain.getById(id) != null && count < 20) {
73 id = (int) (Math.random() * 10000);
75 } catch (Exception e) {
79 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
80 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));