aboutsummaryrefslogtreecommitdiff
path: root/modules/authmodule-eIDAS-v2/src/test/java/at
diff options
context:
space:
mode:
authorThomas <>2022-12-01 13:12:23 +0100
committerThomas <>2022-12-01 13:12:23 +0100
commit458c6f039654ba6ed3608f1523ba45f04f79bcd2 (patch)
treec18102383ec141e77f6a0963d60397fe52939b63 /modules/authmodule-eIDAS-v2/src/test/java/at
parent1923066ca9db0eacb8c1776b657705ef9b173448 (diff)
downloadNational_eIDAS_Gateway-458c6f039654ba6ed3608f1523ba45f04f79bcd2.tar.gz
National_eIDAS_Gateway-458c6f039654ba6ed3608f1523ba45f04f79bcd2.tar.bz2
National_eIDAS_Gateway-458c6f039654ba6ed3608f1523ba45f04f79bcd2.zip
feat(matching): disable UX option to create a new ERnP entry if it was prohibited by matching-process
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/test/java/at')
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java61
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveOtherLoginMethodGuiResponseTaskTest.java25
2 files changed, 77 insertions, 9 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java
index 6d08a731..037c76a1 100644
--- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java
+++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java
@@ -8,6 +8,7 @@ import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
+import java.util.Collections;
import java.util.Locale;
import org.apache.commons.lang3.RandomStringUtils;
@@ -32,9 +33,12 @@ import com.fasterxml.jackson.databind.json.JsonMapper;
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.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.GenerateOtherLoginMethodGuiTask;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.ReceiveOtherLoginMethodGuiResponseTask;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.test.dummy.DummyOA;
+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.data.EaafConstants;
import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
@@ -76,6 +80,7 @@ public class GenerateOtherLoginMethodGuiTaskTest {
* jUnit test set-up.
*/
@Before
+ @SneakyThrows
public void initialize() {
httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector");
httpResp = new MockHttpServletResponse();
@@ -91,6 +96,10 @@ public class GenerateOtherLoginMethodGuiTaskTest {
config.putConfigValue("auth.eIDAS.matching.byaddress.enable", "false");
+ MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq,
+ new RegisterStatusResults(new RegisterOperationStatus(null, true),
+ Collections.emptyList(), Collections.emptyList()));
+
LocaleContextHolder.resetLocaleContext();
}
@@ -125,11 +134,44 @@ public class GenerateOtherLoginMethodGuiTaskTest {
@Test
@SneakyThrows
- public void jsonResponseInsertErnp() throws TaskExecutionException, UnsupportedEncodingException {
- String reason = RandomStringUtils.randomAlphabetic(5);
+ public void jsonResponseInsertErnpScreen() throws TaskExecutionException, UnsupportedEncodingException {
+ executionContext.put(Constants.TRANSITION_TO_REQUESTING_NEW_ERNP_ENTRY_TASK, true);
+ httpReq.addHeader("Accept", "application/json");
+
+ task.execute(pendingReq, executionContext);
+
+ //result validation
+ Assert.assertEquals("httpStausCode", 200, httpResp.getStatus());
+ Assert.assertEquals("http ContentType", "application/json;charset=UTF-8", httpResp.getContentType());
+ final String content = httpResp.getContentAsString();
+ assertNotNull("response body is null", content);
+ Assert.assertFalse("response body is empty", content.isEmpty());
+ final JsonNode json = new JsonMapper().readTree(content);
+ assertNotNull("response body is null", json);
+ assertNull("advancedMatchFailed", json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED));
+ assertNotNull("createNewErnpEntryScreen", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION));
+ assertTrue("createNewErnpEntryScreen", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION).asBoolean());
+
+ assertNotNull("disallowNewErnpEntry", json.get(Constants.HTML_FORM_DISALLOW_CREATENEW_ERNP_ENTRY));
+ assertFalse("disallowNewErnpEntry", json.get(Constants.HTML_FORM_DISALLOW_CREATENEW_ERNP_ENTRY).asBoolean());
+
+ assertNull("advancedMatchingFailedReason", json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED_REASON));
+
+ assertNotNull("pendingRequest not stored",
+ storage.getPendingRequest(pendingReq.getPendingRequestId()));
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void jsonResponseInsertErnpScreenButNotAllowed() throws TaskExecutionException, UnsupportedEncodingException {
executionContext.put(Constants.TRANSITION_TO_REQUESTING_NEW_ERNP_ENTRY_TASK, true);
httpReq.addHeader("Accept", "application/json");
+ MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq,
+ new RegisterStatusResults(new RegisterOperationStatus(null, false),
+ Collections.emptyList(), Collections.emptyList()));
+
task.execute(pendingReq, executionContext);
//result validation
@@ -141,8 +183,11 @@ public class GenerateOtherLoginMethodGuiTaskTest {
final JsonNode json = new JsonMapper().readTree(content);
assertNotNull("response body is null", json);
assertNull("advancedMatchFailed", json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED));
- assertNotNull("createNewErnpEntry", json.get(Constants.HTML_FORM_CREATE_NEW_ERNP_ENTRY));
- assertTrue("createNewErnpEntry", json.get(Constants.HTML_FORM_CREATE_NEW_ERNP_ENTRY).asBoolean());
+ assertNotNull("createNewErnpEntryScreen", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION));
+ assertTrue("createNewErnpEntryScreen", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION).asBoolean());
+
+ assertNotNull("disallowNewErnpEntry", json.get(Constants.HTML_FORM_DISALLOW_CREATENEW_ERNP_ENTRY));
+ assertTrue("disallowNewErnpEntry", json.get(Constants.HTML_FORM_DISALLOW_CREATENEW_ERNP_ENTRY).asBoolean());
assertNull("advancedMatchingFailedReason", json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED_REASON));
@@ -175,11 +220,11 @@ public class GenerateOtherLoginMethodGuiTaskTest {
assertEquals("advancedMatchingFailedReason", reason,
json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED_REASON).asText());
- assertNotNull("createNewErnpEntry", json.get(Constants.HTML_FORM_CREATE_NEW_ERNP_ENTRY));
- assertFalse("createNewErnpEntry", json.get(Constants.HTML_FORM_CREATE_NEW_ERNP_ENTRY).asBoolean());
+ assertNotNull("createNewErnpEntryScreen", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION));
+ assertFalse("createNewErnpEntryScreen", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION).asBoolean());
- assertNotNull("enableMatchingByAddressSearch", json.get(Constants.HTML_FORM_CREATE_NEW_ERNP_ENTRY));
- assertFalse("enableMatchingByAddressSearch", json.get(Constants.HTML_FORM_CREATE_NEW_ERNP_ENTRY).asBoolean());
+ assertNotNull("enableMatchingByAddressSearch", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION));
+ assertFalse("enableMatchingByAddressSearch", json.get(Constants.HTML_FORM_WITH_CREATE_NEW_ERNP_ENTRY_OPTION).asBoolean());
assertNotNull("pendingRequest not stored",
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 dfd355de..db4f4fcb 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
@@ -29,7 +29,10 @@ 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.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.ReceiveOtherLoginMethodGuiResponseTask;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils;
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;
@@ -75,6 +78,7 @@ public class ReceiveOtherLoginMethodGuiResponseTaskTest {
* jUnit test set-up.
*/
@Before
+ @SneakyThrows
public void initialize() {
httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector");
httpResp = new MockHttpServletResponse();
@@ -89,6 +93,10 @@ public class ReceiveOtherLoginMethodGuiResponseTaskTest {
pendingReq.setSpConfig(spConfig);
config.putConfigValue("auth.eIDAS.matching.byaddress.enable", "false");
+ MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq,
+ new RegisterStatusResults(new RegisterOperationStatus(null, true),
+ Collections.emptyList(), Collections.emptyList()));
+
LocaleContextHolder.resetLocaleContext();
}
@@ -166,7 +174,22 @@ public class ReceiveOtherLoginMethodGuiResponseTaskTest {
}
-
+
+ @Test
+ @SneakyThrows
+ public void withAddMeAsNewSelectionButNotAllowed() throws TaskExecutionException {
+ MatchingTaskUtils.storeIntermediateMatchingResult(pendingReq,
+ new RegisterStatusResults(new RegisterOperationStatus(null, false),
+ Collections.emptyList(), Collections.emptyList()));
+ httpReq.setParameter(Constants.REQ_SELECTED_LOGIN_METHOD_PARAMETER, SelectedLoginMethod.ADD_ME_AS_NEW.name());
+
+ TaskExecutionException error = assertThrows("wrong exception", TaskExecutionException.class,
+ () -> task.execute(pendingReq, executionContext));
+ assertEquals("wrong errorCode", "module.eidasauth.matching.98",
+ ((EaafException) error.getOriginalException()).getErrorId());
+
+ }
+
@Test
public void withRequestingNewEntrySelection() throws TaskExecutionException {
testTransition(SelectedLoginMethod.REQUESTING_NEW_ENTRY, Constants.TRANSITION_TO_REQUESTING_NEW_ERNP_ENTRY_TASK);