diff options
author | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-02-25 11:32:57 +0100 |
---|---|---|
committer | Christian Kollmann <christian.kollmann@a-sit.at> | 2021-02-25 13:27:18 +0100 |
commit | 2c49670334049a065d86defc8524f2e5eae6ca78 (patch) | |
tree | dbf4b965e6e935eb0bb6fe4030b3440ce811a664 /eidas_modules/authmodule-eIDAS-v2/src/test | |
parent | 8c13c21799beed76eea848504677eb935026397c (diff) | |
download | National_eIDAS_Gateway-2c49670334049a065d86defc8524f2e5eae6ca78.tar.gz National_eIDAS_Gateway-2c49670334049a065d86defc8524f2e5eae6ca78.tar.bz2 National_eIDAS_Gateway-2c49670334049a065d86defc8524f2e5eae6ca78.zip |
Refactor and test ReceiveOtherLoginMethodGuiResponse
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/ReceiveOtherLoginMethodGuiResponseTaskTest.java | 89 |
1 files changed, 47 insertions, 42 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java index ae4b5d8c..c6b2e1fe 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java @@ -2,12 +2,12 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks; 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.ReceiveOtherLoginMethodGuiResponseTask; import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; 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; @@ -23,16 +23,10 @@ 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; +import static org.junit.Assert.*; +import static org.springframework.util.Assert.isInstanceOf; @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" @@ -41,27 +35,25 @@ import java.io.UnsupportedEncodingException; @WebAppConfiguration public class ReceiveOtherLoginMethodGuiResponseTaskTest { - @Autowired private ReceiveOtherLoginMethodGuiResponseTask task; + @Autowired + private ReceiveOtherLoginMethodGuiResponseTask task; - private ExecutionContextImpl executionContext = new ExecutionContextImpl(); + private final 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() { @@ -79,57 +71,70 @@ public class ReceiveOtherLoginMethodGuiResponseTaskTest { @Test public void withMobileSignatureSelection() throws TaskExecutionException { - test(SelectedLoginMethod.MOBILE_PHONE_SIGNATURE_LOGIN); + testTransition(SelectedLoginMethod.MOBILE_PHONE_SIGNATURE_LOGIN, Constants.TRANSITION_TO_GENERATE_MOBILE_PHONE_SIGNATURE_REQUEST_TASK); } @Test public void withEidasSelection() throws TaskExecutionException { - test(SelectedLoginMethod.MOBILE_PHONE_SIGNATURE_LOGIN); + testTransition(SelectedLoginMethod.EIDAS_LOGIN, Constants.TRANSITION_TO_GENERATE_EIDAS_LOGIN); } @Test public void withNoOtherLoginSelection() throws TaskExecutionException { - test(SelectedLoginMethod.NO_OTHER_LOGIN); + testTransition(SelectedLoginMethod.NO_OTHER_LOGIN, Constants.TRANSITION_TO_GENERATE_GUI_QUERY_AUSTRIAN_RESIDENCE_TASK); } - public void test(SelectedLoginMethod loginMethod) throws TaskExecutionException { - String parameterValue = loginMethod.name(); - httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, parameterValue); + public void testTransition(SelectedLoginMethod loginMethod, String expectedTransition) throws TaskExecutionException { + httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, loginMethod.name()); 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)); + assertFalse("wrong pendingReq auth flag", pendingReq.isAuthenticated()); + assertFalse("wrong process-cancelled flag", executionContext.isProcessCancelled()); + assertNotNull("no login-selection found", executionContext.get(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER)); + assertEquals("Wrong login-selection found", loginMethod, executionContext.get(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER)); + assertEquals("Next task", true, executionContext.get(expectedTransition)); } + public void withInvalidSelection() { + httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, RandomStringUtils.randomAlphabetic(2)); - @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); + TaskExecutionException e = assertThrows(TaskExecutionException.class, + () -> task.execute(pendingReq, executionContext)); + + assertEquals(pendingReq.getPendingRequestId(), e.getPendingRequestID()); + isInstanceOf(InvalidUserInputException.class, e.getOriginalException()); } - @Test(expected = TaskExecutionException.class) - public void withNullSelection() throws TaskExecutionException { + @Test + public void withNullSelection() { httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, "null"); - task.execute(pendingReq, executionContext); + + TaskExecutionException e = assertThrows(TaskExecutionException.class, + () -> task.execute(pendingReq, executionContext)); + + assertEquals(pendingReq.getPendingRequestId(), e.getPendingRequestID()); + isInstanceOf(InvalidUserInputException.class, e.getOriginalException()); } - @Test(expected = TaskExecutionException.class) - public void withEmptySelection() throws TaskExecutionException { + @Test + public void withEmptySelection() { httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, ""); - task.execute(pendingReq, executionContext); + + TaskExecutionException e = assertThrows(TaskExecutionException.class, + () -> task.execute(pendingReq, executionContext)); + + assertEquals(pendingReq.getPendingRequestId(), e.getPendingRequestID()); + isInstanceOf(InvalidUserInputException.class, e.getOriginalException()); } - @Test(expected = TaskExecutionException.class) - public void withoutLoginMethodSelection() throws TaskExecutionException, UnsupportedEncodingException { - task.execute(pendingReq, executionContext); + @Test + public void withoutLoginMethodSelection() { + + TaskExecutionException e = assertThrows(TaskExecutionException.class, + () -> task.execute(pendingReq, executionContext)); + + assertEquals(pendingReq.getPendingRequestId(), e.getPendingRequestID()); + isInstanceOf(InvalidUserInputException.class, e.getOriginalException()); } } |