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.dbObjects.Group;
9 import org.cacert.gigi.dbObjects.User;
10 import org.cacert.gigi.pages.admin.TTPAdminPage;
11 import org.cacert.gigi.testUtils.ClientTest;
12 import org.junit.Test;
14 public class TestTTPAdmin extends ClientTest {
18 public TestTTPAdmin() throws IOException {
19 us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
23 public void testHasRight() throws IOException {
28 public void testHasNoRight() throws IOException {
32 public void testTTPAdmin(boolean hasRight) throws IOException {
34 grant(email, Group.getByString("ttp-assurer"));
36 grant(u.getEmail(), TTPAdminPage.TTP_APPLICANT);
37 cookie = login(u.getEmail(), TEST_PASSWORD);
39 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
40 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
41 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
42 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
43 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
46 private int fetchStatusCode(String path) throws MalformedURLException, IOException {
47 return get(path).getResponseCode();