]> WPIA git - gigi.git/commitdiff
add: ensure that for RA Agent actions there is a valid RA Challenge
authorINOPIAE <m.maengel@inopiae.de>
Tue, 16 Jul 2019 12:42:33 +0000 (14:42 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 8 Sep 2019 19:26:06 +0000 (21:26 +0200)
related to issue #150

Change-Id: I2438e8941864103fe1b2d7c542736c19acb01419

src/club/wpia/gigi/pages/MainPage.java
src/club/wpia/gigi/pages/MainPage.templ
src/club/wpia/gigi/util/AuthorizationContext.java
tests/club/wpia/gigi/pages/TestMain.java
tests/club/wpia/gigi/pages/wot/TestVerification.java
tests/club/wpia/gigi/testUtils/ConfiguredTest.java

index 7fb5228e0df1a425c9bfa4083b2305a7672586e5..a486618fedf39cba887c4d212c26f72c177557dd 100644 (file)
@@ -41,6 +41,12 @@ public class MainPage extends Page {
             vars.put("vp", u.getVerificationPoints());
             vars.put("xp", u.getExperiencePoints());
 
+
+            vars.put("catsinfo", false);
+            if (u.canVerify() && !u.hasValidRAChallenge()) {
+                vars.put("catsinfo", true);
+                vars.put("catsra", true);
+            }
             Certificate[] c = u.getCertificates(false);
             vars.put("c-no", c.length);
 
index 2b14f704cf011d2f73e48a48e82eaf379587fd38..8f9f87313c553aea6b7317b7b15e5a7f3b1d76fc 100644 (file)
     </div>
   <? } ?>
 <? } ?>
-
+<? if($catsinfo) { ?>
+  <div class="alert alert-warning" role="alert">
+  <? if($catsra) { ?>
+    <p><?=_To add a verification you need to pass the RA Agent Challenge.?></p>
+  <? } ?>
+  </div>
+<? } ?>
 <div class="card card-body bg-light">
 <? if($ra-agent) { ?><p><?=_You are an RA Agent.?></p><? } ?>
 <p><?=_Assigned support permissions?>: <?=$support-groups?></p>
index 566436ac5e2834989f5074a07781704a7298b5d9..66c65450bb3fac8180a9025f2af99b465482d3a8 100644 (file)
@@ -113,7 +113,7 @@ public class AuthorizationContext implements Outputable, Serializable {
     }
 
     public boolean canVerify() {
-        return target instanceof User && ((User) target).canVerify() && isStronglyAuthenticated();
+        return target instanceof User && ((User) target).canVerify() && isStronglyAuthenticated() && ((User) target).hasValidRAChallenge();
     }
 
     public boolean isStronglyAuthenticated() {
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")));
+    }
 }
index a25a2bc43b4887cd9667821e52d2ff61bc2920c2..9ad541a383bc18effb800060dfde0f242891b5aa 100644 (file)
@@ -23,6 +23,7 @@ import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.database.GigiPreparedStatement;
+import club.wpia.gigi.dbObjects.CATS.CATSType;
 import club.wpia.gigi.dbObjects.Country;
 import club.wpia.gigi.dbObjects.Group;
 import club.wpia.gigi.dbObjects.User;
@@ -41,6 +42,8 @@ public class TestVerification extends ManagedTest {
 
     private int applicantName;
 
+    private int applicantId;
+
     private String cookie;
 
     @Before
@@ -50,7 +53,7 @@ public class TestVerification extends ManagedTest {
         applicantM = createUniqueName() + "@example.org";
 
         createVerificationUser("a", "b", agentM, TEST_PASSWORD);
-        int applicantId = createVerifiedUser("a", "c", applicantM, TEST_PASSWORD);
+        applicantId = createVerifiedUser("a", "c", applicantM, TEST_PASSWORD);
         applicantName = User.getById(applicantId).getPreferredName().getId();
 
         User users[] = User.findByEmail(agentM);
@@ -391,4 +394,14 @@ public class TestVerification extends ManagedTest {
         loginCertificate = null;
         assertEquals(403, get(cookie, VerifyPage.PATH).getResponseCode());
     }
+
+    @Test
+    public void testVerifyWithoutValidChallenge() throws IOException, GigiApiException {
+        cookie = cookieWithCertificateLogin(User.getById(applicantId));
+        add100Points(applicantId);
+        addChallengeInPast(applicantId, CATSType.AGENT_CHALLENGE);
+        assertEquals(403, get(cookie, VerifyPage.PATH).getResponseCode());
+        addChallenge(applicantId, CATSType.AGENT_CHALLENGE);
+        assertEquals(200, get(cookie, VerifyPage.PATH).getResponseCode());
+    }
 }
index 13eaee5da8dffdfe209ba71aafc8d838004b6777..c0d6d4f74e4ee63a2c489d1ad76e812d029d6f98 100644 (file)
@@ -20,6 +20,7 @@ import java.security.Signature;
 import java.security.spec.RSAPrivateKeySpec;
 import java.security.spec.RSAPublicKeySpec;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -38,6 +39,7 @@ import club.wpia.gigi.database.DatabaseConnection;
 import club.wpia.gigi.database.DatabaseConnection.Link;
 import club.wpia.gigi.database.GigiPreparedStatement;
 import club.wpia.gigi.database.SQLFileManager.ImportType;
+import club.wpia.gigi.dbObjects.CATS;
 import club.wpia.gigi.dbObjects.CATS.CATSType;
 import club.wpia.gigi.dbObjects.CertificateProfile;
 import club.wpia.gigi.dbObjects.Domain;
@@ -332,12 +334,28 @@ public abstract class ConfiguredTest {
     }
 
     public static void makeAgent(int uid) {
+        addChallenge(uid, CATSType.AGENT_CHALLENGE);
+        add100Points(uid);
+    }
+
+    public static void addChallenge(int uid, CATSType ct) {
         try (GigiPreparedStatement ps1 = new GigiPreparedStatement("INSERT INTO cats_passed SET user_id=?, variant_id=?, language='en_EN', version='1'")) {
             ps1.setInt(1, uid);
-            ps1.setInt(2, CATSType.AGENT_CHALLENGE.getId());
+            ps1.setInt(2, ct.getId());
+            ps1.execute();
+        }
+    }
+
+    public static void addChallengeInPast(int uid, CATSType ct) {
+        try (GigiPreparedStatement ps1 = new GigiPreparedStatement("INSERT INTO cats_passed SET user_id=?, variant_id=?, pass_date=?, language='en_EN', version='1'")) {
+            ps1.setInt(1, uid);
+            ps1.setInt(2, ct.getId());
+            ps1.setTimestamp(3, new Timestamp(new Date(System.currentTimeMillis() - 24L * 60 * 60 * (CATS.TEST_MONTHS + 1) * 31 * 1000L).getTime()));
             ps1.execute();
         }
+    }
 
+    public static void add100Points(int uid) {
         try (GigiPreparedStatement ps2 = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, points='100'")) {
             ps2.setInt(1, uid);
             ps2.setInt(2, User.getById(uid).getPreferredName().getId());