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.Group;
13 import club.wpia.gigi.dbObjects.User;
14 import club.wpia.gigi.pages.admin.TTPAdminPage;
15 import club.wpia.gigi.testUtils.ClientTest;
17 public class TestTTPAdmin extends ClientTest {
21 public TestTTPAdmin() throws IOException {
22 us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
26 public void testHasRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
31 public void testHasNoRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
35 public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
37 grant(u, Group.TTP_AGENT);
39 grant(u, TTPAdminPage.TTP_APPLICANT);
40 cookie = cookieWithCertificateLogin(u);
42 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
43 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
44 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
45 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
46 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
49 private int fetchStatusCode(String path) throws MalformedURLException, IOException {
50 return get(path).getResponseCode();
54 public void testVerifyWithoutCertLogin() throws IOException {
55 cookie = login(u.getEmail(), TEST_PASSWORD);
56 loginCertificate = null;
57 assertEquals(403, get(cookie, TTPAdminPage.PATH).getResponseCode());