]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/wot/TestTTPAdmin.java
0e11f6df501c479c8b0d6fea2da5780c315e7368
[gigi.git] / tests / club / wpia / gigi / pages / wot / TestTTPAdmin.java
1 package club.wpia.gigi.pages.wot;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.net.MalformedURLException;
7 import java.security.GeneralSecurityException;
8
9 import org.junit.Test;
10
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;
16
17 public class TestTTPAdmin extends ClientTest {
18
19     User us2;
20
21     public TestTTPAdmin() throws IOException {
22         us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
23     }
24
25     @Test
26     public void testHasRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
27         testTTPAdmin(true);
28     }
29
30     @Test
31     public void testHasNoRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
32         testTTPAdmin(false);
33     }
34
35     public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
36         if (hasRight) {
37             grant(u, Group.TTP_AGENT);
38         }
39         grant(u, TTPAdminPage.TTP_APPLICANT);
40         cookie = cookieWithCertificateLogin(u);
41
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));
47     }
48
49     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
50         return get(path).getResponseCode();
51     }
52
53     @Test
54     public void testVerifyWithoutCertLogin() throws IOException {
55         cookie = login(u.getEmail(), TEST_PASSWORD);
56         loginCertificate = null;
57         assertEquals(403, get(cookie, TTPAdminPage.PATH).getResponseCode());
58     }
59 }