aboutsummaryrefslogtreecommitdiff
path: root/id/server/modules/moa-id-module-ehvd_integration/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/modules/moa-id-module-ehvd_integration/src/test/java')
-rw-r--r--id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/attributes/PvpRoleAttributeBuilderTest.java26
-rw-r--r--id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java80
2 files changed, 103 insertions, 3 deletions
diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/attributes/PvpRoleAttributeBuilderTest.java b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/attributes/PvpRoleAttributeBuilderTest.java
index df02c6f4e..cabd8df19 100644
--- a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/attributes/PvpRoleAttributeBuilderTest.java
+++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/attributes/PvpRoleAttributeBuilderTest.java
@@ -1,6 +1,7 @@
package at.gv.egovernment.moa.id.auth.modules.ehvd.test.attributes;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -27,6 +28,7 @@ import at.gv.egiz.eaaf.core.impl.idp.builder.SimpleStringAttributeGenerator;
import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySPConfiguration;
import at.gv.egovernment.moa.id.auth.modules.ehvd.attributes.PvpRoleAttributeBuilder;
import at.gv.egovernment.moa.id.data.AuthenticationRole;
+import at.gv.egovernment.moa.id.data.AuthenticationRoleFactory;
import at.gv.egovernment.moa.id.data.MOAAuthenticationData;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -99,6 +101,8 @@ public class PvpRoleAttributeBuilderTest {
// validate state
assertNotNull("wrong attr. value", attrValue);
+ assertFalse("List delimiter after last element" ,attrValue.endsWith(";"));
+
String[] el = attrValue.split(";");
assertEquals("wrong role count", 4, el.length);
@@ -110,6 +114,28 @@ public class PvpRoleAttributeBuilderTest {
}
+ @Test
+ public void brzProductionRole() throws AttributeBuilderException {
+
+ IAuthData authData = generateAuthData(Arrays.asList(
+ AuthenticationRoleFactory.buildFormPVPole("EPI-GDA()")));
+
+ // perform test
+ String attrValue = toTest.build(oaParam, authData, g);
+
+ // validate state
+ assertNotNull("wrong attr. value", attrValue);
+ assertFalse("List delimiter after last element" ,attrValue.endsWith(";"));
+
+
+ String[] el = attrValue.split(";");
+ assertEquals("wrong role count", 1, el.length);
+ assertEquals("wrong 1. role", "EPI-GDA()", el[0]);
+
+ assertEquals("wrong role attr. value", "EPI-GDA()", attrValue);
+
+ }
+
private IAuthData generateAuthData(List<AuthenticationRole> roles) {
MOAAuthenticationData authData = new MOAAuthenticationData(null);
if (roles != null) {
diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java
index 8620ef98b..adedd1d02 100644
--- a/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java
+++ b/id/server/modules/moa-id-module-ehvd_integration/src/test/java/at/gv/egovernment/moa/id/auth/modules/ehvd/test/tasks/InjectEhvdIdentityInformationTaskTest.java
@@ -7,7 +7,6 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
-import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
@@ -213,13 +212,61 @@ public class InjectEhvdIdentityInformationTaskTest {
}
}
+
@Test
- public void validateState() throws TaskExecutionException, PendingReqIdValidationException {
+ public void noValidGdaRole() throws TaskExecutionException, PendingReqIdValidationException {
// set-up EHVD response
String role1 = RandomStringUtils.randomAlphabetic(10);
String role2 = RandomStringUtils.randomAlphabetic(10);
when(ehvdService.getGDA(any())).thenReturn(generateGdaResponse(true, Arrays.asList(role1, role2)));
+ try {
+ task.execute(pendingReq, context);
+ fail("wrong state not detected");
+
+ } catch (final TaskExecutionException e) {
+ Assert.isInstanceOf(AuthenticationException.class, e.getOriginalException(), "wrong execpetion");
+ assertEquals("wrong errorCode", "ehvd.04", ((EAAFException) e.getOriginalException()).getErrorId());
+
+ }
+ }
+
+
+ @Test
+ public void validateStateWithRandomData() throws TaskExecutionException, PendingReqIdValidationException {
+ // set-up EHVD response
+ String role1 = RandomStringUtils.randomAlphabetic(10);
+ String role2 = "1.2.40.0.34.5.2:101";
+ String role3 = RandomStringUtils.randomAlphabetic(10);
+ when(ehvdService.getGDA(any())).thenReturn(generateGdaResponse(true, Arrays.asList(role1, role2, role3)));
+
+ task.execute(pendingReq, context);
+
+ // validate state
+ final IRequest storedReq = storage.getPendingRequest(pendingReq.getPendingRequestId());
+ assertNotNull("pendingReq not stored", storedReq);
+
+ final AuthenticationSessionWrapper moaSession = storedReq.getSessionData(
+ AuthenticationSessionWrapper.class);
+
+ assertFalse("foreign", moaSession.isForeigner());
+ assertFalse("mandate", moaSession.isMandateUsed());
+ assertEquals("missing attributes", 1, moaSession.getGenericSessionDataStorage().size());
+ assertNotNull("no Role attr", moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME));
+ assertEquals("wrong role attr",
+ "EPI-GDA()",
+ moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME, String.class));
+
+ }
+
+ @Test
+ public void validateState() throws TaskExecutionException, PendingReqIdValidationException {
+ // set-up EHVD response
+ String role1 = "1.2.40.0.33.5.2.101";
+ String role2 = "1.2.40.0.34.5.2:100";
+ String role3 = RandomStringUtils.randomAlphabetic(10);
+ when(ehvdService.getGDA(any())).thenReturn(generateGdaResponse(true, Arrays.asList(role1, role2, role3)));
+
task.execute(pendingReq, context);
// validate state
@@ -234,11 +281,38 @@ public class InjectEhvdIdentityInformationTaskTest {
assertEquals("missing attributes", 1, moaSession.getGenericSessionDataStorage().size());
assertNotNull("no Role attr", moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME));
assertEquals("wrong role attr",
- role1 + ";" + role2,
+ "EPI-GDA()",
moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME, String.class));
}
+ @Test
+ public void validateStateSecondOid() throws TaskExecutionException, PendingReqIdValidationException {
+ // set-up EHVD response
+ String role1 = "1.2.40.0.33.5.2.101";
+ String role2 = "1.2.40.0.34.5.2:158";
+ String role3 = RandomStringUtils.randomAlphabetic(10);
+ when(ehvdService.getGDA(any())).thenReturn(generateGdaResponse(true, Arrays.asList(role1, role2, role3)));
+
+ task.execute(pendingReq, context);
+
+ // validate state
+ final IRequest storedReq = storage.getPendingRequest(pendingReq.getPendingRequestId());
+ assertNotNull("pendingReq not stored", storedReq);
+
+ final AuthenticationSessionWrapper moaSession = storedReq.getSessionData(
+ AuthenticationSessionWrapper.class);
+
+ assertFalse("foreign", moaSession.isForeigner());
+ assertFalse("mandate", moaSession.isMandateUsed());
+ assertEquals("missing attributes", 1, moaSession.getGenericSessionDataStorage().size());
+ assertNotNull("no Role attr", moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME));
+ assertEquals("wrong role attr",
+ "EPI-GDA()",
+ moaSession.getGenericDataFromSession(PVPConstants.ROLES_NAME, String.class));
+
+ }
+
private GdaIndexResponse generateGdaResponse(boolean isActive, List<String> roles) {
GdaIndexResponse resp = new GdaIndexResponse();
GdaDescriptor gda = new GdaDescriptor();