]> WPIA git - gigi.git/commitdiff
add: ensure that for OrgAgent action there is a valid OrgAgent Challenge
authorINOPIAE <m.maengel@inopiae.de>
Wed, 17 Jul 2019 04:06:36 +0000 (06:06 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 8 Sep 2019 19:28:57 +0000 (21:28 +0200)
related to issue #150

Change-Id: I9e57e82da383c26ccbcb659a0f93d5de59816b15

src/club/wpia/gigi/pages/MainPage.java
src/club/wpia/gigi/pages/MainPage.templ
src/club/wpia/gigi/pages/orga/CreateOrgPage.java
src/club/wpia/gigi/pages/orga/ViewOrgPage.java
tests/club/wpia/gigi/pages/TestMain.java
tests/club/wpia/gigi/pages/orga/TestOrgManagement.java
tests/club/wpia/gigi/testUtils/OrgTest.java

index 9b7e079c25af0a8081c9e70f4cc1c9b562d8d998..e0170185982d4a1c3caf1492a09e5b4333dfa55f 100644 (file)
@@ -51,6 +51,11 @@ public class MainPage extends Page {
                 vars.put("catsinfo", true);
                 vars.put("catssupport", true);
             }
+            if (u.isInGroup(Group.ORG_AGENT) && !u.hasValidOrgAgentChallenge()) {
+                vars.put("catsinfo", true);
+                vars.put("catsorgagent", true);
+            }
+
             Certificate[] c = u.getCertificates(false);
             vars.put("c-no", c.length);
 
index 52b805b55c555deafe729740baa2e323d5d240cf..e8ecee42c3eacf5017c4e6436c016814cc357776 100644 (file)
@@ -20,6 +20,9 @@
   <? if($catssupport) { ?>
     <p><?=_To act as supporter you need to pass the Support Challenge.?></p>
   <? } ?>
+  <? if($catsorgagent) { ?>
+    <p><?=_To act as Organisation Agent you need to pass the Organisation Agent Challenge.?></p>
+  <? } ?>
   </div>
 <? } ?>
 <div class="card card-body bg-light">
index 27a0e4de9e8808e518824aec9a7595162406ad55..a27cf5ba4691bf27c06ed97fd811303e8a37da10 100644 (file)
@@ -21,7 +21,7 @@ public class CreateOrgPage extends ManagedFormPage {
 
     @Override
     public boolean isPermitted(AuthorizationContext ac) {
-        return ac != null && ac.isInGroup(ORG_AGENT) && ac.isStronglyAuthenticated();
+        return ac != null && ac.isInGroup(ORG_AGENT) && ac.isStronglyAuthenticated() && ac.getActor().hasValidOrgAgentChallenge();
     }
 
     @Override
index 0ee3d5ddf9b1e52e14e064491a9cabb952cc9e1a..03274215e6158e1bb81565542435a9c66f91a45c 100644 (file)
@@ -36,7 +36,7 @@ public class ViewOrgPage extends ManagedMultiFormPage {
 
     @Override
     public boolean isPermitted(AuthorizationContext ac) {
-        return ac != null && (ac.isInGroup(CreateOrgPage.ORG_AGENT) || ac.getActor().getOrganisations(true).size() != 0) && ac.isStronglyAuthenticated();
+        return ac != null && ((ac.isInGroup(CreateOrgPage.ORG_AGENT) && ac.getActor().hasValidOrgAgentChallenge()) || ac.getActor().getOrganisations(true).size() != 0) && ac.isStronglyAuthenticated();
     }
 
     @Override
index 47c4c151a7c4351fe96a58f85c482d49b93883e9..70a71a5dc50c6f7672ca699f24ea5aefd9095253 100644 (file)
@@ -142,5 +142,30 @@ public class TestMain extends ClientTest {
         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")));
     }
 }
index 6565d25fe04ed41a88933560823a661709d48d29..164facf6d179f9513726c3889341c760d8b45438 100644 (file)
@@ -17,6 +17,7 @@ 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.Country;
 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
@@ -286,4 +287,16 @@ public class TestOrgManagement extends OrgTest {
         uc = get(cookie, CreateOrgPage.DEFAULT_PATH);
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
     }
+
+    @Test
+    public void testAgentWithoutValidChallenge() throws IOException, GigiApiException {
+        User agent = User.getById(createVerificationUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD));
+        addChallenge(agent.getId(), CATSType.ORG_AGENT_CHALLENGE);
+        loginCertificate = null;
+        cookie = cookieWithCertificateLogin(agent);
+        URLConnection uc = get(cookie, ViewOrgPage.DEFAULT_PATH);
+        assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
+        uc = get(cookie, CreateOrgPage.DEFAULT_PATH);
+        assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
+    }
 }
index 6c3ba7c4621651952aa12dcdc04b737481a6ef66..9f33686cee89dd64295d56ca7b0947e111e24a17 100644 (file)
@@ -3,6 +3,7 @@ package club.wpia.gigi.testUtils;
 import java.io.IOException;
 
 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;
@@ -14,6 +15,7 @@ public class OrgTest extends ClientTest {
     public OrgTest() throws IOException, GigiApiException {
         makeAgent(u.getId());
         u.grantGroup(getSupporter(), Group.ORG_AGENT);
+        addChallenge(u.getId(), CATSType.ORG_AGENT_CHALLENGE);
         clearCaches();
         cookie = cookieWithCertificateLogin(u);
     }