1 package club.wpia.gigi.pages.wot;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.MalformedURLException;
7 import java.security.GeneralSecurityException;
11 import club.wpia.gigi.GigiApiException;
12 import club.wpia.gigi.dbObjects.CATS.CATSType;
13 import club.wpia.gigi.dbObjects.Group;
14 import club.wpia.gigi.dbObjects.User;
15 import club.wpia.gigi.pages.admin.TTPAdminPage;
16 import club.wpia.gigi.testUtils.ClientTest;
18 public class TestTTPAdmin extends ClientTest {
22 public TestTTPAdmin() throws IOException {
23 us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
27 public void testHasRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
32 public void testHasNoRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
36 public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
38 grant(u, Group.TTP_AGENT);
39 addChallenge(u.getId(), CATSType.TTP_AGENT_CHALLENGE);
41 grant(u, TTPAdminPage.TTP_APPLICANT);
42 cookie = cookieWithCertificateLogin(u);
44 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
45 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
46 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
47 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
48 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
51 private int fetchStatusCode(String path) throws MalformedURLException, IOException {
52 return get(path).getResponseCode();
56 public void testVerifyWithoutCertLogin() throws IOException {
57 cookie = login(u.getEmail(), TEST_PASSWORD);
58 loginCertificate = null;
59 assertEquals(403, get(cookie, TTPAdminPage.PATH).getResponseCode());
63 public void testAccessTTPPageWithoutValidChallenge() throws IOException, GigiApiException {
64 grant(u, Group.TTP_AGENT);
65 loginCertificate = null;
66 cookie = cookieWithCertificateLogin(u);
67 assertEquals(403, get(cookie, TTPAdminPage.PATH).getResponseCode());