aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/test
diff options
context:
space:
mode:
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/ReceiveAustrianResidenceGuiResponseTaskTest.java127
1 files changed, 89 insertions, 38 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java
index 64bb0d48..15edce07 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java
@@ -1,14 +1,9 @@
package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;
-import static at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveAustrianResidenceGuiResponseTask.PARAM_CITY;
-import static at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveAustrianResidenceGuiResponseTask.PARAM_FORMER_RESIDENCE_AVAILABLE;
-import static at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveAustrianResidenceGuiResponseTask.PARAM_STREET;
-import static at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveAustrianResidenceGuiResponseTask.PARAM_ZIPCODE;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.eq;
-import static org.springframework.util.Assert.isInstanceOf;
import java.math.BigInteger;
import java.util.Arrays;
@@ -21,7 +16,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.i18n.LocaleContextHolder;
@@ -36,21 +30,22 @@ import com.google.common.collect.Lists;
import at.asitplus.eidas.specific.connector.test.config.dummy.MsConnectorDummyConfigMap;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.controller.AdresssucheController;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.controller.AdresssucheController.AdresssucheOutput;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.MatchedPersonResult;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData;
-import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.ManualFixNecessaryException;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterOperationStatus;
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.tasks.ReceiveAustrianResidenceGuiResponseTask.UserInput;
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.EaafStorageException;
-import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper;
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 = {
@@ -67,7 +62,7 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest {
private ReceiveAustrianResidenceGuiResponseTask task;
- private final ExecutionContext executionContext = new ExecutionContextImpl();
+ private ExecutionContext executionContext;
private MockHttpServletRequest httpReq;
private MockHttpServletResponse httpResp;
private TestRequestImpl pendingReq;
@@ -79,8 +74,9 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest {
*/
@Before
public void setUp() throws Exception {
+ executionContext = new ExecutionContextImpl();
task = new ReceiveAustrianResidenceGuiResponseTask(registerSearchService);
-
+
httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector");
httpResp = new MockHttpServletResponse();
RequestContextHolder.resetRequestAttributes();
@@ -94,8 +90,26 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest {
}
@Test
+ public void canceledByUser() throws Exception {
+ AdresssucheOutput userInput = setupUserInput();
+ SimpleEidasData eidasData = setupEidasData();
+ RegisterStatusResults registerSearchResult = buildEmptyResult();
+ mockRegisterSearch(userInput, registerSearchResult, eidasData);
+ MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, registerSearchResult);
+ httpReq.setParameter(ReceiveAustrianResidenceGuiResponseTask.HTTP_PARAM_NO_RESIDENCE, "true");
+
+ task.execute(pendingReq, executionContext);
+
+ assertEquals("Transition To S9", true, executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK));
+ assertEquals("matching failed flag", true, executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED));
+ assertEquals("failed reason", "module.eidasauth.matching.20", executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON));
+ assertNull("no final matching result", MatchingTaskUtils.getFinalMatchingResult(pendingReq));
+
+ }
+
+ @Test
public void noRegisterResult() throws Exception {
- UserInput userInput = setupUserInput();
+ AdresssucheOutput userInput = setupUserInput();
SimpleEidasData eidasData = setupEidasData();
RegisterStatusResults registerSearchResult = buildEmptyResult();
mockRegisterSearch(userInput, registerSearchResult, eidasData);
@@ -103,56 +117,86 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest {
task.execute(pendingReq, executionContext);
- assertEquals("Transition To S9", true, executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK));
+ assertEquals("Transition To S9", true, executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK));
+ assertEquals("matching failed flag", true, executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED));
+ assertEquals("failed reason", "module.eidasauth.matching.22", executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON));
+ assertNull("no final matching result", MatchingTaskUtils.getFinalMatchingResult(pendingReq));
+
}
@Test
- public void exactlyOneRegisterResult_Matching() throws Exception {
- UserInput userInput = setupUserInput();
+ public void exactlyOneRegisterResult_NoUpdate() throws Exception {
+ AdresssucheOutput userInput = setupUserInput();
SimpleEidasData eidasData = setupEidasData();
RegisterStatusResults registerSearchResult = buildResultWithOneMatch(buildMatchingRegisterResult(eidasData));
MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, registerSearchResult);
mockRegisterSearch(userInput, registerSearchResult, eidasData);
task.execute(pendingReq, executionContext);
-
+
+ // validate state
assertNull("Transition To S9", executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK));
- Mockito.verify(registerSearchService).step7aKittProcess(eq(registerSearchResult), eq(eidasData));
-
+ MatchedPersonResult matchingResult = MatchingTaskUtils.getFinalMatchingResult(pendingReq);
+ assertNotNull("no final matching result", matchingResult);
+ validateMatchedPerson(matchingResult, registerSearchResult);
+
}
@Test
- public void exactlyOneRegisterResult_NotMatching() throws Exception {
- UserInput userInput = setupUserInput();
+ public void exactlyOneRegisterResult_UpdateRequired() throws Exception {
+ AdresssucheOutput userInput = setupUserInput();
SimpleEidasData eidasData = setupEidasData();
RegisterStatusResults registerSearchResult = buildResultWithOneMatch(buildNotMatchingRegisterResult(eidasData));
+ RegisterStatusResults registerUpdateResult = buildResultWithOneMatch(buildRandomRegisterResult());
MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, registerSearchResult);
mockRegisterSearch(userInput, registerSearchResult, eidasData);
-
+ Mockito.when(registerSearchService.step7aKittProcess(eq(registerSearchResult), eq(eidasData)))
+ .thenReturn(registerUpdateResult);
+
+ // perform test
task.execute(pendingReq, executionContext);
- assertEquals("Transition To S9", true, executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK));
+ // validate state
+ assertNull("Transition To S9", executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK));
+
+ MatchedPersonResult matchingResult = MatchingTaskUtils.getFinalMatchingResult(pendingReq);
+ assertNotNull("no final matching result", matchingResult);
+ validateMatchedPerson(matchingResult, registerUpdateResult);
+
}
@Test
public void moreThanOneRegisterResult() throws Exception {
- UserInput userInput = setupUserInput();
+ AdresssucheOutput userInput = setupUserInput();
SimpleEidasData eidasData = setupEidasData();
RegisterStatusResults registerSearchResult = buildResultWithTwoMatches();
MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq, registerSearchResult);
mockRegisterSearch(userInput, registerSearchResult, eidasData);
- TaskExecutionException e = assertThrows(TaskExecutionException.class,
- () -> task.execute(pendingReq, executionContext));
+ task.execute(pendingReq, executionContext);
- assertEquals(pendingReq.getPendingRequestId(), e.getPendingRequestID());
- isInstanceOf(ManualFixNecessaryException.class, e.getOriginalException());
- assertNull("Transition To S16", executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK));
+ assertEquals("Transition To S9", true, executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK));
+ assertEquals("matching failed flag", true, executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED));
+ assertEquals("failed reason", "module.eidasauth.matching.22", executionContext.get(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON));
+ assertNull("no final matching result", MatchingTaskUtils.getFinalMatchingResult(pendingReq));
+
}
- private void mockRegisterSearch(UserInput userInput, RegisterStatusResults registerSearchResult, SimpleEidasData eidasData ) {
+ @SneakyThrows
+ private void validateMatchedPerson(MatchedPersonResult current,
+ RegisterStatusResults registerUpdateResult) {
+ RegisterResult expected = registerUpdateResult.getResult();
+ assertEquals("familyName", expected.getFamilyName(), current.getFamilyName());
+ assertEquals("givenName", expected.getGivenName(), current.getGivenName());
+ assertEquals("birthday", expected.getDateOfBirth(), current.getDateOfBirth());
+ assertEquals("bpk", expected.getBpk(), current.getBpk());
+
+ }
+
+ @SneakyThrows
+ private void mockRegisterSearch(AdresssucheOutput userInput, RegisterStatusResults registerSearchResult, SimpleEidasData eidasData ) {
Mockito.when(registerSearchService.searchWithResidence(eq(registerSearchResult.getOperationStatus()), eq(eidasData),
- eq(userInput.getZipcode()), eq(userInput.getCity()), eq(userInput.getStreet()))).thenReturn(registerSearchResult);
+ eq(userInput))).thenReturn(registerSearchResult);
}
@NotNull
@@ -216,11 +260,13 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest {
}
- private void setHttpParameters(UserInput input) {
- httpReq.setParameter(PARAM_FORMER_RESIDENCE_AVAILABLE, String.valueOf(input.isFormerResidenceAvailable()));
- httpReq.setParameter(PARAM_STREET, input.getStreet());
- httpReq.setParameter(PARAM_CITY, input.getCity());
- httpReq.setParameter(PARAM_ZIPCODE, input.getZipcode());
+ private void setHttpParameters(AdresssucheOutput input) {
+ httpReq.setParameter(AdresssucheController.PARAM_STREET, input.getStreet());
+ httpReq.setParameter(AdresssucheController.PARAM_MUNIPICALITY, input.getMunicipality());
+ httpReq.setParameter(AdresssucheController.PARAM_NUMBER, input.getNumber());
+ httpReq.setParameter(AdresssucheController.PARAM_VILLAGE, input.getVillage());
+ httpReq.setParameter(AdresssucheController.PARAM_POSTLEITZAHL, input.getPostleitzahl());
+
}
@NotNull
@@ -237,8 +283,13 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest {
}
@NotNull
- private UserInput setupUserInput() {
- UserInput result = new UserInput(true, RandomStringUtils.randomAlphabetic(8), RandomStringUtils.randomAlphabetic(8), RandomStringUtils.randomAlphabetic(8));
+ private AdresssucheOutput setupUserInput() {
+ AdresssucheOutput result = new AdresssucheOutput(
+ RandomStringUtils.randomAlphabetic(8),
+ RandomStringUtils.randomAlphabetic(8),
+ RandomStringUtils.randomAlphabetic(8),
+ RandomStringUtils.randomAlphabetic(8),
+ RandomStringUtils.randomAlphabetic(8));
setHttpParameters(result);
return result;
}