]> WPIA git - gigi.git/blobdiff - 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
index d518dea4e3c177986222730576e1e357c2872b57..ec423d681c3f76321f347b6a4467f4cc2be71dab 100644 (file)
@@ -4,10 +4,12 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.security.GeneralSecurityException;
 
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.CATS.CATSType;
 import club.wpia.gigi.dbObjects.Group;
 import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.pages.admin.TTPAdminPage;
@@ -22,21 +24,22 @@ public class TestTTPAdmin extends ClientTest {
     }
 
     @Test
-    public void testHasRight() throws IOException, GigiApiException {
+    public void testHasRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
         testTTPAdmin(true);
     }
 
     @Test
-    public void testHasNoRight() throws IOException, GigiApiException {
+    public void testHasNoRight() throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
         testTTPAdmin(false);
     }
 
-    public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException {
+    public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException, GeneralSecurityException, InterruptedException {
         if (hasRight) {
             grant(u, Group.TTP_AGENT);
+            addChallenge(u.getId(), CATSType.TTP_AGENT_CHALLENGE);
         }
         grant(u, TTPAdminPage.TTP_APPLICANT);
-        cookie = login(u.getEmail(), TEST_PASSWORD);
+        cookie = cookieWithCertificateLogin(u);
 
         assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
         assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
@@ -48,4 +51,19 @@ public class TestTTPAdmin extends ClientTest {
     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
         return get(path).getResponseCode();
     }
+
+    @Test
+    public void testVerifyWithoutCertLogin() throws IOException {
+        cookie = login(u.getEmail(), TEST_PASSWORD);
+        loginCertificate = null;
+        assertEquals(403, get(cookie, TTPAdminPage.PATH).getResponseCode());
+    }
+
+    @Test
+    public void testAccessTTPPageWithoutValidChallenge() throws IOException, GigiApiException {
+        grant(u, Group.TTP_AGENT);
+        loginCertificate = null;
+        cookie = cookieWithCertificateLogin(u);
+        assertEquals(403, get(cookie, TTPAdminPage.PATH).getResponseCode());
+    }
 }