X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2Fpages%2FTestMain.java;h=4c0ae78625a0028dfa5eae2025f90dbd42056d09;hb=374e616d077431214c8128e3bf5ac3045a088aae;hp=194097fa8304038ce70192b9c3a55f3c6b11ec85;hpb=dc6dcaf2f0da0e54df3f8b69da40f93897c9f358;p=gigi.git diff --git a/tests/club/wpia/gigi/pages/TestMain.java b/tests/club/wpia/gigi/pages/TestMain.java index 194097fa..4c0ae786 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; @@ -80,7 +81,7 @@ public class TestMain extends ClientTest { authenticate((HttpURLConnection) uc); String content = IOUtils.readURL(uc); - assertThat(content, containsString("change to organisation administrator context")); + assertThat(content, containsString("Change to organisation administrator context")); assertThat(content, containsString("You are authenticated via certificate, so you will be able to perform all actions.")); } @@ -93,4 +94,87 @@ public class TestMain extends ClientTest { makeAgent(orgAdmin.getId()); o.addAdmin(orgAdmin, u, true); } + + @Test + public void testValidChallenges() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException { + insertRAContract(u.getId()); + // test RA Agent challenge + cookie = cookieWithCertificateLogin(u); + + testChallengeText("you need to pass the RA Agent Challenge", false); + + add100Points(u.getId()); + addChallengeInPast(u.getId(), CATSType.AGENT_CHALLENGE); + testChallengeText("you need to pass the RA Agent Challenge", true); + + addChallenge(u.getId(), CATSType.AGENT_CHALLENGE); + testChallengeText("you need to pass the RA Agent Challenge", false); + + // test Support challenge + testChallengeText("you need to pass the Support Challenge", false); + + grant(u, Group.SUPPORTER); + cookie = login(loginPrivateKey, loginCertificate.cert()); + testChallengeText("you need to pass the Support Challenge", true); + + addChallengeInPast(u.getId(), CATSType.SUPPORT_DP_CHALLENGE_NAME); + testChallengeText("you need to pass the Support Challenge", true); + + addChallenge(u.getId(), CATSType.SUPPORT_DP_CHALLENGE_NAME); + testChallengeText("you need to pass the Support Challenge", false); + + // test Org Agent challenge + testChallengeText("you need to pass the Organisation Agent Challenge", false); + + grant(u, Group.ORG_AGENT); + cookie = login(loginPrivateKey, loginCertificate.cert()); + testChallengeText("you need to pass the Organisation Agent Challenge", true); + + addChallengeInPast(u.getId(), CATSType.ORG_AGENT_CHALLENGE); + testChallengeText("you need to pass the Organisation Agent Challenge", true); + + addChallenge(u.getId(), CATSType.ORG_AGENT_CHALLENGE); + testChallengeText("you need to pass the Organisation Agent Challenge", false); + + // test TTP Agent challenge + testChallengeText("you need to pass the TTP RA Agent Challenge", false); + + grant(u, Group.TTP_AGENT); + cookie = login(loginPrivateKey, loginCertificate.cert()); + testChallengeText("you need to pass the TTP RA Agent Challenge", true); + + addChallengeInPast(u.getId(), CATSType.TTP_AGENT_CHALLENGE); + testChallengeText("you need to pass the TTP RA Agent Challenge", true); + + addChallenge(u.getId(), CATSType.TTP_AGENT_CHALLENGE); + testChallengeText("you need to pass the TTP RA Agent Challenge", false); + + // test Org Admin Challenge + Organisation o = new Organisation(createUniqueName(), Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "city", "test@example.com", "", "", u); + User admin = User.getById(createVerificationUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD)); + + loginCertificate = null; + cookie = cookieWithCertificateLogin(admin); + testChallengeText("you need to pass the Organisation Administrator Challenge", false); + + o.addAdmin(admin, u, true); + testChallengeText("you need to pass the Organisation Administrator Challenge", true); + + addChallengeInPast(admin.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME); + testChallengeText("you need to pass the Organisation Administrator Challenge", true); + + addChallenge(admin.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME); + testChallengeText("you need to pass the Organisation Administrator Challenge", false); + } + + private void testChallengeText(String contentText, boolean contains) throws IOException, MalformedURLException, GigiApiException { + URLConnection uc = new URL("https://" + getSecureServerName()).openConnection(); + authenticate((HttpURLConnection) uc); + String content = IOUtils.readURL(uc); + if (contains) { + assertThat(content, containsString(contentText)); + } else { + assertThat(content, not(containsString(contentText))); + } + } }