aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/test/java
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2019-10-31 08:16:30 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2019-10-31 08:16:30 +0100
commit5bda3bcc87f7c58dfa782e76eecb183631369ede (patch)
tree294ba6f01edafc041cda6375a2b3447060351f03 /eidas_modules/authmodule-eIDAS-v2/src/test/java
parent319dff9d1a119f94789b30e4d4e0d1df25ba7ce6 (diff)
downloadNational_eIDAS_Gateway-5bda3bcc87f7c58dfa782e76eecb183631369ede.tar.gz
National_eIDAS_Gateway-5bda3bcc87f7c58dfa782e76eecb183631369ede.tar.bz2
National_eIDAS_Gateway-5bda3bcc87f7c58dfa782e76eecb183631369ede.zip
add jUnit tests for static ProviderName
include an update to eaaf-core 1.0.12-snapshot
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/dummy/DummySpecificCommunicationService.java60
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskFirstTest.java103
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskSecondTest.java119
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskThirdTest.java92
4 files changed, 374 insertions, 0 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/dummy/DummySpecificCommunicationService.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/dummy/DummySpecificCommunicationService.java
new file mode 100644
index 00000000..c2b6f08f
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/dummy/DummySpecificCommunicationService.java
@@ -0,0 +1,60 @@
+package at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2.dummy;
+
+import java.util.Collection;
+
+import eu.eidas.auth.commons.attribute.AttributeDefinition;
+import eu.eidas.auth.commons.light.ILightRequest;
+import eu.eidas.auth.commons.light.ILightResponse;
+import eu.eidas.auth.commons.tx.BinaryLightToken;
+import eu.eidas.specificcommunication.BinaryLightTokenHelper;
+import eu.eidas.specificcommunication.exception.SpecificCommunicationException;
+import eu.eidas.specificcommunication.protocol.SpecificCommunicationService;
+
+public class DummySpecificCommunicationService implements SpecificCommunicationService {
+
+ private ILightRequest iLightRequest;
+ private ILightResponse iLightResponse;
+
+ @Override
+ public BinaryLightToken putRequest(ILightRequest iLightRequest) throws SpecificCommunicationException {
+ this.iLightRequest = iLightRequest;
+ return BinaryLightTokenHelper.createBinaryLightToken("Test", "TestSecret", "SHA-256");
+ }
+
+ @Override
+ public ILightRequest getAndRemoveRequest(String tokenBase64, Collection<AttributeDefinition<?>> registry)
+ throws SpecificCommunicationException {
+ return iLightRequest;
+ }
+
+ @Override
+ public BinaryLightToken putResponse(ILightResponse iLightResponse) throws SpecificCommunicationException {
+ this.iLightResponse = iLightResponse;
+ return BinaryLightTokenHelper.createBinaryLightToken("Test", "TestSecret", "SHA-256");
+ }
+
+ @Override
+ public ILightResponse getAndRemoveResponse(String tokenBase64, Collection<AttributeDefinition<?>> registry)
+ throws SpecificCommunicationException {
+ return iLightResponse;
+ }
+
+ public ILightRequest getiLightRequest() {
+ return iLightRequest;
+ }
+
+ public void setiLightRequest(ILightRequest iLightReques) {
+ this.iLightRequest = iLightReques;
+ }
+
+ public ILightResponse getiLightResponse() {
+ return iLightResponse;
+ }
+
+ public void setiLightResponse(ILightResponse iLightResponse) {
+ this.iLightResponse = iLightResponse;
+ }
+
+
+
+}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskFirstTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskFirstTest.java
new file mode 100644
index 00000000..342ef424
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskFirstTest.java
@@ -0,0 +1,103 @@
+package at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2.tasks;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.Constants;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.tasks.GenerateAuthnRequestTask;
+import at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2.dummy.DummySpecificCommunicationService;
+import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants;
+import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext;
+import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException;
+import at.gv.egiz.eaaf.core.exceptions.EAAFException;
+import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySPConfiguration;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
+import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
+import eu.eidas.auth.commons.light.ILightRequest;
+import eu.eidas.specificcommunication.exception.SpecificCommunicationException;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/SpringTest-context_tasks_test.xml")
+@DirtiesContext
+public class GenerateAuthnRequestTaskFirstTest {
+
+ @Autowired(required=true) private GenerateAuthnRequestTask task;
+ @Autowired(required=true) private DummySpecificCommunicationService commService;
+ @Autowired(required=true) private IConfiguration basicConfig;
+
+ final ExecutionContext executionContext = new ExecutionContextImpl();
+ private MockHttpServletRequest httpReq;
+ private MockHttpServletResponse httpResp;
+ private TestRequestImpl pendingReq;
+ private DummySPConfiguration oaParam;
+
+ @BeforeClass
+ public static void classInitializer() throws IOException {
+ final String current = new java.io.File( "." ).toURI().toString();
+ System.setProperty("eidas.ms.configuration", current + "src/test/resources/config/junit_config_1.properties");
+
+ }
+
+ @Before
+ public void setUp() {
+
+ httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler");
+ httpResp = new MockHttpServletResponse();
+ RequestContextHolder.resetRequestAttributes();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
+
+ Map<String, String> spConfig = new HashMap<>();
+ spConfig.put(EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER, "testSp");
+ spConfig.put("target", "urn:publicid:gv.at:cdid+XX");
+ oaParam = new DummySPConfiguration(spConfig , basicConfig);
+
+ pendingReq = new TestRequestImpl();
+ pendingReq.setSpConfig(oaParam);
+ pendingReq.setPendingReqId(at.gv.egiz.eaaf.core.impl.utils.Random.nextProcessReferenceValue());
+ pendingReq.setAuthURL("http://test.com/");
+
+ }
+
+ @Test
+ @DirtiesContext
+ public void withCustomStaticProviderNameForPublicSPs() throws TaskExecutionException, SpecificCommunicationException {
+ executionContext.put(MSeIDASNodeConstants.REQ_PARAM_SELECTED_COUNTRY, "CC");
+
+ try {
+ task.execute(pendingReq, executionContext);
+
+ } catch (TaskExecutionException e) {
+ //forward URL is not set in example config
+ org.springframework.util.Assert.isInstanceOf(EAAFConfigurationException.class, e.getOriginalException(), "Wrong exception");
+ Assert.assertEquals("wrong errorCode", "config.08", ((EAAFException) e.getOriginalException()).getErrorId());
+ Assert.assertEquals("wrong parameter size", 1, ((EAAFException) e.getOriginalException()).getParams().length);
+ Assert.assertEquals("wrong errorMsg", Constants.CONIG_PROPS_EIDAS_NODE_FORWARD_URL, ((EAAFException) e.getOriginalException()).getParams()[0]);
+
+ }
+
+ ILightRequest eIDASReq = commService.getAndRemoveRequest(null, null);
+
+ Assert.assertEquals("ProviderName is not Static", "myNode", eIDASReq.getProviderName());
+ Assert.assertEquals("no PublicSP", "public", eIDASReq.getSpType());
+ Assert.assertEquals("wrong LoA", "http://eidas.europa.eu/LoA/high", eIDASReq.getLevelOfAssurance());
+ }
+
+}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskSecondTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskSecondTest.java
new file mode 100644
index 00000000..dd1bf523
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskSecondTest.java
@@ -0,0 +1,119 @@
+package at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2.tasks;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.Constants;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.exception.eIDASAuthenticationException;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.tasks.GenerateAuthnRequestTask;
+import at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2.dummy.DummySpecificCommunicationService;
+import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants;
+import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext;
+import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException;
+import at.gv.egiz.eaaf.core.exceptions.EAAFException;
+import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySPConfiguration;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
+import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
+import eu.eidas.auth.commons.light.ILightRequest;
+import eu.eidas.specificcommunication.exception.SpecificCommunicationException;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/SpringTest-context_tasks_test.xml")
+@DirtiesContext
+public class GenerateAuthnRequestTaskSecondTest {
+
+ @Autowired(required=true) private GenerateAuthnRequestTask task;
+ @Autowired(required=true) private DummySpecificCommunicationService commService;
+ @Autowired(required=true) private IConfiguration basicConfig;
+
+ final ExecutionContext executionContext = new ExecutionContextImpl();
+ private MockHttpServletRequest httpReq;
+ private MockHttpServletResponse httpResp;
+ private TestRequestImpl pendingReq;
+ private DummySPConfiguration oaParam;
+
+ @BeforeClass
+ public static void classInitializer() throws IOException {
+ final String current = new java.io.File( "." ).toURI().toString();
+ System.setProperty("eidas.ms.configuration", current + "../../basicConfig/default_config.properties");
+
+ }
+
+ @Before
+ public void setUp() {
+
+ httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler");
+ httpResp = new MockHttpServletResponse();
+ RequestContextHolder.resetRequestAttributes();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
+
+ Map<String, String> spConfig = new HashMap<>();
+ spConfig.put(EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER, "testSp");
+ spConfig.put("target", "urn:publicid:gv.at:cdid+XX");
+ oaParam = new DummySPConfiguration(spConfig , basicConfig);
+
+ pendingReq = new TestRequestImpl();
+ pendingReq.setSpConfig(oaParam);
+ pendingReq.setPendingReqId(at.gv.egiz.eaaf.core.impl.utils.Random.nextProcessReferenceValue());
+ pendingReq.setAuthURL("http://test.com/");
+
+ }
+
+ @Test
+ public void noCountryCode() {
+ try {
+ task.execute(pendingReq, executionContext);
+ Assert.fail("No countryCode not detected");
+
+ } catch (TaskExecutionException e) {
+ Assert.assertEquals("wrong pendingReqId", pendingReq.getPendingRequestId(), e.getPendingRequestID());
+ org.springframework.util.Assert.isInstanceOf(eIDASAuthenticationException.class, e.getOriginalException(), "Wrong exception");
+ Assert.assertEquals("wrong errorCode", "eidas.03", ((EAAFException) e.getOriginalException()).getErrorId());
+
+ }
+
+ }
+
+ @Test
+ @DirtiesContext
+ public void withStaticProviderNameForPublicSPs() throws TaskExecutionException, SpecificCommunicationException {
+ executionContext.put(MSeIDASNodeConstants.REQ_PARAM_SELECTED_COUNTRY, "CC");
+
+ try {
+ task.execute(pendingReq, executionContext);
+
+ } catch (TaskExecutionException e) {
+ //forward URL is not set in example config
+ org.springframework.util.Assert.isInstanceOf(EAAFConfigurationException.class, e.getOriginalException(), "Wrong exception");
+ Assert.assertEquals("wrong errorCode", "config.08", ((EAAFException) e.getOriginalException()).getErrorId());
+ Assert.assertEquals("wrong parameter size", 1, ((EAAFException) e.getOriginalException()).getParams().length);
+ Assert.assertEquals("wrong errorMsg", Constants.CONIG_PROPS_EIDAS_NODE_FORWARD_URL, ((EAAFException) e.getOriginalException()).getParams()[0]);
+
+ }
+
+ ILightRequest eIDASReq = commService.getAndRemoveRequest(null, null);
+
+ Assert.assertEquals("ProviderName is not Static", Constants.DEFAULT_PROPS_EIDAS_NODE_STATIC_PROVIDERNAME_FOR_PUBLIC_SP, eIDASReq.getProviderName());
+ Assert.assertEquals("no PublicSP", "public", eIDASReq.getSpType());
+ Assert.assertEquals("wrong LoA", "http://eidas.europa.eu/LoA/high", eIDASReq.getLevelOfAssurance());
+ }
+
+}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskThirdTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskThirdTest.java
new file mode 100644
index 00000000..cf2de754
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/tasks/GenerateAuthnRequestTaskThirdTest.java
@@ -0,0 +1,92 @@
+package at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2.tasks;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.tasks.GenerateAuthnRequestTask;
+import at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2.dummy.DummySpecificCommunicationService;
+import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants;
+import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext;
+import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySPConfiguration;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
+import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
+import eu.eidas.auth.commons.light.ILightRequest;
+import eu.eidas.specificcommunication.exception.SpecificCommunicationException;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/SpringTest-context_tasks_test.xml")
+@DirtiesContext
+public class GenerateAuthnRequestTaskThirdTest {
+
+ @Autowired(required=true) private GenerateAuthnRequestTask task;
+ @Autowired(required=true) private DummySpecificCommunicationService commService;
+ @Autowired(required=true) private IConfiguration basicConfig;
+
+ final ExecutionContext executionContext = new ExecutionContextImpl();
+ private MockHttpServletRequest httpReq;
+ private MockHttpServletResponse httpResp;
+ private TestRequestImpl pendingReq;
+ private DummySPConfiguration oaParam;
+
+ @BeforeClass
+ public static void classInitializer() throws IOException {
+ final String current = new java.io.File( "." ).toURI().toString();
+ System.setProperty("eidas.ms.configuration", current + "src/test/resources/config/junit_config_2.properties");
+
+ }
+
+ @Before
+ public void setUp() {
+
+ httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler");
+ httpResp = new MockHttpServletResponse();
+ RequestContextHolder.resetRequestAttributes();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
+
+ Map<String, String> spConfig = new HashMap<>();
+ spConfig.put(EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER, "testSp");
+ spConfig.put("target", "urn:publicid:gv.at:cdid+XX");
+ oaParam = new DummySPConfiguration(spConfig , basicConfig);
+
+ pendingReq = new TestRequestImpl();
+ pendingReq.setSpConfig(oaParam);
+ pendingReq.setPendingReqId(at.gv.egiz.eaaf.core.impl.utils.Random.nextProcessReferenceValue());
+ pendingReq.setAuthURL("http://test.com/");
+
+
+ }
+
+ @Test
+ @DirtiesContext
+ public void withDynamicProviderNameForPublicSPs() throws TaskExecutionException, SpecificCommunicationException {
+ executionContext.put(MSeIDASNodeConstants.REQ_PARAM_SELECTED_COUNTRY, "CC");
+
+ task.execute(pendingReq, executionContext);
+ Assert.assertEquals("Wrong http statusCode", 302, httpResp.getStatus());
+
+ ILightRequest eIDASReq = commService.getAndRemoveRequest(null, null);
+
+ Assert.assertNull("ProviderName found", eIDASReq.getProviderName());
+ Assert.assertEquals("no PublicSP", "public", eIDASReq.getSpType());
+ Assert.assertEquals("wrong LoA", "http://eidas.europa.eu/LoA/high", eIDASReq.getLevelOfAssurance());
+ }
+
+}