X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2Fpages%2Forga%2FTestOrgSwitch.java;h=c19f387c38e28d7e7f6ac1c6b1993e80afa06267;hp=122ed18b99127f6f367b9eaf425ff38d5fe17e08;hb=ae1472c79b919cde36c2666ea243b005d33bfd68;hpb=5b7941ba6f39cabd29b3eb20db0fee688c3fffde diff --git a/tests/club/wpia/gigi/pages/orga/TestOrgSwitch.java b/tests/club/wpia/gigi/pages/orga/TestOrgSwitch.java index 122ed18b..c19f387c 100644 --- a/tests/club/wpia/gigi/pages/orga/TestOrgSwitch.java +++ b/tests/club/wpia/gigi/pages/orga/TestOrgSwitch.java @@ -5,13 +5,21 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.*; import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URLConnection; import java.net.URLEncoder; +import java.security.GeneralSecurityException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; import java.sql.SQLException; import org.junit.After; import org.junit.Test; import club.wpia.gigi.GigiApiException; +import club.wpia.gigi.dbObjects.CATS.CATSType; +import club.wpia.gigi.dbObjects.Certificate; import club.wpia.gigi.dbObjects.Organisation; import club.wpia.gigi.dbObjects.User; import club.wpia.gigi.testUtils.IOUtils; @@ -25,6 +33,10 @@ public class TestOrgSwitch extends OrgTest { private Organisation org2 = createUniqueOrg(); + private Certificate cagent; + + private PrivateKey pkagent; + public TestOrgSwitch() throws IOException, GigiApiException { assertEquals(403, get(SwitchOrganisation.PATH).getResponseCode()); @@ -33,9 +45,12 @@ public class TestOrgSwitch extends OrgTest { u2 = User.getById(createVerificationUser("testworker", "testname", email, TEST_PASSWORD)); assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org1.getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1)); assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org2.getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1)); + addChallenge(u2.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME); + cagent = loginCertificate; + pkagent = loginPrivateKey; // login with new user u2 - cookie = login(email, TEST_PASSWORD); + cookie = cookieWithCertificateLogin(u2); } @After @@ -118,4 +133,31 @@ public class TestOrgSwitch extends OrgTest { } + @Test + public void testSwitchOrgPasswordLogin() throws IOException, GigiApiException { + cookie = login(email, TEST_PASSWORD); + loginCertificate = null; + URLConnection uc = get(cookie, SwitchOrganisation.PATH); + assertEquals(403, ((HttpURLConnection) uc).getResponseCode()); + } + + @Test + public void testSwitchOrgLoginChallenge() throws IOException, GigiApiException, KeyManagementException, NoSuchAlgorithmException, GeneralSecurityException { + loginCertificate = cagent; + loginPrivateKey = pkagent; + cookie = login(pkagent, cagent.cert()); + String email = createUniqueName() + "@testdom.com"; + User u3 = User.getById(createVerificationUser("testworker", "testname", email, TEST_PASSWORD)); + assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org1.getId(), "email=" + URLEncoder.encode(u3.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1)); + assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org2.getId(), "email=" + URLEncoder.encode(u3.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1)); + + cookie = cookieWithCertificateLogin(u3); + URLConnection uc = get(cookie, SwitchOrganisation.PATH); + assertEquals(403, ((HttpURLConnection) uc).getResponseCode()); + + addChallenge(u3.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME); + clearCaches(); + uc = get(cookie, SwitchOrganisation.PATH); + assertEquals(200, ((HttpURLConnection) uc).getResponseCode()); + } }