diff options
author | Thomas <> | 2022-11-17 07:34:19 +0100 |
---|---|---|
committer | Thomas <> | 2022-11-17 07:34:19 +0100 |
commit | 288d67a809d82298933d8c92d177673039a55f89 (patch) | |
tree | b631ec8240c85fb3c95a105aa48b27ad774e26c3 /modules | |
parent | 0eb64119119f96bd48a49946cc9ab864f55902e5 (diff) | |
download | National_eIDAS_Gateway-288d67a809d82298933d8c92d177673039a55f89.tar.gz National_eIDAS_Gateway-288d67a809d82298933d8c92d177673039a55f89.tar.bz2 National_eIDAS_Gateway-288d67a809d82298933d8c92d177673039a55f89.zip |
test(core): optimize jUnit tests to get better test coverage
Diffstat (limited to 'modules')
8 files changed, 62 insertions, 10 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java index c9d13eaf..70a1e69a 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java @@ -23,6 +23,7 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2; +import at.asitplus.eidas.specific.core.MsEidasNodeConstants; import at.asitplus.eidas.specific.modules.core.eidas.EidasConstants; import at.gv.egiz.eaaf.core.api.data.EaafConstants; @@ -33,10 +34,11 @@ public class Constants { public static final String ERRORCODE_00 = "module.eidasauth.00"; - public static final String DATA_REQUESTERID = "req_requesterId"; - public static final String DATA_PROVIDERNAME = "req_providerName"; - public static final String DATA_REQUESTED_LOA_LIST = "req_requestedLoA"; - public static final String DATA_REQUESTED_LOA_COMPERISON = "req_requestedLoAComperision"; + public static final String DATA_REQUESTERID = MsEidasNodeConstants.DATA_REQUESTERID; + public static final String DATA_PROVIDERNAME = MsEidasNodeConstants.DATA_PROVIDERNAME; + public static final String DATA_REQUESTED_LOA_LIST = MsEidasNodeConstants.DATA_REQUESTED_LOA_LIST; + public static final String DATA_REQUESTED_LOA_COMPERISON = MsEidasNodeConstants.DATA_REQUESTED_LOA_COMPERISON; + public static final String DATA_FULL_EIDAS_RESPONSE = "resp_fulleIDASResponse"; public static final String DATA_FULL_EIDAS_RESPONSE_ALTERNATIVE = "resp_fulleIDASResponseAlternative"; diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java index 604a6588..6530c7b3 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/AlternativeSearchTask.java @@ -110,6 +110,9 @@ public class AlternativeSearchTask extends AbstractAuthServletTask { MatchingTaskUtils.getDetailedMatchingStatistic(pendingReq).incrementAlternativEidas(); + // store pending request before next step + requestStoreage.storePendingRequest(pendingReq); + //pre-validation of eIDAS data if (!preVerifyAlternativeEidasData(altEidasData, initialEidasData, intermediateMatchingState, executionContext)) { diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java index ecdf8ce0..09b90a1d 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveAustrianResidenceGuiResponseTask.java @@ -54,6 +54,7 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchSe import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterStatusResults; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; +import at.gv.egiz.eaaf.core.exceptions.EaafException; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException; import at.gv.egiz.eaaf.core.impl.idp.controller.tasks.AbstractLocaleAuthServletTask; @@ -163,11 +164,15 @@ public class ReceiveAustrianResidenceGuiResponseTask extends AbstractLocaleAuthS executionContext.put(TRANSITION_TO_GENERATE_GUI_QUERY_AUSTRIAN_RESIDENCE_TASK, false); } - + + // store pending request before next step + requestStoreage.storePendingRequest(pendingReq); + + } catch (WorkflowException e) { throw new TaskExecutionException(pendingReq, "Search with residency data failed", e); - } catch (EaafStorageException e) { + } catch (EaafException e) { log.error("Search with residency data failed", e); throw new TaskExecutionException(pendingReq, "Search with residency data failed", e); diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveMobilePhoneSignatureResponseTask.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveMobilePhoneSignatureResponseTask.java index 7db61bd0..644c1543 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveMobilePhoneSignatureResponseTask.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/ReceiveMobilePhoneSignatureResponseTask.java @@ -172,6 +172,9 @@ public class ReceiveMobilePhoneSignatureResponseTask extends AbstractAuthServlet log.info("Receive a valid assertion from IDP " + inboundMessage.getEntityID()); MatchingTaskUtils.getDetailedMatchingStatistic(pendingReq).setIdaLoginUsed(true); + // store pending request before next step + requestStoreage.storePendingRequest(pendingReq); + // load already existing information from session SimpleEidasData eidasData = MatchingTaskUtils.getInitialEidasData(pendingReq); RegisterStatusResults initialSearchResult = MatchingTaskUtils.getIntermediateMatchingResult(pendingReq); diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/AlternativeSearchTaskWithRegisterTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/AlternativeSearchTaskWithRegisterTest.java index 25a8a5b5..2506a9b6 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/AlternativeSearchTaskWithRegisterTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/AlternativeSearchTaskWithRegisterTest.java @@ -75,6 +75,7 @@ import at.gv.bmi.namespace.zmr_su.base._20040201_.ServicePort; import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasIdentitaetAnlageType; import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasSuchdatenType; import at.gv.egiz.eaaf.core.api.IRequest; +import at.gv.egiz.eaaf.core.api.IRequestStorage; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.EaafException; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; @@ -105,6 +106,10 @@ public class AlternativeSearchTaskWithRegisterTest { @Autowired private IZmrClient zmrClient; @Autowired private List<CountrySpecificDetailSearchProcessor> handlers; + + @Autowired(required = true) + protected IRequestStorage requestStoreage; + private RegisterSearchService registerSearchService; private ServicePort zmrMock = null; @@ -142,6 +147,7 @@ public class AlternativeSearchTaskWithRegisterTest { registerSearchService = new RegisterSearchService(handlers, zmrClient, ernpClient); task = new AlternativeSearchTask(registerSearchService, eidPostProcessor); + task.setRequestStoreage(requestStoreage); MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); MockHttpServletResponse httpResp = new MockHttpServletResponse(); diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskRegisterTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskRegisterTest.java index 8d52baf3..8d3959f4 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskRegisterTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskRegisterTest.java @@ -51,6 +51,7 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.test.clients.ZmrClientTe import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils; import at.gv.bmi.namespace.zmr_su.base._20040201.ResponseType; import at.gv.bmi.namespace.zmr_su.base._20040201_.ServicePort; +import at.gv.egiz.eaaf.core.api.IRequestStorage; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.EaafException; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; @@ -70,6 +71,9 @@ public class ReceiveAustrianResidenceGuiResponseTaskRegisterTest { @Autowired protected MsConnectorDummyConfigMap authConfig; + @Autowired(required = true) + protected IRequestStorage requestStoreage; + @Autowired private RegisterSearchService registerSearchService; @@ -112,6 +116,7 @@ public class ReceiveAustrianResidenceGuiResponseTaskRegisterTest { executionContext = new ExecutionContextImpl(); task = new ReceiveAustrianResidenceGuiResponseTask(registerSearchService); + task.setRequestStoreage(requestStoreage); httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); httpResp = new MockHttpServletResponse(); diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java index 3bd86e63..83284455 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java @@ -41,6 +41,7 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchSe import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterStatusResults; import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveAustrianResidenceGuiResponseTask; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils; +import at.gv.egiz.eaaf.core.api.IRequestStorage; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper; @@ -58,6 +59,9 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest { @Autowired protected MsConnectorDummyConfigMap authConfig; + @Autowired(required = true) + protected IRequestStorage requestStoreage; + @MockBean private RegisterSearchService registerSearchService; @@ -77,7 +81,8 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest { public void setUp() throws Exception { executionContext = new ExecutionContextImpl(); task = new ReceiveAustrianResidenceGuiResponseTask(registerSearchService); - + task.setRequestStoreage(requestStoreage); + httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector"); httpResp = new MockHttpServletResponse(); RequestContextHolder.resetRequestAttributes(); diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java index 080731d9..dfd355de 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java @@ -7,6 +7,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import java.util.Collections; + import org.apache.commons.lang3.RandomStringUtils; import org.junit.Before; import org.junit.BeforeClass; @@ -23,14 +25,20 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import at.asitplus.eidas.specific.core.MsEidasNodeConstants; import at.asitplus.eidas.specific.core.test.config.dummy.MsConnectorDummyConfigMap; 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.tasks.ReceiveOtherLoginMethodGuiResponseTask; +import at.gv.egiz.eaaf.core.api.IRequest; +import at.gv.egiz.eaaf.core.api.IRequestStorage; +import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration; 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 lombok.SneakyThrows; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { @@ -44,6 +52,9 @@ public class ReceiveOtherLoginMethodGuiResponseTaskTest { @Autowired MsConnectorDummyConfigMap config; @Autowired + private IRequestStorage storage; + + @Autowired private ReceiveOtherLoginMethodGuiResponseTask task; private final ExecutionContextImpl executionContext = new ExecutionContextImpl(); @@ -70,22 +81,34 @@ public class ReceiveOtherLoginMethodGuiResponseTaskTest { RequestContextHolder.resetRequestAttributes(); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + ISpConfiguration spConfig = new DummySpConfiguration(Collections.emptyMap(), config); pendingReq = new TestRequestImpl(); pendingReq.setAuthUrl("https://localhost/ms_connector"); pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10)); - + + pendingReq.setSpConfig(spConfig); config.putConfigValue("auth.eIDAS.matching.byaddress.enable", "false"); LocaleContextHolder.resetLocaleContext(); } @Test + @SneakyThrows public void withStopMatchingSelection() throws TaskExecutionException { -httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, SelectedLoginMethod.STOP_MATCHING_PROCESS.name()); + httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, SelectedLoginMethod.STOP_MATCHING_PROCESS.name()); task.execute(pendingReq, executionContext); - assertTrue("stoppedByUser", pendingReq.isAbortedByUser()); + assertTrue("stoppedByUser", pendingReq.isAbortedByUser()); + assertNotNull("matchingstate", pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE)); + assertEquals("matchingState", MsEidasNodeConstants.MatchingStates.CANCELED_BY_USER, + pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE)); + + IRequest storedPendingReq = storage.getPendingRequest(pendingReq.getPendingRequestId()); + assertNotNull("pendingReq not stored", storedPendingReq); + assertNotNull("matchingstate storedReq", storedPendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE)); + assertEquals("matchingState storedReq", MsEidasNodeConstants.MatchingStates.CANCELED_BY_USER, + storedPendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE)); } |