aboutsummaryrefslogtreecommitdiff
path: root/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 'modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java')
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java429
1 files changed, 274 insertions, 155 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
index 10595402..023c196c 100644
--- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
+++ b/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.core.MsEidasNodeConstants.PROP_CONFIG_S
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;
@@ -23,6 +23,8 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
import org.jose4j.jwa.AlgorithmConstraints;
import org.jose4j.jwa.AlgorithmConstraints.ConstraintType;
import org.jose4j.jws.AlgorithmIdentifiers;
@@ -32,7 +34,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;
@@ -45,15 +46,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.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.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;
@@ -73,8 +83,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.GetIdentityLinkEidasResponse;
@@ -86,7 +98,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",
@@ -105,6 +116,9 @@ public class CreateIdentityLinkTaskEidNewTest {
EaafKeyStoreFactory keyStoreFactory;
@Autowired
+ ICcSpecificEidProcessingService eidPostProcessor;
+
+ @Autowired
private IRequestStorage requestStorage;
final ExecutionContext executionContext = new ExecutionContextImpl();
@@ -123,25 +137,27 @@ public class CreateIdentityLinkTaskEidNewTest {
AlgorithmIdentifiers.RSA_PSS_USING_SHA512));
private static ObjectMapper mapper = new ObjectMapper();
-
+
private AuthenticationResponse response;
-
+ private MatchedPersonResult matchingInfos;
+
@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");
- basicConfig.putConfigValue("eidas.ms.auth.eIDAS.szrclient.workarounds.use.getidentitylink.for.ida", "true");
final Map<String, String> spConfig = new HashMap<>();
spConfig.put(EaafConfigConstants.SERVICE_UNIQUEIDENTIFIER, "testSp");
@@ -153,14 +169,27 @@ 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);
+
+ matchingInfos = MatchedPersonResult.builder()
+ .bpk(RandomStringUtils.randomAlphabetic(5))
+ .givenName(eidData.getGivenName())
+ .familyName(eidData.getFamilyName())
+ .dateOfBirth(eidData.getDateOfBirth())
+ .countryCode(eidData.getCitizenCountryCode())
+ .build();
+ MatchingTaskUtils.storeFinalMatchingResult(pendingReq, matchingInfos);
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);
@@ -173,27 +202,39 @@ public class CreateIdentityLinkTaskEidNewTest {
response = buildDummyAuthResponse(true);
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
-
- setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml");
+
+ SimpleEidasData eidData = eidPostProcessor.postProcess(
+ convertEidasAttrToSimpleMap(response.getAttributes().getAttributeMap()));
+ MatchingTaskUtils.storeInitialEidasData(pendingReq, eidData);
+
+ matchingInfos = MatchedPersonResult.builder()
+ .bpk(RandomStringUtils.randomAlphabetic(5))
+ .givenName(eidData.getGivenName())
+ .familyName(eidData.getFamilyName())
+ .dateOfBirth(eidData.getDateOfBirth())
+ .countryCode(eidData.getCitizenCountryCode())
+ .build();
+ MatchingTaskUtils.storeFinalMatchingResult(pendingReq, matchingInfos);
+
String vsz = RandomStringUtils.randomNumeric(10);
- when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(vsz);
- val signContentResp = new SignContentResponseType();
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(vsz);
+ SignContentResponseType 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);
@@ -201,16 +242,12 @@ public class CreateIdentityLinkTaskEidNewTest {
String authBlock = authProcessData.getGenericDataFromSession(MsEidasNodeConstants.AUTH_DATA_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()]));
@@ -218,52 +255,47 @@ 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.assertFalse("insertERnP flag", param5);
+ Assert.assertFalse("insertERnP flag", param5);
PersonInfoType person = argument4.getValue();
- Assert.assertEquals("FamilyName", "Mustermann", person.getPerson().getName().getFamilyName());
- Assert.assertEquals("GivenName", "Hans", person.getPerson().getName().getGivenName());
- Assert.assertEquals("DateOfBirth", "1989-05-05", person.getPerson().getDateOfBirth());
- Assert.assertEquals("bpk", "1NjpYBHFn6onfNp2pCM8nXrlyQc=", person.getPerson().getIdentification().getValue());
- Assert.assertEquals("bPKType", EaafConstants.URN_PREFIX_CDID + "ZP", person.getPerson().getIdentification().getType());
-
-// Assert.assertEquals("PlaceOfBirth",
-// response.getAttributes().getAttributeValuesByFriendlyName("PlaceOfBirth").getFirstValue(
-// response.getAttributes().getDefinitionsByFriendlyName("PlaceOfBirth").iterator().next()),
-// person.getPerson().getPlaceOfBirth());
-// Assert.assertEquals("BirthName",
-// response.getAttributes().getAttributeValuesByFriendlyName("BirthName").getFirstValue(
-// 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",
-// response.getAttributes().getAttributeValuesByFriendlyName("PersonIdentifier").getFirstValue(
-// response.getAttributes().getDefinitionsByFriendlyName("PersonIdentifier").iterator().next())
-// .toString().split("/")[2],
-// person.getTravelDocument().getDocumentNumber());
-
+ Assert.assertEquals("FamilyName",
+ response.getAttributes().getAttributeValuesByFriendlyName("FamilyName").getFirstValue(
+ response.getAttributes().getDefinitionsByFriendlyName("FamilyName").iterator().next()),
+ person.getPerson().getName().getFamilyName());
+ Assert.assertEquals("GivenName",
+ response.getAttributes().getAttributeValuesByFriendlyName("FirstName").getFirstValue(
+ response.getAttributes().getDefinitionsByFriendlyName("FirstName").iterator().next()),
+ person.getPerson().getName().getGivenName());
+ Assert.assertEquals("DateOfBirth",
+ response.getAttributes().getAttributeValuesByFriendlyName("DateOfBirth").getFirstValue(
+ response.getAttributes().getDefinitionsByFriendlyName("DateOfBirth").iterator().next())
+ .toString().split("T")[0],
+ person.getPerson().getDateOfBirth());
+
+ Assert.assertNull("PlaceOfBirth", person.getPerson().getPlaceOfBirth());
+ Assert.assertNull("BirthName", person.getPerson().getAlternativeName());
+ Assert.assertNull("TravelDocument", person.getTravelDocument());
+
// check bcBind singing request
ArgumentCaptor<Boolean> argument1 = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<List<JwsHeaderParam>> argument2 = ArgumentCaptor.forClass(List.class);
@@ -271,66 +303,67 @@ 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 successfulProcessWithStandardInfosWithoutIdl() throws Exception {
+ public void successfulProcessWithDataFromMatching() throws Exception {
//initialize test
- basicConfig.putConfigValue("eidas.ms.auth.eIDAS.szrclient.workarounds.use.getidentitylink.for.ida", "false");
-
String vsz = RandomStringUtils.randomNumeric(10);
- when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(vsz);
- val signContentResp = new SignContentResponseType();
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(vsz);
+ SignContentResponseType 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);
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);
@@ -339,6 +372,7 @@ public class CreateIdentityLinkTaskEidNewTest {
// check authblock signature
String authBlock = authProcessData.getGenericDataFromSession(MsEidasNodeConstants.AUTH_DATA_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();
@@ -361,122 +395,108 @@ 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.assertTrue("insertERnP flag", param5);
+ Assert.assertFalse("insertERnP flag", param5);
PersonInfoType person = argument4.getValue();
- Assert.assertEquals("FamilyName",
- response.getAttributes().getAttributeValuesByFriendlyName("FamilyName").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("FamilyName").iterator().next()),
+ Assert.assertEquals("FamilyName",
+ matchingInfos.getFamilyName(),
person.getPerson().getName().getFamilyName());
- Assert.assertEquals("GivenName",
- response.getAttributes().getAttributeValuesByFriendlyName("FirstName").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("FirstName").iterator().next()),
+ Assert.assertEquals("GivenName",
+ matchingInfos.getGivenName(),
person.getPerson().getName().getGivenName());
- Assert.assertEquals("DateOfBirth",
- response.getAttributes().getAttributeValuesByFriendlyName("DateOfBirth").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("DateOfBirth").iterator().next())
- .toString().split("T")[0],
+ 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());
-
- Assert.assertEquals("CitizenCountry", "LU", person.getTravelDocument().getIssuingCountry());
- Assert.assertEquals("DocumentType", "ELEKTR_DOKUMENT", person.getTravelDocument().getDocumentType());
-
- Assert.assertEquals("Identifier",
- response.getAttributes().getAttributeValuesByFriendlyName("PersonIdentifier").getFirstValue(
- response.getAttributes().getDefinitionsByFriendlyName("PersonIdentifier").iterator().next())
- .toString().split("/")[2],
- person.getTravelDocument().getDocumentNumber());
+ Assert.assertNull("PlaceOfBirth", person.getPerson().getPlaceOfBirth());
+ Assert.assertNull("BirthName", person.getPerson().getAlternativeName());
+
}
@Test
public void successfulProcessWithStandardInfos() throws Exception {
- //initialize test
- setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml");
+ //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);
- 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);
Assert.assertNotNull("eidasBind", authProcessData.getGenericDataFromSession(MsEidasNodeConstants.AUTH_DATA_EIDAS_BIND, String.class));
- // check authblock signature
String authBlock = authProcessData.getGenericDataFromSession(MsEidasNodeConstants.AUTH_DATA_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();
- 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.assertNotNull("deserialized AuthBlock", authBlockJson);
-
- Assert.assertNotNull("no piiTransactionId in pendingRequesdt",
- storedPendingReq.getUniquePiiTransactionIdentifier());
- Assert.assertEquals("piiTransactionId", storedPendingReq.getUniquePiiTransactionIdentifier(),
- authBlockJson.get("piiTransactionId").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.assertTrue("binding pubKey", authBlockJson.has("bindingPublicKey"));
- Assert.assertEquals("binding PubKey", bindingPubKey, authBlockJson.get("bindingPublicKey").asText());
-
+
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",
+ response.getAttributes().getAttributeValuesByFriendlyName("FamilyName").getFirstValue(
+ response.getAttributes().getDefinitionsByFriendlyName("FamilyName").iterator().next()),
+ person.getPerson().getName().getFamilyName());
+ Assert.assertEquals("GivenName",
+ response.getAttributes().getAttributeValuesByFriendlyName("FirstName").getFirstValue(
+ response.getAttributes().getDefinitionsByFriendlyName("FirstName").iterator().next()),
+ person.getPerson().getName().getGivenName());
+ Assert.assertEquals("DateOfBirth",
+ response.getAttributes().getAttributeValuesByFriendlyName("DateOfBirth").getFirstValue(
+ response.getAttributes().getDefinitionsByFriendlyName("DateOfBirth").iterator().next())
+ .toString().split("T")[0],
+ person.getPerson().getDateOfBirth());
+
+ Assert.assertNull("PlaceOfBirth", person.getPerson().getPlaceOfBirth());
+ Assert.assertNull("BirthName", person.getPerson().getAlternativeName());
+ Assert.assertNull("TravelDocument", person.getTravelDocument());
+
}
@Test
public void getStammzahlEncryptedExceptionTest() throws Exception {
try {
- setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml");
- 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(),
"IdentityLink generation for foreign person " + "FAILED.");
@@ -489,10 +509,10 @@ public class CreateIdentityLinkTaskEidNewTest {
@Test
public void signContentExceptionTest() throws Exception {
try {
- setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml");
- 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(),
"IdentityLink generation for foreign person " + "FAILED.");
@@ -502,6 +522,45 @@ public class CreateIdentityLinkTaskEidNewTest {
}
}
+ @Test
+ public void checkEmptyStringAttribute() throws Exception {
+ //initialize test
+ setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml");
+ 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);
+ String bindingPubKey = RandomStringUtils.randomAlphabetic(10);
+ pendingReq.setRawDataToTransaction(MsEidasNodeConstants.DATA_REQUESTERID, randomTestSp);
+ pendingReq.setRawDataToTransaction(MsEidasNodeConstants.EID_BINDING_PUBLIC_KEY_NAME, bindingPubKey);
+
+
+ response = buildDummyAuthResponse(true, true);
+ pendingReq.getSessionData(AuthProcessDataWrapper.class)
+ .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
+
+
+ //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(MsEidasNodeConstants.AUTH_DATA_EIDAS_BIND, String.class));
+
+ }
+
+
private Pair<KeyStore, Provider> getKeyStore() throws EaafException {
// read Connector wide config data TODO connector wide!
String keyStoreName = basicConfig.getBasicConfiguration(MsEidasNodeConstants.PROP_CONFIG_AUTHBLOCK_KEYSTORE_NAME);
@@ -537,9 +596,14 @@ public class CreateIdentityLinkTaskEidNewTest {
}
-
@Nonnull
private AuthenticationResponse buildDummyAuthResponse(boolean withAll) throws URISyntaxException {
+ return buildDummyAuthResponse(withAll, false);
+
+ }
+
+ @Nonnull
+ private AuthenticationResponse buildDummyAuthResponse(boolean withAll, boolean withEmpty) throws URISyntaxException {
final AttributeDefinition attributeDef = attrRegistry.getCoreAttributeRegistry().getByFriendlyName(
Constants.eIDAS_ATTR_PERSONALIDENTIFIER).first();
final AttributeDefinition attributeDef2 = attrRegistry.getCoreAttributeRegistry().getByFriendlyName(
@@ -552,16 +616,22 @@ 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));
attributeMap.put(attributeDef3, RandomStringUtils.randomAlphabetic(10));
attributeMap.put(attributeDef4, "2001-01-01");
if (withAll) {
- attributeMap.put(attributeDef5, RandomStringUtils.randomAlphabetic(10));
+ if (withEmpty) {
+ attributeMap.put(attributeDef5, Collections.emptySet());
+
+ } else {
+ attributeMap.put(attributeDef5, RandomStringUtils.randomAlphabetic(10));
+
+ }
attributeMap.put(attributeDef6, RandomStringUtils.randomAlphabetic(10));
-
+
}
val b = new AuthenticationResponse.Builder();
@@ -575,4 +645,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);
+
+ }
+ }
}