1 package org.cacert.gigi.pages.wot;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.MalformedURLException;
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;
15 public class TestTTPAdmin extends ClientTest {
19 public TestTTPAdmin() throws IOException {
20 us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
24 public void testHasRight() throws IOException, GigiApiException {
29 public void testHasNoRight() throws IOException, GigiApiException {
33 public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException {
35 grant(u, Group.TTP_ASSURER);
37 grant(u, TTPAdminPage.TTP_APPLICANT);
38 cookie = login(u.getEmail(), TEST_PASSWORD);
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));
47 private int fetchStatusCode(String path) throws MalformedURLException, IOException {
48 return get(path).getResponseCode();