aboutsummaryrefslogtreecommitdiff
path: root/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java')
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java67
1 files changed, 59 insertions, 8 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 1751e95a..496158fa 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
@@ -1,6 +1,7 @@
package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -106,17 +107,47 @@ public class GenerateOtherLoginMethodGuiTaskTest {
ReceiveOtherLoginMethodGuiResponseTask.ALL_EXECUTIONCONTEXT_PARAMETERS.forEach(
el -> assertNull("executionContext parameter: " + el, executionContext.get(el)));
- // remove pendingRequestId because it's added by default
- executionContext.remove(EaafConstants.PROCESS_ENGINE_PENDINGREQUESTID);
-
+ // remove pendingRequestId and changeLanguage because it's added by default
+ executionContext.remove(EaafConstants.PROCESS_ENGINE_PENDINGREQUESTID);
+ executionContext.remove("changeLanguage");
+
// in case of 'ReceiveOtherLoginMethodGuiResponseTask.ALL_EXECUTIONCONTEXT_PARAMETERS' does not include all parameters
assertTrue("ExecutionContext is not empty", executionContext.keySet().isEmpty());
}
+
+ @Test
+ @SneakyThrows
+ public void jsonResponseInsertErnp() throws TaskExecutionException, UnsupportedEncodingException {
+ String reason = RandomStringUtils.randomAlphabetic(5);
+ 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("createNewErnpEntry", json.get(Constants.HTML_FORM_CREATE_NEW_ERNP_ENTRY));
+ assertTrue("createNewErnpEntry", json.get(Constants.HTML_FORM_CREATE_NEW_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 jsonResponse() throws TaskExecutionException, UnsupportedEncodingException {
+ public void jsonResponseMathingFailed() throws TaskExecutionException, UnsupportedEncodingException {
String reason = RandomStringUtils.randomAlphabetic(5);
executionContext.put(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED, true);
executionContext.put(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON, reason);
@@ -138,19 +169,41 @@ 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("pendingRequest not stored",
storage.getPendingRequest(pendingReq.getPendingRequestId()));
}
@Test
+ public void insertErnpRequested() throws TaskExecutionException, UnsupportedEncodingException {
+ executionContext.put(Constants.TRANSITION_TO_REQUESTING_NEW_ERNP_ENTRY_TASK, true);
+
+ task.execute(pendingReq, executionContext);
+
+ Assert.assertEquals("Wrong http StatusCode", 200, httpResp.getStatus());
+ Assert.assertEquals("Wrong http ContentType", "text/html;charset=UTF-8", httpResp.getContentType());
+
+ String html = httpResp.getContentAsString();
+ Assert.assertNotNull("html result is null", html);
+ Assert.assertFalse("html result is empty", html.isEmpty());
+ Assert.assertTrue("No language selector with pendingRequestId",
+ html.contains("/otherLoginMethod?lang=en&pendingid=" + pendingReq.getPendingRequestId()));
+ Assert.assertTrue("Missing eIDAS infos",
+ html.contains(MessageFormat.format(TEST_PATTER_REQ_PARAM, SelectedLoginMethod.ADD_ME_AS_NEW)));
+
+ }
+
+ @Test
public void advancedMatchingFailedMsg() throws TaskExecutionException, UnsupportedEncodingException {
executionContext.put(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED, true);
task.execute(pendingReq, executionContext);
String html = doBasicValidation();
- Assert.assertTrue("Missing eIDAS infos",
+ Assert.assertFalse("Missing eIDAS infos",
html.contains(MessageFormat.format(TEST_PATTER_REQ_PARAM, SelectedLoginMethod.ADD_ME_AS_NEW)));
Assert.assertTrue("missing errorfield",
html.contains("<div id=\"matchingError\""));
@@ -166,8 +219,6 @@ public class GenerateOtherLoginMethodGuiTaskTest {
task.execute(pendingReq, executionContext);
String html = doBasicValidation();
- Assert.assertTrue("Missing eIDAS infos",
- html.contains(MessageFormat.format(TEST_PATTER_REQ_PARAM, SelectedLoginMethod.ADD_ME_AS_NEW)));
Assert.assertTrue("missing errorfield",
html.contains("<div id=\"matchingError\""));
Assert.assertTrue("missing errorfield",
@@ -232,7 +283,7 @@ public class GenerateOtherLoginMethodGuiTaskTest {
html.contains(MessageFormat.format(TEST_PATTER_REQ_PARAM, SelectedLoginMethod.EIDAS_LOGIN)));
Assert.assertTrue("No language selector with pendingRequestId",
- html.contains("/otherLoginMethod?pendingid=" + pendingReq.getPendingRequestId()));
+ html.contains("/otherLoginMethod?lang=en&amp;pendingid=" + pendingReq.getPendingRequestId()));
Assert.assertTrue("No country-selection form",
html.contains("<form method=\"post\" action=\"/otherLoginMethod\">"));