1 package org.cacert.gigi.pages.wot;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.HttpURLConnection;
7 import java.net.MalformedURLException;
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;
16 public class TestTTPAdmin extends ClientTest {
20 public TestTTPAdmin() throws IOException {
21 us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
25 public void testHasRight() throws IOException {
30 public void testHasNoRight() throws IOException {
34 public void testTTPAdmin(boolean hasRight) throws IOException {
36 grant(email, Group.getByString("ttp-assurer"));
38 grant(u.getEmail(), TTPAdminPage.TTP_APPLICANT);
39 cookie = login(u.getEmail(), TEST_PASSWORD);
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));
48 private int fetchStatusCode(String path) throws MalformedURLException, IOException {
49 URL u = new URL(path);
50 return ((HttpURLConnection) cookie(u.openConnection(), cookie)).getResponseCode();