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.FindDomainPage;
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 {
26 public TestSEAdminPageUserDomainSearch() throws IOException {
27 grant(email, Group.SUPPORTER);
28 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
32 public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
33 String mail = createUniqueName() + "@example.com";
34 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
35 User user = User.getById(id);
36 String domainName = createUniqueName() + ".org";
37 new Domain(user, user, domainName);
38 URLConnection uc = post(FindDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
40 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
44 public void testDomainSearchById() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
45 String mail = createUniqueName() + "@example.com";
46 int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
47 User user = User.getById(id);
48 String domainName = createUniqueName() + ".org";
49 Domain d = new Domain(user, user, domainName);
50 URLConnection uc = post(FindDomainPage.PATH, "process&domain=#" + d.getId());
51 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + id, uc.getHeaderField("Location"));
55 public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
56 URLConnection uc = post(FindDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8"));
57 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
61 public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
62 int id = (int) (Math.random() * 10000);
64 boolean found = false;
66 while (Domain.getById(id) != null && count < 20) {
68 id = (int) (Math.random() * 10000);
70 } catch (Exception e) {
74 URLConnection uc = post(FindDomainPage.PATH, "process&domain=#" + id);
75 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));