aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java1
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java14
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java10
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java135
4 files changed, 121 insertions, 39 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java
index cdc17654..cc275f24 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/Constants.java
@@ -32,6 +32,7 @@ public class Constants {
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_FULL_EIDAS_RESPONSE = "resp_fulleIDASResponse";
+ public static final String DATA_RESULT_MATCHING_BPK = "matching-result-bpk";//TODO?
// templates for post-binding forwarding
public static final String TEMPLATE_POST_FORWARD_NAME = "eidas_node_forward.html";
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java
index 9509e7de..f557ca69 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/RegisterResult.java
@@ -23,6 +23,20 @@ import lombok.Data;
* @param givenName The givenName
* @param familyName The familyName
* @param dateOfBirth The dateOfBirth
+ */
+ public RegisterResult(String pseudonym, String givenName, String familyName, String dateOfBirth) {
+ this.pseudonym = pseudonym;
+ this.givenName = givenName;
+ this.familyName = familyName;
+ this.dateOfBirth = dateOfBirth;
+ }
+
+ /**
+ * Register search result.
+ * @param pseudonym The pseudonym
+ * @param givenName The givenName
+ * @param familyName The familyName
+ * @param dateOfBirth The dateOfBirth
* @param placeOfBirth The placeOfBirth
*/
public RegisterResult(String pseudonym, String givenName, String familyName, String dateOfBirth,
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java
index 3b573851..0b7ce030 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java
@@ -337,4 +337,14 @@ public class InitialSearchTask extends AbstractAuthServletTask {
return result;
}
+
+ //just for testing
+ //TODO is there a nicer solution?
+ public void setErnbClient(IErnbClient ernbClient) {
+ this.ernbClient = ernbClient;
+ }
+
+ public void setZmrClient(IZmrClient zmrClient) {
+ this.zmrClient = zmrClient;
+ }
}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java
index 30f88ec8..1b1bdeae 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java
@@ -1,10 +1,13 @@
package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;
-import at.asitplus.eidas.specific.connector.MsEidasNodeConstants;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
-import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernb.DummyErnbClient;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernb.IErnbClient;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.ManualFixNecessaryException;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.InitialSearchTask;
-import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.DummyZmrClient;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.IZmrClient;
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;
@@ -23,12 +26,10 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -38,30 +39,29 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
-
+import org.junit.Assert;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-
-import static org.mockito.Mockito.times;
-import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
+import java.util.ArrayList;
@RunWith(SpringJUnit4ClassRunner.class)
-//@RunWith(PowerMockRunner.class)
-//@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
+
@ContextConfiguration("/SpringTest-context_tasks_test.xml")
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
-//@RunWith(PowerMockRunner.class)
-//@PrepareForTest(InitialSearchTaskFirstTest.class)
public class InitialSearchTaskFirstTest {
@Autowired(required = true)
@Mock
+ @InjectMocks
private InitialSearchTask task;
- @Autowired(required = true)
- private IConfiguration basicConfig;
+ @Mock
+ private IZmrClient zmrClient;
+
+ @Mock
+ private IErnbClient ernbClient;
final ExecutionContext executionContext = new ExecutionContextImpl();
private MockHttpServletRequest httpReq;
@@ -71,7 +71,7 @@ public class InitialSearchTaskFirstTest {
/**
* jUnit class initializer.
- *
+ *
* @throws IOException In case of an error
*/
@BeforeClass
@@ -84,7 +84,6 @@ public class InitialSearchTaskFirstTest {
/**
* jUnit test set-up.
- *
*/
@Before
public void setUp() throws URISyntaxException, EaafStorageException {
@@ -96,41 +95,97 @@ public class InitialSearchTaskFirstTest {
RequestContextHolder.resetRequestAttributes();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
- final AuthenticationResponse response = buildDummyAuthResponse();
+ final AuthenticationResponse response = buildDummyAuthResponseMaxMustermann();
pendingReq = new TestRequestImpl();
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
}
-
+
@Test
@DirtiesContext
- public void testInitialSearch() throws Exception {
+ /**
+ * Two matches found in ZMR
+ */
+ public void testNode101a() throws Exception {
+
+ //Mock ZMR
+ ArrayList<RegisterResult> zmrResult = new ArrayList<>();
+ zmrResult.add(new RegisterResult("de/st/max123", "Max", "Mustermann", "1111-01-01"));
+ zmrResult.add(new RegisterResult("de/st/max123", "Maximilian", "Mustermann", "1111-01-01"));
+ zmrClient = Mockito.mock(DummyZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
+ task.setZmrClient(zmrClient);
+
+ //Mock ernb
+ ArrayList<RegisterResult> ernbResult = new ArrayList<>();
+ ernbClient = Mockito.mock(DummyErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
+ task.setErnbClient(ernbClient);
try {
task.execute(pendingReq, executionContext);
+ Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false);
+ String bPk = (String)
+ pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
} catch (final TaskExecutionException e) {
- // forward URL is not set in example config
- // org.springframework.util.Assert.isInstanceOf(EaafConfigurationException.class, e.getOriginalException(),
- // "Wrong exception");
- // Assert.assertEquals("wrong errorCode", "config.08", ((EaafException) e.getOriginalException())
- // .getErrorId());
- // Assert.assertEquals("wrong parameter size", 1, ((EaafException) e.getOriginalException())
- // .getParams().length);
- // Assert.assertEquals("wrong errorMsg", Constants.CONIG_PROPS_EIDAS_NODE_FORWARD_URL, ((EaafException) e
- // .getOriginalException()).getParams()[0]);
-
+ Throwable origE = e.getOriginalException();
+ Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
}
-// verifyPrivate(task, times(1)).invoke("step2", ArgumentMatchers.any(SimpleEidasData.class));
-// verifyPrivate(task, times(0)).invoke("step3", ArgumentMatchers.any());
-// verifyPrivate(task, times(0)).invoke("step4", ArgumentMatchers.any());
+ }
+
+
+ @Test
+ @DirtiesContext
+ /**
+ * Two matches found in ErnB
+ */
+ public void testNode101b() throws Exception {
+
+ //Mock ZMR
+ ArrayList<RegisterResult> zmrResult = new ArrayList<>();
+ zmrClient = Mockito.mock(DummyZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
+ task.setZmrClient(zmrClient);
+
+ //Mock ernb
+ ArrayList<RegisterResult> ernbResult = new ArrayList<>();
+ ernbResult.add(new RegisterResult("de/st/max123", "Max", "Mustermann", "1111-01-01"));
+ ernbResult.add(new RegisterResult("de/st/max123", "Maximilian", "Mustermann", "1111-01-01"));
+
+ ernbClient = Mockito.mock(DummyErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
+ task.setErnbClient(ernbClient);
+
+ try {
+ task.execute(pendingReq, executionContext);
+ Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false);
+ String bPk = (String)
+ pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
+ } catch (final TaskExecutionException e) {
+ Throwable origE = e.getOriginalException();
+ Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
+ }
}
@NotNull
private AuthenticationResponse buildDummyAuthResponse() throws URISyntaxException {
+ return buildDummyAuthResponse(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAlphabetic(10),
+ "de/st/" + RandomStringUtils.randomNumeric(64), "2001-01-01");
+ }
+
+ @NotNull
+ private AuthenticationResponse buildDummyAuthResponseMaxMustermann() throws URISyntaxException {
+ return buildDummyAuthResponse("Max", "Mustermann",
+ "de/st/max123", "1111-01-01");
+ }
+
+ @NotNull
+ private AuthenticationResponse buildDummyAuthResponse(String givenName, String familyName, String identifier,
+ String dateOfBirth) throws URISyntaxException {
final AttributeDefinition attributeDef = AttributeDefinition.builder()
.friendlyName(Constants.eIDAS_ATTR_PERSONALIDENTIFIER).nameUri(new URI("ad", "sd", "ff"))
.personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "af"))
@@ -149,12 +204,14 @@ public class InitialSearchTaskFirstTest {
.attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.DateTimeAttributeValueMarshaller").build();
final ImmutableAttributeMap attributeMap = ImmutableAttributeMap.builder()
- .put(attributeDef, "de/st/" + RandomStringUtils.randomNumeric(64))
- .put(attributeDef2, RandomStringUtils.randomAlphabetic(10))
- .put(attributeDef3, RandomStringUtils.randomAlphabetic(10)).put(attributeDef4, "2001-01-01").build();
+ .put(attributeDef, identifier)
+ .put(attributeDef2, familyName)
+ .put(attributeDef3, givenName)
+ .put(attributeDef4, dateOfBirth).build();
val b = new AuthenticationResponse.Builder();
- return b.id("aasdf").issuer("asd").subject("asf").statusCode("200").inResponseTo("asdf").subjectNameIdFormat("afaf")
+ return b.id("aasdf").issuer("asd").subject("asf").statusCode("200").inResponseTo("asdf").subjectNameIdFormat(
+ "afaf")
.attributes(attributeMap).build();
}
}