]> WPIA git - gigi.git/commitdiff
add: implement to check if user has valid challenges for roles
authorINOPIAE <m.maengel@inopiae.de>
Tue, 16 Jul 2019 10:39:51 +0000 (12:39 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 8 Sep 2019 19:24:48 +0000 (21:24 +0200)
This is just the basic work for upcoming patches to enforce the
requirement to have a challenge passed within in the given time for
valid tests for certain areas. see issue #150

Change-Id: Ie53634cd2c1d74829c811cd4d35f584ddb0eb307

src/club/wpia/gigi/dbObjects/User.java
tests/club/wpia/gigi/dbObjects/TestUser.java

index 10586d71a02414fd2bded81816304ddf6936c468..3b4f4671d2a01b8462e2c0b6238ea7c48b7e3d0a 100644 (file)
@@ -680,4 +680,24 @@ public class User extends CertificateOwner {
             update.executeUpdate();
         }
     }
+
+    public boolean hasValidRAChallenge() {
+        return CATS.isInCatsLimit(getId(), CATSType.AGENT_CHALLENGE.getId());
+    }
+
+    public boolean hasValidSupportChallenge() {
+        return CATS.isInCatsLimit(getId(), CATSType.SUPPORT_DP_CHALLENGE_NAME.getId());
+    }
+
+    public boolean hasValidOrgAdminChallenge() {
+        return CATS.isInCatsLimit(getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME.getId());
+    }
+
+    public boolean hasValidOrgAgentChallenge() {
+        return CATS.isInCatsLimit(getId(), CATSType.ORG_AGENT_CHALLENGE.getId());
+    }
+
+    public boolean hasValidTTPAgentChallenge() {
+        return CATS.isInCatsLimit(getId(), CATSType.TTP_AGENT_CHALLENGE.getId());
+    }
 }
index b25970b6c8b4815a61ef22ae2706b5043398f8d2..ed3f1c951b3df52d3dd31ad693df7227e7a4b83d 100644 (file)
@@ -2,9 +2,14 @@ package club.wpia.gigi.dbObjects;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.sql.Date;
+
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.CATS.CATSType;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
 import club.wpia.gigi.testUtils.ClientBusinessTest;
 
@@ -64,4 +69,40 @@ public class TestUser extends ClientBusinessTest {
         assertEquals("HPH", u0.getInitials());
     }
 
+    @Test
+    public void testValidCATS() throws IOException, GeneralSecurityException {
+        Date min11month = new Date(System.currentTimeMillis() - 24L * 60 * 60 * 11 * 31 * 1000L);
+        Date min12month = new Date(System.currentTimeMillis() - 24L * 60 * 60 * 12 * 31 * 1000L);
+
+        assertFalse(u.hasValidRAChallenge());
+        CATS.enterResult(u, CATSType.AGENT_CHALLENGE, min12month, "en_US", "1");
+        assertFalse(u.hasValidRAChallenge());
+        CATS.enterResult(u, CATSType.AGENT_CHALLENGE, min11month, "en_US", "1");
+        assertTrue(u.hasValidRAChallenge());
+
+        assertFalse(u.hasValidSupportChallenge());
+        CATS.enterResult(u, CATSType.SUPPORT_DP_CHALLENGE_NAME, min12month, "en_US", "1");
+        assertFalse(u.hasValidSupportChallenge());
+        CATS.enterResult(u, CATSType.SUPPORT_DP_CHALLENGE_NAME, min11month, "en_US", "1");
+        assertTrue(u.hasValidSupportChallenge());
+
+        assertFalse(u.hasValidOrgAdminChallenge());
+        CATS.enterResult(u, CATSType.ORG_ADMIN_DP_CHALLENGE_NAME, min12month, "en_US", "1");
+        assertFalse(u.hasValidOrgAdminChallenge());
+        CATS.enterResult(u, CATSType.ORG_ADMIN_DP_CHALLENGE_NAME, min11month, "en_US", "1");
+        assertTrue(u.hasValidOrgAdminChallenge());
+
+        assertFalse(u.hasValidOrgAgentChallenge());
+        CATS.enterResult(u, CATSType.ORG_AGENT_CHALLENGE, min12month, "en_US", "1");
+        assertFalse(u.hasValidOrgAgentChallenge());
+        CATS.enterResult(u, CATSType.ORG_AGENT_CHALLENGE, min11month, "en_US", "1");
+        assertTrue(u.hasValidOrgAgentChallenge());
+
+        assertFalse(u.hasValidTTPAgentChallenge());
+        CATS.enterResult(u, CATSType.TTP_AGENT_CHALLENGE, min12month, "en_US", "1");
+        assertFalse(u.hasValidTTPAgentChallenge());
+        CATS.enterResult(u, CATSType.TTP_AGENT_CHALLENGE, min11month, "en_US", "1");
+        assertTrue(u.hasValidTTPAgentChallenge());
+    }
+
 }