]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / tests / org / cacert / gigi / pages / wot / TestTTPAdmin.java
1 package org.cacert.gigi.pages.wot;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.net.MalformedURLException;
7
8 import org.cacert.gigi.GigiApiException;
9 import org.cacert.gigi.dbObjects.Group;
10 import org.cacert.gigi.dbObjects.User;
11 import org.cacert.gigi.pages.admin.TTPAdminPage;
12 import org.cacert.gigi.testUtils.ClientTest;
13 import org.junit.Test;
14
15 public class TestTTPAdmin extends ClientTest {
16
17     User us2;
18
19     public TestTTPAdmin() throws IOException {
20         us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
21     }
22
23     @Test
24     public void testHasRight() throws IOException, GigiApiException {
25         testTTPAdmin(true);
26     }
27
28     @Test
29     public void testHasNoRight() throws IOException, GigiApiException {
30         testTTPAdmin(false);
31     }
32
33     public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException {
34         if (hasRight) {
35             grant(u, Group.TTP_ASSURER);
36         }
37         grant(u, TTPAdminPage.TTP_APPLICANT);
38         cookie = login(u.getEmail(), TEST_PASSWORD);
39
40         assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
41         assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
42         assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
43         assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
44         assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
45     }
46
47     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
48         return get(path).getResponseCode();
49     }
50 }