]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/wot/TestTTPAdmin.java
add: ensure that for TTPAgent action there is a valid TTPAgent Challenge
[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.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;
17
18 public class TestTTPAdmin extends ClientTest {
19
20     User us2;
21
22     public TestTTPAdmin() throws IOException {
23         us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
24     }
25
26     @Test
27     public void testHasRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
28         testTTPAdmin(true);
29     }
30
31     @Test
32     public void testHasNoRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
33         testTTPAdmin(false);
34     }
35
36     public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
37         if (hasRight) {
38             grant(u, Group.TTP_AGENT);
39             addChallenge(u.getId(), CATSType.TTP_AGENT_CHALLENGE);
40         }
41         grant(u, TTPAdminPage.TTP_APPLICANT);
42         cookie = cookieWithCertificateLogin(u);
43
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));
49     }
50
51     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
52         return get(path).getResponseCode();
53     }
54
55     @Test
56     public void testVerifyWithoutCertLogin() throws IOException {
57         cookie = login(u.getEmail(), TEST_PASSWORD);
58         loginCertificate = null;
59         assertEquals(403, get(cookie, TTPAdminPage.PATH).getResponseCode());
60     }
61
62     @Test
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());
68     }
69 }