]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/TestDomain.java
ADD: prefix check for domains against database
[gigi.git] / tests / org / cacert / gigi / TestDomain.java
1 package org.cacert.gigi;
2
3 import static org.junit.Assert.*;
4
5 import org.cacert.gigi.dbObjects.Domain;
6 import org.cacert.gigi.dbObjects.User;
7 import org.cacert.gigi.testUtils.ManagedTest;
8 import org.junit.Test;
9
10 public class TestDomain extends ManagedTest {
11
12     private User us;
13
14     public TestDomain() {
15         int uid = createVerifiedUser("fn", "ln", createUniqueName() + "pr@test-email.de", TEST_PASSWORD);
16         us = User.getById(uid);
17     }
18
19     @Test
20     public void testDomain() throws InterruptedException, GigiApiException {
21         assertEquals(0, us.getDomains().length);
22         Domain d = new Domain(us, "v1.example.org");
23         assertEquals(0, d.getId());
24         d.insert();
25         Domain[] domains = us.getDomains();
26         assertEquals(1, domains.length);
27         assertEquals("v1.example.org", domains[0].getSuffix());
28         assertEquals(domains[0].getOwner().getId(), us.getId());
29         assertNotEquals(0, domains[0].getId());
30         assertNotEquals(0, d.getId());
31         assertEquals(d.getId(), domains[0].getId());
32
33         Domain d2 = new Domain(us, "v2.example.org");
34         assertEquals(0, d2.getId());
35         d2.insert();
36
37         domains = us.getDomains();
38         assertEquals(2, domains.length);
39         if ( !domains[1].getSuffix().equals("v2.example.org")) {
40             Domain d1 = domains[0];
41             domains[0] = domains[1];
42             domains[1] = d1;
43         }
44         assertEquals("v2.example.org", domains[1].getSuffix());
45         assertEquals(domains[0].getOwner().getId(), us.getId());
46         assertEquals(domains[1].getOwner().getId(), us.getId());
47         assertNotEquals(0, domains[0].getId());
48         assertNotEquals(0, d.getId());
49         assertEquals(d.getId(), domains[0].getId());
50
51     }
52
53     @Test
54     public void testDoubleDomain() throws InterruptedException, GigiApiException {
55         Domain d = new Domain(us, "dub.example.org");
56         d.insert();
57         try {
58             Domain d2 = new Domain(us, "dub.example.org");
59             d2.insert();
60             fail("expected exception");
61         } catch (GigiApiException e) {
62             // expected
63         }
64     }
65
66     @Test
67     public void testDoubleDomainDelete() throws InterruptedException, GigiApiException {
68         Domain d = new Domain(us, "del.example.org");
69         d.insert();
70         d.delete();
71         Domain d2 = new Domain(us, "del.example.org");
72         d2.insert();
73     }
74
75     @Test
76     public void testPrefixCheck() throws InterruptedException, GigiApiException {
77         String uni = createUniqueName() + "un.tld";
78         Domain d0 = new Domain(us, uni);
79         d0.insert();
80         d0.delete();
81         Domain d = new Domain(us, "pref." + uni);
82         d.insert();
83
84         Domain d2 = new Domain(us, uni);
85         try {
86             d2.insert();
87             fail("Prefix match failed");
88         } catch (GigiApiException e) {
89         }
90         d2 = new Domain(us, "a.pref." + uni);
91         try {
92             d2.insert();
93             fail("Prefix match failed");
94         } catch (GigiApiException e) {
95         }
96         d2 = new Domain(us, "pref." + uni);
97         try {
98             d2.insert();
99             fail("exact match failed");
100         } catch (GigiApiException e) {
101         }
102
103     }
104
105     @Test
106     public void testDoubleDomainPrefix() throws InterruptedException, GigiApiException {
107         Domain d = new Domain(us, "pref.aexample.org");
108         d.insert();
109         Domain d2 = new Domain(us, "a.pref.aexample.org");
110         try {
111             d2.insert();
112             fail("expected exception");
113         } catch (GigiApiException e) {
114             // expected
115         }
116         Domain d3 = new Domain(us, "aexample.org");
117         try {
118             d3.insert();
119             fail("expected exception");
120         } catch (GigiApiException e) {
121             // expected
122         }
123     }
124
125     @Test
126     public void testDoubleInsertDomain() throws InterruptedException, GigiApiException {
127         Domain d = new Domain(us, "dins.example.org");
128         d.insert();
129         try {
130             d.insert();
131             fail("expected exception");
132         } catch (GigiApiException e) {
133             // expected
134         }
135     }
136
137 }