]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/wot/TestTTPAdmin.java
UPD: clean up/document/beatufy testcases.
[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.HttpURLConnection;
7 import java.net.MalformedURLException;
8 import java.net.URL;
9
10 import org.cacert.gigi.dbObjects.Group;
11 import org.cacert.gigi.dbObjects.User;
12 import org.cacert.gigi.pages.admin.TTPAdminPage;
13 import org.cacert.gigi.testUtils.ClientTest;
14 import org.junit.Test;
15
16 public class TestTTPAdmin extends ClientTest {
17
18     User us2;
19
20     public TestTTPAdmin() throws IOException {
21         us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
22     }
23
24     @Test
25     public void testHasRight() throws IOException {
26         testTTPAdmin(true);
27     }
28
29     @Test
30     public void testHasNoRight() throws IOException {
31         testTTPAdmin(false);
32     }
33
34     public void testTTPAdmin(boolean hasRight) throws IOException {
35         if (hasRight) {
36             grant(email, Group.getByString("ttp-assurer"));
37         }
38         grant(u.getEmail(), TTPAdminPage.TTP_APPLICANT);
39         cookie = login(u.getEmail(), TEST_PASSWORD);
40
41         assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH));
42         assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/"));
43         assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + u.getId()));
44         assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + us2.getId()));
45         assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + 100));
46     }
47
48     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
49         URL u = new URL(path);
50         return ((HttpURLConnection) cookie(u.openConnection(), cookie)).getResponseCode();
51     }
52 }