aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java337
1 files changed, 242 insertions, 95 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
index 175f95e6..e3757c0d 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
@@ -4,7 +4,7 @@ import static at.asitplus.eidas.specific.connector.MsEidasNodeConstants.PROP_CON
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.powermock.api.mockito.PowerMockito.when;
+import static org.mockito.Mockito.when;
import java.net.URISyntaxException;
import java.security.KeyStore;
@@ -18,7 +18,9 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
+import org.joda.time.DateTime;
import org.jose4j.jwa.AlgorithmConstraints;
import org.jose4j.jwa.AlgorithmConstraints.ConstraintType;
import org.jose4j.jws.AlgorithmIdentifiers;
@@ -28,7 +30,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -41,15 +42,24 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.skjolber.mockito.soap.SoapServiceRule;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import at.asitplus.eidas.specific.connector.MsEidasNodeConstants;
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.dao.MatchedPersonResult;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPostProcessingException;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasAttributeException;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.SzrCommunicationException;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.EidasAttributeRegistry;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.ICcSpecificEidProcessingService;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.CreateIdentityLinkTask;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.JoseUtils;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.JoseUtils.JwsResult;
+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.data.EaafConfigConstants;
@@ -69,8 +79,10 @@ import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
import at.gv.egiz.eaaf.core.impl.utils.Random;
import eu.eidas.auth.commons.attribute.AttributeDefinition;
+import eu.eidas.auth.commons.attribute.AttributeValue;
import eu.eidas.auth.commons.attribute.ImmutableAttributeMap;
import eu.eidas.auth.commons.attribute.ImmutableAttributeMap.Builder;
+import eu.eidas.auth.commons.protocol.eidas.impl.PostalAddress;
import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse;
import lombok.val;
import szrservices.JwsHeaderParam;
@@ -80,7 +92,6 @@ import szrservices.SignContentEntry;
import szrservices.SignContentResponseType;
@RunWith(SpringJUnit4ClassRunner.class)
-@PrepareForTest(CreateIdentityLinkTask.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ContextConfiguration(locations = {
"/SpringTest-context_tasks_test.xml",
@@ -99,6 +110,9 @@ public class CreateIdentityLinkTaskEidNewTest {
EaafKeyStoreFactory keyStoreFactory;
@Autowired
+ ICcSpecificEidProcessingService eidPostProcessor;
+
+ @Autowired
private IRequestStorage requestStorage;
final ExecutionContext executionContext = new ExecutionContextImpl();
@@ -117,25 +131,27 @@ public class CreateIdentityLinkTaskEidNewTest {
AlgorithmIdentifiers.RSA_PSS_USING_SHA512));
private static ObjectMapper mapper = new ObjectMapper();
-
+
private AuthenticationResponse response;
-
+
@Rule
public final SoapServiceRule soap = SoapServiceRule.newInstance();
/**
* jUnit test set-up.
+ * @throws EidasAttributeException
+ * @throws EidPostProcessingException
*/
@Before
- public void setUp() throws EaafStorageException, URISyntaxException {
+ public void setUp() throws EaafStorageException, URISyntaxException, EidPostProcessingException, EidasAttributeException {
httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler");
httpResp = new MockHttpServletResponse();
RequestContextHolder.resetRequestAttributes();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
-
+
basicConfig.putConfigValue("eidas.ms.auth.eIDAS.szrclient.debug.useDummySolution", "false");
-
+
final Map<String, String> spConfig = new HashMap<>();
spConfig.put(EaafConfigConstants.SERVICE_UNIQUEIDENTIFIER, "testSp");
spConfig.put("target", "urn:publicid:gv.at:cdid+XX");
@@ -146,14 +162,20 @@ public class CreateIdentityLinkTaskEidNewTest {
response = buildDummyAuthResponse(false);
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
-
+
+ final Map<String, Object> eidasAttributes = convertEidasAttrToSimpleMap(
+ response.getAttributes().getAttributeMap());
+ final SimpleEidasData eidData = eidPostProcessor.postProcess(eidasAttributes);
+ MatchingTaskUtils.storeInitialEidasData(pendingReq, eidData);
+
+ MatchingTaskUtils.storeFinalMatchingResult(pendingReq, null);
pendingReq.setSpConfig(oaParam);
pendingReq.setPendingReqId(at.gv.egiz.eaaf.core.impl.utils.Random.nextProcessReferenceValue());
pendingReq.setAuthUrl("http://test.com/");
pendingReq.setTransactionId("avaasbav");
pendingReq.setPiiTransactionId(RandomStringUtils.randomAlphanumeric(10));
-
+
executionContext.put(MsEidasNodeConstants.REQ_PARAM_SELECTED_COUNTRY, "XX");
executionContext.put(EaafConstants.PROCESS_ENGINE_REQUIRES_NO_POSTAUTH_REDIRECT, true);
@@ -165,27 +187,29 @@ public class CreateIdentityLinkTaskEidNewTest {
//initialize test
response = buildDummyAuthResponse(true);
pendingReq.getSessionData(AuthProcessDataWrapper.class)
- .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
+ .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
+ MatchingTaskUtils.storeInitialEidasData(pendingReq, eidPostProcessor.postProcess(
+ convertEidasAttrToSimpleMap(response.getAttributes().getAttributeMap())));
String vsz = RandomStringUtils.randomNumeric(10);
- when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(vsz);
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(vsz);
val signContentResp = new SignContentResponseType();
final SignContentEntry signContentEntry = new SignContentEntry();
signContentEntry.setValue(RandomStringUtils.randomAlphanumeric(10));
signContentResp.getOut().add(signContentEntry);
- when(szrMock, "signContent", any(), any(), any()).thenReturn(signContentResp);
+ when(szrMock.signContent(any(), any(), any())).thenReturn(signContentResp);
String randomTestSp = RandomStringUtils.randomAlphabetic(10);
pendingReq.setRawDataToTransaction(MsEidasNodeConstants.DATA_REQUESTERID, randomTestSp);
-
+
//perform test
task.execute(pendingReq, executionContext);
- //validate state
+ //validate state
// check if pendingRequest was stored
IRequest storedPendingReq = requestStorage.getPendingRequest(pendingReq.getPendingRequestId());
Assert.assertNotNull("pendingReq not stored", storedPendingReq);
-
+
//check data in session
final AuthProcessDataWrapper authProcessData = storedPendingReq.getSessionData(AuthProcessDataWrapper.class);
Assert.assertNotNull("AuthProcessData", authProcessData);
@@ -193,16 +217,12 @@ public class CreateIdentityLinkTaskEidNewTest {
String authBlock = authProcessData.getGenericDataFromSession(Constants.SZR_AUTHBLOCK, String.class);
Assert.assertNotNull("AuthBlock", authBlock);
-
+
Assert.assertTrue("EID process", authProcessData.isEidProcess());
Assert.assertTrue("foreigner process", authProcessData.isForeigner());
- Assert.assertEquals("EID-ISSUING_NATION", "LU",
+ Assert.assertEquals("EID-ISSUING_NATION", "LU",
authProcessData.getGenericDataFromSession(PvpAttributeDefinitions.EID_ISSUING_NATION_NAME, String.class));
- Assert.assertNotNull("LoA is null", authProcessData.getQaaLevel());
- Assert.assertEquals("LoA", response.getLevelOfAssurance(),
- authProcessData.getQaaLevel());
-
-
+
// check authblock signature
final AlgorithmConstraints constraints = new AlgorithmConstraints(ConstraintType.PERMIT,
BINDING_AUTH_ALGORITHM_WHITELIST_SIGNING.toArray(new String[BINDING_AUTH_ALGORITHM_WHITELIST_SIGNING.size()]));
@@ -210,60 +230,61 @@ public class CreateIdentityLinkTaskEidNewTest {
X509Certificate[] trustedCerts = EaafKeyStoreUtils
.getPrivateKeyAndCertificates(keyStore.getFirst(), ALIAS, PW.toCharArray(), true, "junit").getSecond();
JwsResult result = JoseUtils.validateSignature(authBlock, Arrays.asList(trustedCerts), constraints);
- Assert.assertTrue("AuthBlock not valid", result.isValid());
- JsonNode authBlockJson = mapper.readTree(result.getPayLoad());
+ Assert.assertTrue("AuthBlock not valid", result.isValid());
+ JsonNode authBlockJson = mapper.readTree(result.getPayLoad());
Assert.assertNotNull("deserialized AuthBlock", authBlockJson);
-
- Assert.assertNotNull("no piiTransactionId in pendingRequesdt",
+
+ Assert.assertNotNull("no piiTransactionId in pendingRequesdt",
storedPendingReq.getUniquePiiTransactionIdentifier());
- Assert.assertEquals("piiTransactionId", storedPendingReq.getUniquePiiTransactionIdentifier(),
+ Assert.assertEquals("piiTransactionId", storedPendingReq.getUniquePiiTransactionIdentifier(),
authBlockJson.get("piiTransactionId").asText());
- Assert.assertEquals("appId", randomTestSp, authBlockJson.get("appId").asText());
+ Assert.assertEquals("appId", randomTestSp, authBlockJson.get("appId").asText());
Assert.assertFalse("'challenge' is null", authBlockJson.get("challenge").asText().isEmpty());
Assert.assertFalse("'timestamp' is null", authBlockJson.get("timestamp").asText().isEmpty());
Assert.assertFalse("binding pubKey", authBlockJson.has("bindingPublicKey"));
+
// check vsz request
ArgumentCaptor<PersonInfoType> argument4 = ArgumentCaptor.forClass(PersonInfoType.class);
- ArgumentCaptor<Boolean> argument5 = ArgumentCaptor.forClass(Boolean.class);
+ ArgumentCaptor<Boolean> argument5 = ArgumentCaptor.forClass(Boolean.class);
verify(szrMock, times(1)).getStammzahlEncrypted(argument4.capture(), argument5.capture());
-
+
Boolean param5 = argument5.getValue();
- Assert.assertTrue("insertERnP flag", param5);
+ Assert.assertTrue("insertERnP flag", param5);
PersonInfoType person = argument4.getValue();
- Assert.assertEquals("FamilyName",
+ Assert.assertEquals("FamilyName",
response.getAttributes().getAttributeValuesByFriendlyName("FamilyName").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("FamilyName").iterator().next()),
+ response.getAttributes().getDefinitionsByFriendlyName("FamilyName").iterator().next()),
person.getPerson().getName().getFamilyName());
- Assert.assertEquals("GivenName",
+ Assert.assertEquals("GivenName",
response.getAttributes().getAttributeValuesByFriendlyName("FirstName").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("FirstName").iterator().next()),
+ response.getAttributes().getDefinitionsByFriendlyName("FirstName").iterator().next()),
person.getPerson().getName().getGivenName());
- Assert.assertEquals("DateOfBirth",
+ Assert.assertEquals("DateOfBirth",
response.getAttributes().getAttributeValuesByFriendlyName("DateOfBirth").getFirstValue(
response.getAttributes().getDefinitionsByFriendlyName("DateOfBirth").iterator().next())
- .toString().split("T")[0],
+ .toString().split("T")[0],
person.getPerson().getDateOfBirth());
-
- Assert.assertEquals("PlaceOfBirth",
+
+ Assert.assertEquals("PlaceOfBirth",
response.getAttributes().getAttributeValuesByFriendlyName("PlaceOfBirth").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("PlaceOfBirth").iterator().next()),
- person.getPerson().getPlaceOfBirth());
- Assert.assertEquals("BirthName",
+ response.getAttributes().getDefinitionsByFriendlyName("PlaceOfBirth").iterator().next()),
+ person.getPerson().getPlaceOfBirth());
+ Assert.assertEquals("BirthName",
response.getAttributes().getAttributeValuesByFriendlyName("BirthName").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("BirthName").iterator().next()),
+ response.getAttributes().getDefinitionsByFriendlyName("BirthName").iterator().next()),
person.getPerson().getAlternativeName().getFamilyName());
-
+
Assert.assertEquals("CitizenCountry", "LU", person.getTravelDocument().getIssuingCountry());
Assert.assertEquals("DocumentType", "ELEKTR_DOKUMENT", person.getTravelDocument().getDocumentType());
-
- Assert.assertEquals("Identifier",
+
+ Assert.assertEquals("Identifier",
response.getAttributes().getAttributeValuesByFriendlyName("PersonIdentifier").getFirstValue(
response.getAttributes().getDefinitionsByFriendlyName("PersonIdentifier").iterator().next())
- .toString().split("/")[2],
+ .toString().split("/")[2],
person.getTravelDocument().getDocumentNumber());
-
+
// check bcBind singing request
ArgumentCaptor<Boolean> argument1 = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<List<JwsHeaderParam>> argument2 = ArgumentCaptor.forClass(List.class);
@@ -271,62 +292,76 @@ public class CreateIdentityLinkTaskEidNewTest {
verify(szrMock, times(1)).signContent(argument1.capture(), argument2.capture(), argument3.capture());
Boolean param1 = argument1.getValue();
Assert.assertFalse("addCert flag", param1);
-
+
List<JwsHeaderParam> param2 = argument2.getValue();
- Assert.assertNotNull("JWS Headers", param2);
+ Assert.assertNotNull("JWS Headers", param2);
Assert.assertFalse("JWS Headers empty", param2.isEmpty());
Assert.assertEquals("Wrong JWS header size", 1, param2.size());
Assert.assertEquals("Missing JWS header key", "urn:at.gv.eid:bindtype", param2.get(0).getKey());
Assert.assertEquals("Missing JWS header value", "urn:at.gv.eid:eidasBind", param2.get(0).getValue());
-
+
List<SignContentEntry> param3 = argument3.getValue();
Assert.assertNotNull("sign Payload", param3);
- Assert.assertEquals("wrong sign-payload size", 1, param3.size());
- Assert.assertNotNull("payload", param3.get(0).getValue().getBytes());
+ Assert.assertEquals("wrong sign-payload size", 1, param3.size());
+ Assert.assertNotNull("payload", param3.get(0).getValue().getBytes());
JsonNode bcBind = mapper.readTree(param3.get(0).getValue().getBytes());
Assert.assertNotNull("bcbind req", bcBind);
-
+
Assert.assertEquals("vsz", vsz, bcBind.get("urn:eidgvat:attributes.vsz.value").asText());
- Assert.assertEquals("eid status", "urn:eidgvat:eid.status.eidas",
+ Assert.assertEquals("eid status", "urn:eidgvat:eid.status.eidas",
bcBind.get("urn:eidgvat:attributes.eid.status").asText());
Assert.assertTrue("pubKeys", bcBind.has("urn:eidgvat:attributes.user.pubkeys"));
- Assert.assertTrue("pubKeys", bcBind.get("urn:eidgvat:attributes.user.pubkeys").isArray());
+ Assert.assertTrue("pubKeys", bcBind.get("urn:eidgvat:attributes.user.pubkeys").isArray());
Iterator<JsonNode> pubKeys = bcBind.get("urn:eidgvat:attributes.user.pubkeys").elements();
Assert.assertTrue("No PubKey", pubKeys.hasNext());
- Assert.assertEquals("Wrong pubKey",
+ Assert.assertEquals("Wrong pubKey",
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmxcB5jnrAwGn7xjgVFv1UBUv1pluwDRFQx7x5O6rSn7pblYfwaWeKa8y"
+ "jS5BDDaZ00mhhnSlm2XByNrkg5yBGetTgBGtQVAxV5apfuAWN8TS3uSXgdZol7Khd6kraUITtnulvLe8tNaboom5P0zN6UxbJN"
+ "NVLishVp80HiRXiDbplCTUk8b5cYtmivdb0+5JBTa7L5N/anRVnHHoJCXgNPTouO8daUHZbG1mPk0HgqD8rhZ+OBzE+APKH9No"
- + "agedSrGRDLdIgZxkrg0mxmfsZQIi2wdJSi3y0PAjEps/s4j0nmw9bPRgCMNLBqqjxtN5JKC8E1yyLm7YefXv/nPaMwIDAQAB",
+ + "agedSrGRDLdIgZxkrg0mxmfsZQIi2wdJSi3y0PAjEps/s4j0nmw9bPRgCMNLBqqjxtN5JKC8E1yyLm7YefXv/nPaMwIDAQAB",
pubKeys.next().asText());
Assert.assertFalse("More than one PubKey", pubKeys.hasNext());
-
+
}
@Test
- public void successfulProcessWithStandardInfos() throws Exception {
- //initialize test
+ public void successfulProcessWithDataFromMatching() throws Exception {
+ //initialize test
String vsz = RandomStringUtils.randomNumeric(10);
- when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(vsz);
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(vsz);
val signContentResp = new SignContentResponseType();
final SignContentEntry signContentEntry = new SignContentEntry();
signContentEntry.setValue(RandomStringUtils.randomAlphanumeric(10));
signContentResp.getOut().add(signContentEntry);
- when(szrMock, "signContent", any(), any(), any()).thenReturn(signContentResp);
-
+
+ when(szrMock.signContent(any(), any(), any())).thenReturn(signContentResp);
+
+
String randomTestSp = RandomStringUtils.randomAlphabetic(10);
String bindingPubKey = RandomStringUtils.randomAlphabetic(10);
pendingReq.setRawDataToTransaction(MsEidasNodeConstants.DATA_REQUESTERID, randomTestSp);
+
+ MatchedPersonResult matchingInfos = MatchedPersonResult.builder()
+ .bpk(RandomStringUtils.randomAlphabetic(5))
+ .givenName(RandomStringUtils.randomAlphabetic(5))
+ .familyName(RandomStringUtils.randomAlphabetic(5))
+ .dateOfBirth(RandomStringUtils.randomAlphabetic(5))
+ .countryCode(RandomStringUtils.randomAlphabetic(2).toUpperCase())
+ .build();
+ MatchingTaskUtils.storeFinalMatchingResult(pendingReq, matchingInfos);
+
pendingReq.setRawDataToTransaction(MsEidasNodeConstants.EID_BINDING_PUBLIC_KEY_NAME, bindingPubKey);
+
//perform test
task.execute(pendingReq, executionContext);
-
- //validate state
+
+
+ //validate state
// check if pendingRequest was stored
IRequest storedPendingReq = requestStorage.getPendingRequest(pendingReq.getPendingRequestId());
Assert.assertNotNull("pendingReq not stored", storedPendingReq);
-
+
//check data in session
final AuthProcessDataWrapper authProcessData = storedPendingReq.getSessionData(AuthProcessDataWrapper.class);
Assert.assertNotNull("AuthProcessData", authProcessData);
@@ -335,6 +370,7 @@ public class CreateIdentityLinkTaskEidNewTest {
// check authblock signature
String authBlock = authProcessData.getGenericDataFromSession(Constants.SZR_AUTHBLOCK, String.class);
Assert.assertNotNull("AuthBlock", authBlock);
+
final AlgorithmConstraints constraints = new AlgorithmConstraints(ConstraintType.PERMIT,
BINDING_AUTH_ALGORITHM_WHITELIST_SIGNING.toArray(new String[BINDING_AUTH_ALGORITHM_WHITELIST_SIGNING.size()]));
Pair<KeyStore, Provider> keyStore = getKeyStore();
@@ -357,53 +393,115 @@ public class CreateIdentityLinkTaskEidNewTest {
Assert.assertTrue("EID process", authProcessData.isEidProcess());
Assert.assertTrue("foreigner process", authProcessData.isForeigner());
- Assert.assertEquals("EID-ISSUING_NATION", "LU",
+ Assert.assertEquals("EID-ISSUING_NATION", "LU",
authProcessData.getGenericDataFromSession(PvpAttributeDefinitions.EID_ISSUING_NATION_NAME, String.class));
- Assert.assertNotNull("LoA is null", authProcessData.getQaaLevel());
- Assert.assertEquals("LoA", response.getLevelOfAssurance(),
- authProcessData.getQaaLevel());
-
+
// check vsz request
ArgumentCaptor<PersonInfoType> argument4 = ArgumentCaptor.forClass(PersonInfoType.class);
- ArgumentCaptor<Boolean> argument5 = ArgumentCaptor.forClass(Boolean.class);
+ ArgumentCaptor<Boolean> argument5 = ArgumentCaptor.forClass(Boolean.class);
verify(szrMock, times(1)).getStammzahlEncrypted(argument4.capture(), argument5.capture());
+
+ Boolean param5 = argument5.getValue();
+ Assert.assertFalse("insertERnP flag", param5);
+ PersonInfoType person = argument4.getValue();
+ Assert.assertEquals("FamilyName",
+ matchingInfos.getFamilyName(),
+ person.getPerson().getName().getFamilyName());
+ Assert.assertEquals("GivenName",
+ matchingInfos.getGivenName(),
+ person.getPerson().getName().getGivenName());
+ Assert.assertEquals("DateOfBirth",
+ matchingInfos.getDateOfBirth(),
+ person.getPerson().getDateOfBirth());
+ Assert.assertEquals("bPK",
+ matchingInfos.getBpk(),
+ person.getPerson().getIdentification().getValue());
+ Assert.assertEquals("bPKType",
+ EaafConstants.URN_PREFIX_CDID + "ZP",
+ person.getPerson().getIdentification().getType());
+
+ Assert.assertNull("PlaceOfBirth", person.getPerson().getPlaceOfBirth());
+ Assert.assertNull("BirthName", person.getPerson().getAlternativeName());
+
+ }
+
+ @Test
+ public void successfulProcessWithStandardInfos() throws Exception {
+ //initialize test
+ String vsz = RandomStringUtils.randomNumeric(10);
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(vsz);
+ val signContentResp = new SignContentResponseType();
+ final SignContentEntry signContentEntry = new SignContentEntry();
+ signContentEntry.setValue(RandomStringUtils.randomAlphanumeric(10));
+ signContentResp.getOut().add(signContentEntry);
+ when(szrMock.signContent(any(), any(), any())).thenReturn(signContentResp);
+
+ String randomTestSp = RandomStringUtils.randomAlphabetic(10);
+ pendingReq.setRawDataToTransaction(MsEidasNodeConstants.DATA_REQUESTERID, randomTestSp);
+
+ //perform test
+ task.execute(pendingReq, executionContext);
+
+ //validate state
+ // check if pendingRequest was stored
+ IRequest storedPendingReq = requestStorage.getPendingRequest(pendingReq.getPendingRequestId());
+ Assert.assertNotNull("pendingReq not stored", storedPendingReq);
+
+ //check data in session
+ final AuthProcessDataWrapper authProcessData = storedPendingReq.getSessionData(AuthProcessDataWrapper.class);
+ Assert.assertNotNull("AuthProcessData", authProcessData);
+ Assert.assertNotNull("eidasBind", authProcessData.getGenericDataFromSession(Constants.EIDAS_BIND, String.class));
+
+ String authBlock = authProcessData.getGenericDataFromSession(Constants.SZR_AUTHBLOCK, String.class);
+ Assert.assertNotNull("AuthBlock", authBlock);
+
+ Assert.assertTrue("EID process", authProcessData.isEidProcess());
+ Assert.assertTrue("foreigner process", authProcessData.isForeigner());
+ Assert.assertEquals("EID-ISSUING_NATION", "LU",
+ authProcessData.getGenericDataFromSession(PvpAttributeDefinitions.EID_ISSUING_NATION_NAME, String.class));
+
+ // check vsz request
+ ArgumentCaptor<PersonInfoType> argument4 = ArgumentCaptor.forClass(PersonInfoType.class);
+ ArgumentCaptor<Boolean> argument5 = ArgumentCaptor.forClass(Boolean.class);
+ verify(szrMock, times(1)).getStammzahlEncrypted(argument4.capture(), argument5.capture());
+
Boolean param5 = argument5.getValue();
- Assert.assertTrue("insertERnP flag", param5);
+ Assert.assertTrue("insertERnP flag", param5);
PersonInfoType person = argument4.getValue();
- Assert.assertEquals("FamilyName",
+ Assert.assertEquals("FamilyName",
response.getAttributes().getAttributeValuesByFriendlyName("FamilyName").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("FamilyName").iterator().next()),
+ response.getAttributes().getDefinitionsByFriendlyName("FamilyName").iterator().next()),
person.getPerson().getName().getFamilyName());
- Assert.assertEquals("GivenName",
+ Assert.assertEquals("GivenName",
response.getAttributes().getAttributeValuesByFriendlyName("FirstName").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("FirstName").iterator().next()),
+ response.getAttributes().getDefinitionsByFriendlyName("FirstName").iterator().next()),
person.getPerson().getName().getGivenName());
- Assert.assertEquals("DateOfBirth",
+ Assert.assertEquals("DateOfBirth",
response.getAttributes().getAttributeValuesByFriendlyName("DateOfBirth").getFirstValue(
response.getAttributes().getDefinitionsByFriendlyName("DateOfBirth").iterator().next())
- .toString().split("T")[0],
+ .toString().split("T")[0],
person.getPerson().getDateOfBirth());
-
- Assert.assertNull("PlaceOfBirth", person.getPerson().getPlaceOfBirth());
+
+ Assert.assertNull("PlaceOfBirth", person.getPerson().getPlaceOfBirth());
Assert.assertNull("BirthName", person.getPerson().getAlternativeName());
-
+
Assert.assertEquals("CitizenCountry", "LU", person.getTravelDocument().getIssuingCountry());
Assert.assertEquals("DocumentType", "ELEKTR_DOKUMENT", person.getTravelDocument().getDocumentType());
-
- Assert.assertEquals("Identifier",
+
+ Assert.assertEquals("Identifier",
response.getAttributes().getAttributeValuesByFriendlyName("PersonIdentifier").getFirstValue(
response.getAttributes().getDefinitionsByFriendlyName("PersonIdentifier").iterator().next())
- .toString().split("/")[2],
+ .toString().split("/")[2],
person.getTravelDocument().getDocumentNumber());
-
-
+
+
}
-
+
@Test
public void getStammzahlEncryptedExceptionTest() throws Exception {
try {
- when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(null);
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(null);
task.execute(pendingReq, executionContext);
} catch (TaskExecutionException e) {
Assert.assertEquals("Incorrect exception thrown", e.getMessage(),
@@ -417,8 +515,8 @@ public class CreateIdentityLinkTaskEidNewTest {
@Test
public void signContentExceptionTest() throws Exception {
try {
- when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(RandomStringUtils.randomNumeric(10));
- when(szrMock, "signContent", any(), any(), any()).thenReturn(null);
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(RandomStringUtils.randomNumeric(10));
+ when(szrMock.signContent(any(), any(), any())).thenReturn(null);
task.execute(pendingReq, executionContext);
} catch (TaskExecutionException e) {
Assert.assertEquals("Incorrect exception thrown", e.getMessage(),
@@ -465,7 +563,7 @@ public class CreateIdentityLinkTaskEidNewTest {
Constants.eIDAS_ATTR_PLACEOFBIRTH).first();
final AttributeDefinition attributeDef6 = attrRegistry.getCoreAttributeRegistry().getByFriendlyName(
Constants.eIDAS_ATTR_BIRTHNAME).first();
-
+
final Builder attributeMap = ImmutableAttributeMap.builder();
attributeMap.put(attributeDef, "LU/AT/" + RandomStringUtils.randomNumeric(64));
attributeMap.put(attributeDef2, RandomStringUtils.randomAlphabetic(10));
@@ -474,7 +572,7 @@ public class CreateIdentityLinkTaskEidNewTest {
if (withAll) {
attributeMap.put(attributeDef5, RandomStringUtils.randomAlphabetic(10));
attributeMap.put(attributeDef6, RandomStringUtils.randomAlphabetic(10));
-
+
}
val b = new AuthenticationResponse.Builder();
@@ -488,4 +586,53 @@ public class CreateIdentityLinkTaskEidNewTest {
.attributes(attributeMap.build())
.build();
}
+
+ private Map<String, Object> convertEidasAttrToSimpleMap(
+ ImmutableMap<AttributeDefinition<?>, ImmutableSet<? extends AttributeValue<?>>> attributeMap) {
+ final Map<String, Object> result = new HashMap<>();
+ for (final AttributeDefinition<?> el : attributeMap.keySet()) {
+ final Class<?> parameterizedType = el.getParameterizedType();
+ if (DateTime.class.equals(parameterizedType)) {
+ convertDateTime(attributeMap, result, el);
+ } else if (PostalAddress.class.equals(parameterizedType)) {
+ convertPostalAddress(attributeMap, result, el);
+ } else {
+ convertString(attributeMap, result, el);
+ }
+ }
+ return result;
+ }
+
+ private void convertString(ImmutableMap<AttributeDefinition<?>,
+ ImmutableSet<? extends AttributeValue<?>>> attributeMap,
+ Map<String, Object> result, AttributeDefinition<?> el) {
+ final List<String> natPersonIdObj = EidasResponseUtils
+ .translateStringListAttribute(el, attributeMap.get(el));
+ final String stringAttr = natPersonIdObj.get(0);
+ if (StringUtils.isNotEmpty(stringAttr)) {
+ result.put(el.getFriendlyName(), stringAttr);
+
+ }
+ }
+
+ private void convertPostalAddress(ImmutableMap<AttributeDefinition<?>,
+ ImmutableSet<? extends AttributeValue<?>>> attributeMap,
+ Map<String, Object> result, AttributeDefinition<?> el) {
+ final PostalAddress addressAttribute = EidasResponseUtils
+ .translateAddressAttribute(el, attributeMap.get(el).asList());
+ if (addressAttribute != null) {
+ result.put(el.getFriendlyName(), addressAttribute);
+
+ }
+ }
+
+ private void convertDateTime(ImmutableMap<AttributeDefinition<?>,
+ ImmutableSet<? extends AttributeValue<?>>> attributeMap,
+ Map<String, Object> result, AttributeDefinition<?> el) {
+ final DateTime attribute = EidasResponseUtils.translateDateAttribute(el, attributeMap.get(el).asList());
+ if (attribute != null) {
+ result.put(el.getFriendlyName(), attribute);
+
+ }
+ }
}