X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2Fpages%2FTestMain.java;h=70a71a5dc50c6f7672ca699f24ea5aefd9095253;hp=194097fa8304038ce70192b9c3a55f3c6b11ec85;hb=7ea933e2e4cac62194d860cf213c1fd106ce76c5;hpb=f1328bd450dd974c5c7327f503ee0dd7f1620b8a diff --git a/tests/club/wpia/gigi/pages/TestMain.java b/tests/club/wpia/gigi/pages/TestMain.java index 194097fa..70a71a5d 100644 --- a/tests/club/wpia/gigi/pages/TestMain.java +++ b/tests/club/wpia/gigi/pages/TestMain.java @@ -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,78 @@ 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"))); + + // test Support challenge + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, not(containsString("you need to pass the Support Challenge"))); + + grant(u, Group.SUPPORTER); + cookie = login(loginPrivateKey, loginCertificate.cert()); + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, containsString("you need to pass the Support Challenge")); + + addChallengeInPast(u.getId(), CATSType.SUPPORT_DP_CHALLENGE_NAME); + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, containsString("you need to pass the Support Challenge")); + + addChallenge(u.getId(), CATSType.SUPPORT_DP_CHALLENGE_NAME); + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, not(containsString("you need to pass the Support Challenge"))); + + // test Org Agent challenge + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, not(containsString("you need to pass the Organisation Agent Challenge"))); + + grant(u, Group.ORG_AGENT); + cookie = login(loginPrivateKey, loginCertificate.cert()); + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, containsString("you need to pass the Organisation Agent Challenge")); + + addChallengeInPast(u.getId(), CATSType.ORG_AGENT_CHALLENGE); + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, containsString("you need to pass the Organisation Agent Challenge")); + + addChallenge(u.getId(), CATSType.ORG_AGENT_CHALLENGE); + uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + content = IOUtils.readURL(uc); + assertThat(content, not(containsString("you need to pass the Organisation Agent Challenge"))); + } }