]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/pages/TestMain.java
add: ensure that for RA Agent actions there is a valid RA Challenge
[gigi.git] / tests / club / wpia / gigi / pages / TestMain.java
index 194097fa8304038ce70192b9c3a55f3c6b11ec85..e6dce4569348d0d6a795aecaa742911a449c80fb 100644 (file)
@@ -13,6 +13,7 @@ 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.Country;
 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
 import club.wpia.gigi.dbObjects.Group;
@@ -93,4 +94,28 @@ public class TestMain extends ClientTest {
         makeAgent(orgAdmin.getId());
         o.addAdmin(orgAdmin, u, true);
     }
+
+    @Test
+    public void testValidChallenges() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException {
+        cookie = cookieWithCertificateLogin(u);
+
+        // test RA Agent challenge
+        URLConnection uc = new URL("https://" + getSecureServerName()).openConnection();
+        authenticate((HttpURLConnection) uc);
+        String content = IOUtils.readURL(uc);
+        assertThat(content, not(containsString("you need to pass the RA Agent Challenge")));
+
+        add100Points(u.getId());
+        addChallengeInPast(u.getId(), CATSType.AGENT_CHALLENGE);
+        uc = new URL("https://" + getSecureServerName()).openConnection();
+        authenticate((HttpURLConnection) uc);
+        content = IOUtils.readURL(uc);
+        assertThat(content, containsString("you need to pass the RA Agent Challenge"));
+
+        addChallenge(u.getId(), CATSType.AGENT_CHALLENGE);
+        uc = new URL("https://" + getSecureServerName()).openConnection();
+        authenticate((HttpURLConnection) uc);
+        content = IOUtils.readURL(uc);
+        assertThat(content, not(containsString("you need to pass the RA Agent Challenge")));
+    }
 }