]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java
upd: rename file to match the function FindUserBy Email/Domain
[gigi.git] / tests / org / cacert / gigi / pages / admin / TestSEAdminPageUserDomainSearch.java
1 package org.cacert.gigi.pages.admin;
2
3 import static org.junit.Assert.*;
4 import static org.junit.Assume.*;
5
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;
11
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;
23
24 public class TestSEAdminPageUserDomainSearch extends ClientTest {
25
26     private Domain d;
27
28     private String domainName;
29
30     private String unique;
31
32     private int tid;
33
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());
37
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);
44     }
45
46     @Test
47     public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
48         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
49
50         assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid, uc.getHeaderField("Location"));
51     }
52
53     @Test
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"));
57     }
58
59     @Test
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)));
63     }
64
65     @Test
66     public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
67         int id = (int) (Math.random() * 10000);
68         int count = 0;
69         boolean found = false;
70         try {
71             while (Domain.getById(id) != null && count < 20) {
72                 count++;
73                 id = (int) (Math.random() * 10000);
74             }
75         } catch (Exception e) {
76             found = true;
77         }
78         assumeTrue(found);
79         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
80         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
81     }
82 }