aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/test
diff options
context:
space:
mode:
authorAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-02-05 11:58:12 +0100
committerAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-02-05 12:03:10 +0100
commit6e16e4bbddf6dcddf2ed7b25fd55b41adfa4a08c (patch)
treeb47b844ef2a701bc65c7de6a242622053327d3b1 /eidas_modules/authmodule-eIDAS-v2/src/test
parentde03adfbe79968f65bb711d7b3a583eeb1054140 (diff)
downloadNational_eIDAS_Gateway-6e16e4bbddf6dcddf2ed7b25fd55b41adfa4a08c.tar.gz
National_eIDAS_Gateway-6e16e4bbddf6dcddf2ed7b25fd55b41adfa4a08c.tar.bz2
National_eIDAS_Gateway-6e16e4bbddf6dcddf2ed7b25fd55b41adfa4a08c.zip
added test for ReceiveLoginMethodGuiResponse
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveLoginMethodGuiResponseTaskTest.java139
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml4
2 files changed, 141 insertions, 2 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveLoginMethodGuiResponseTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveLoginMethodGuiResponseTaskTest.java
new file mode 100644
index 00000000..c6729a03
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveLoginMethodGuiResponseTaskTest.java
@@ -0,0 +1,139 @@
+package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;
+
+import at.asitplus.eidas.specific.connector.MsEidasNodeConstants;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SelectedLoginMethod;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.InvalidUserInputException;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveLoginMethodGuiResponseTask;
+import at.gv.egiz.eaaf.core.api.data.EaafConstants;
+import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
+import at.gv.egiz.eaaf.core.impl.idp.controller.tasks.AbstractLocaleAuthServletTask;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
+import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
+import org.apache.commons.lang3.RandomStringUtils;
+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.context.i18n.LocaleContextHolder;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import java.io.UnsupportedEncodingException;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration({
+// "/applicationContext.xml",
+// "/specific_eIDAS_connector.beans.xml",
+// "/eaaf_core.beans.xml",
+// "/eaaf_pvp.beans.xml",
+// "/eaaf_pvp_idp.beans.xml",
+// "/spring/SpringTest-context_simple_storage.xml" })
+@ContextConfiguration(locations = {
+ "/SpringTest-context_tasks_test.xml",
+ "/SpringTest-context_basic_mapConfig.xml"
+})
+@ActiveProfiles(profiles = {"deprecatedConfig"})
+@WebAppConfiguration
+public class ReceiveLoginMethodGuiResponseTaskTest {
+
+ @Autowired private ReceiveLoginMethodGuiResponseTask task;
+
+ private ExecutionContextImpl executionContext = new ExecutionContextImpl();
+ private TestRequestImpl pendingReq;
+ private MockHttpServletRequest httpReq;
+ private MockHttpServletResponse httpResp;
+
+ /**
+ * jUnit class initializer.
+ *
+ */
+ @BeforeClass
+ public static void classInitializer() {
+ final String current = new java.io.File(".").toURI().toString();
+ System.setProperty("eidas.ms.configuration", current + "src/test/resources/config/junit_config_1.properties");
+
+ }
+
+ /**
+ * jUnit test set-up.
+ *
+ */
+ @Before
+ public void initialize() {
+ httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector");
+ httpResp = new MockHttpServletResponse();
+ RequestContextHolder.resetRequestAttributes();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
+
+ pendingReq = new TestRequestImpl();
+ pendingReq.setAuthUrl("https://localhost/ms_connector");
+ pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10));
+
+ LocaleContextHolder.resetLocaleContext();
+ }
+
+ @Test
+ public void withMobileSignatureSelection() throws TaskExecutionException {
+ test(SelectedLoginMethod.MOBILE_PHONE_SIGNATURE_LOGIN);
+ }
+
+ @Test
+ public void withEidasSelection() throws TaskExecutionException {
+ test(SelectedLoginMethod.MOBILE_PHONE_SIGNATURE_LOGIN);
+ }
+
+ @Test
+ public void withNoOtherLoginSelection() throws TaskExecutionException {
+ test(SelectedLoginMethod.NO_OTHER_LOGIN);
+ }
+
+ public void test(SelectedLoginMethod loginMethod) throws TaskExecutionException {
+ String parameterValue = loginMethod.name();
+ httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, parameterValue);
+
+ task.execute(pendingReq, executionContext);
+
+ //result validation
+ Assert.assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated());
+ Assert.assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled());
+
+ Assert.assertNotNull("no login-selection found",
+ executionContext.get(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER));
+ Assert.assertEquals("Wrong login-selection found", loginMethod,
+ executionContext.get(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER));
+ }
+
+
+ @Test(expected = TaskExecutionException.class)
+ public void withInvalidSelection() throws TaskExecutionException {
+ String parameterValue = RandomStringUtils.randomAlphabetic(2);
+ httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, parameterValue);
+ task.execute(pendingReq, executionContext);
+ }
+
+ @Test(expected = TaskExecutionException.class)
+ public void withNullSelection() throws TaskExecutionException {
+ httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, "null");
+ task.execute(pendingReq, executionContext);
+ }
+
+ @Test(expected = TaskExecutionException.class)
+ public void withEmptySelection() throws TaskExecutionException {
+ httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, "");
+ task.execute(pendingReq, executionContext);
+ }
+
+ @Test(expected = TaskExecutionException.class)
+ public void withoutLoginMethodSelection() throws TaskExecutionException, UnsupportedEncodingException {
+ task.execute(pendingReq, executionContext);
+ }
+}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml
index ed636eed..df7ce85f 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml
@@ -87,7 +87,7 @@
scope="prototype" />
<bean id="GenerateGuiTask"
- class="at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.GenerateGuiTask"
+ class="at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.GenerateLoginMethodGuiTask"
scope="prototype" />
<bean id="GenerateMobilePhoneSignatureRequestTask"
@@ -95,7 +95,7 @@
scope="prototype" />
<bean id="ReceiveGuiResponseTask"
- class="at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveGuiResponseTask"
+ class="at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveLoginMethodGuiResponseTask"
scope="prototype" />
<bean id="ReceiveMobilePhoneSignatureResponseTask"