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.ManagedTest;
14 import org.junit.Test;
16 public class TestTTPAdmin extends ManagedTest {
24 public TestTTPAdmin() throws IOException {
25 String email = uniq + "@example.com";
26 us = User.getById(createVerifiedUser("fn", "ln", email, TEST_PASSWORD));
27 cookie = login(email, TEST_PASSWORD);
28 us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
32 public void testHasRight() throws IOException {
37 public void testHasNoRight() throws IOException {
41 public void testTTPAdmin(boolean hasRight) throws IOException {
43 grant(us.getEmail(), Group.getByString("ttp-assurer"));
45 grant(us.getEmail(), TTPAdminPage.TTP_APPLICANT);
46 cookie = login(us.getEmail(), TEST_PASSWORD);
48 assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH));
49 assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/"));
50 assertEquals( !hasRight ? 403 : 200, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + us.getId()));
51 assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + us2.getId()));
52 assertEquals( !hasRight ? 403 : 404, fetchStatusCode("https://" + getServerName() + TTPAdminPage.PATH + "/" + 100));
55 private int fetchStatusCode(String path) throws MalformedURLException, IOException {
56 URL u = new URL(path);
57 return ((HttpURLConnection) cookie(u.openConnection(), cookie)).getResponseCode();