From 7471d2724a9ade98b30296545c39c7d49c690e10 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Wed, 16 Mar 2022 15:37:39 +0100 Subject: test(szr): add second randomized integration test for SZR communication --- .../eidas/v2/test/SzrClientTestProduction.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'modules/authmodule-eIDAS-v2/src/test/java/at') diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java index 1e7ff369..0ea62855 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java @@ -104,6 +104,17 @@ public class SzrClientTestProduction { } + @Test + public void getVszRandom() throws SzrCommunicationException, EidasSAuthenticationException { + String vsz = szrClient.getEncryptedStammzahl(getPersonInfo( + RandomStringUtils.randomAlphabetic(10), + familyName, dateOfBirth, + "IS/AT/" + RandomStringUtils.randomAlphanumeric(15) + )); + Assert.assertNotNull("vsz", vsz); + + } + @Test public void getEidasBind() throws SzrCommunicationException, EidasSAuthenticationException { String vsz = RandomStringUtils.randomAlphanumeric(10); @@ -203,7 +214,9 @@ public class SzrClientTestProduction { } } - private PersonInfoType getPersonInfo() throws EidasSAuthenticationException { + private PersonInfoType getPersonInfo(String givenname, String familyname, String dateofbirth, + String eidaseid) throws EidasSAuthenticationException { + final PersonInfoType personInfo = new PersonInfoType(); final PersonNameType personName = new PersonNameType(); final PhysicalPersonType naturalPerson = new PhysicalPersonType(); @@ -215,7 +228,7 @@ public class SzrClientTestProduction { // parse some eID attributes final Triple eIdentifier = - EidasResponseUtils.parseEidasPersonalIdentifier(eIDASeID); + EidasResponseUtils.parseEidasPersonalIdentifier(eidaseid); final String uniqueId = createHashFromUniqueId(eIdentifier.getThird()); final String citizenCountry = eIdentifier.getFirst(); @@ -232,5 +245,11 @@ public class SzrClientTestProduction { Constants.SZR_CONSTANTS_DEFAULT_DOCUMENT_TYPE)); return personInfo; + + } + + private PersonInfoType getPersonInfo() throws EidasSAuthenticationException { + return getPersonInfo(givenName, familyName, dateOfBirth, eIDASeID); + } } -- cgit v1.2.3 From 321a2e29b84f441033bec477b2d71eb0a2f75e3f Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 17 Mar 2022 08:06:42 +0100 Subject: fix(szr): Request getIdentityLinkEidas before getVSZ because getVSZ does not support insertErnp by using eIDAS entities # Conflicts: # modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java # modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java --- .../eidas/v2/test/SzrClientTestProduction.java | 88 +++++++++----- .../tasks/CreateIdentityLinkTaskEidNewTest.java | 135 ++++++++++++--------- 2 files changed, 134 insertions(+), 89 deletions(-) (limited to 'modules/authmodule-eIDAS-v2/src/test/java/at') diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java index 0ea62855..83d7866e 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTestProduction.java @@ -53,12 +53,16 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenti import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.SzrCommunicationException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.szr.SzrClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.EidasResponseUtils; +import at.gv.e_government.reference.namespace.persondata._20020228.IdentificationType; import at.gv.e_government.reference.namespace.persondata._20020228.PersonNameType; import at.gv.e_government.reference.namespace.persondata._20020228.PhysicalPersonType; import at.gv.egiz.eaaf.core.api.data.EaafConstants; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; import at.gv.egiz.eaaf.core.api.idp.auth.data.IIdentityLink; +import at.gv.egiz.eaaf.core.exceptions.EaafBuilderException; import at.gv.egiz.eaaf.core.exceptions.EaafParserException; +import at.gv.egiz.eaaf.core.impl.builder.BpkBuilder; +import at.gv.egiz.eaaf.core.impl.data.Pair; import at.gv.egiz.eaaf.core.impl.data.Triple; import at.gv.egiz.eaaf.core.impl.idp.auth.data.SimpleIdentityLinkAssertionParser; import szrservices.IdentityLinkType; @@ -103,14 +107,35 @@ public class SzrClientTestProduction { Assert.assertNotNull("vsz", vsz); } - + @Test - public void getVszRandom() throws SzrCommunicationException, EidasSAuthenticationException { - String vsz = szrClient.getEncryptedStammzahl(getPersonInfo( - RandomStringUtils.randomAlphabetic(10), - familyName, dateOfBirth, - "IS/AT/" + RandomStringUtils.randomAlphanumeric(15) - )); + public void getVszRandom() throws SzrCommunicationException, EidasSAuthenticationException, EaafBuilderException { + + final String givenName = "Franz"; + final String familyName = RandomStringUtils.randomAlphabetic(10); + final String dateOfBirth = "1989-05-04"; + final String eIDASeID = "IS/AT/" + RandomStringUtils.randomAlphanumeric(20); + + IdentityLinkType idl = szrClient.getIdentityLinkInRawMode(getPersonInfo(familyName, givenName, dateOfBirth, eIDASeID)); + + PersonInfoType vszPerson = getPersonInfo( + idl.getPersonInfo().getPerson().getName().getFamilyName(), + idl.getPersonInfo().getPerson().getName().getGivenName(), + idl.getPersonInfo().getPerson().getDateOfBirth(), + null); + + final Pair bpkCalc = + BpkBuilder.generateAreaSpecificPersonIdentifier( + idl.getPersonInfo().getPerson().getIdentification().getValue(), + idl.getPersonInfo().getPerson().getIdentification().getType(), + EaafConstants.URN_PREFIX_CDID + "ZP"); + + IdentificationType vszId = new IdentificationType(); + vszPerson.getPerson().setIdentification(vszId); + vszId.setValue(bpkCalc.getFirst()); + vszId.setType(bpkCalc.getSecond()); + + String vsz = szrClient.getEncryptedStammzahl(vszPerson); Assert.assertNotNull("vsz", vsz); } @@ -214,8 +239,13 @@ public class SzrClientTestProduction { } } - private PersonInfoType getPersonInfo(String givenname, String familyname, String dateofbirth, - String eidaseid) throws EidasSAuthenticationException { + private PersonInfoType getPersonInfo() throws EidasSAuthenticationException { + return getPersonInfo(familyName, givenName, dateOfBirth, eIDASeID); + + } + + private PersonInfoType getPersonInfo(String familyName, String givenName, String dateOfBirth, String eIDASeID) + throws EidasSAuthenticationException { final PersonInfoType personInfo = new PersonInfoType(); final PersonNameType personName = new PersonNameType(); @@ -224,32 +254,32 @@ public class SzrClientTestProduction { naturalPerson.setName(personName); personInfo.setPerson(naturalPerson); - personInfo.setTravelDocument(eDocument); - - // parse some eID attributes - final Triple eIdentifier = - EidasResponseUtils.parseEidasPersonalIdentifier(eidaseid); - final String uniqueId = createHashFromUniqueId(eIdentifier.getThird()); - final String citizenCountry = eIdentifier.getFirst(); // person information personName.setFamilyName(familyName); personName.setGivenName(givenName); naturalPerson.setDateOfBirth(dateOfBirth); - eDocument.setIssuingCountry(citizenCountry); - eDocument.setDocumentNumber(uniqueId); - - // eID document information - eDocument.setDocumentType(basicConfig.getBasicConfiguration( - Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_EDOCUMENTTYPE, - Constants.SZR_CONSTANTS_DEFAULT_DOCUMENT_TYPE)); + + // parse some eID attributes + if (eIDASeID != null) { + final Triple eIdentifier = + EidasResponseUtils.parseEidasPersonalIdentifier(eIDASeID); + final String uniqueId = createHashFromUniqueId(eIdentifier.getThird()); + final String citizenCountry = eIdentifier.getFirst(); + + eDocument.setIssuingCountry(citizenCountry); + eDocument.setDocumentNumber(uniqueId); + + // eID document information + eDocument.setDocumentType(basicConfig.getBasicConfiguration( + Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_EDOCUMENTTYPE, + Constants.SZR_CONSTANTS_DEFAULT_DOCUMENT_TYPE)); + + personInfo.setTravelDocument(eDocument); + + } return personInfo; - } - - private PersonInfoType getPersonInfo() throws EidasSAuthenticationException { - return getPersonInfo(givenName, familyName, dateOfBirth, eIDASeID); - - } + } } 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 7aab1f3e..fd2e589b 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 @@ -18,6 +18,9 @@ import java.util.List; import java.util.Map; import javax.annotation.Nonnull; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; import org.apache.commons.lang3.RandomStringUtils; import org.jose4j.jwa.AlgorithmConstraints; @@ -74,9 +77,11 @@ import eu.eidas.auth.commons.attribute.ImmutableAttributeMap; import eu.eidas.auth.commons.attribute.ImmutableAttributeMap.Builder; import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse; import lombok.val; +import szrservices.GetIdentityLinkEidasResponse; import szrservices.JwsHeaderParam; import szrservices.PersonInfoType; import szrservices.SZR; +import szrservices.SZRException_Exception; import szrservices.SignContentEntry; import szrservices.SignContentResponseType; @@ -167,7 +172,8 @@ 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"); String vsz = RandomStringUtils.randomNumeric(10); when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(vsz); val signContentResp = new SignContentResponseType(); @@ -231,39 +237,31 @@ public class CreateIdentityLinkTaskEidNewTest { 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()), - 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.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("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("Identifier", - response.getAttributes().getAttributeValuesByFriendlyName("PersonIdentifier").getFirstValue( - response.getAttributes().getDefinitionsByFriendlyName("PersonIdentifier").iterator().next()) - .toString().split("/")[2], - person.getTravelDocument().getDocumentNumber()); +// 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()); // check bcBind singing request ArgumentCaptor argument1 = ArgumentCaptor.forClass(Boolean.class); @@ -307,6 +305,7 @@ public class CreateIdentityLinkTaskEidNewTest { @Test public void successfulProcessWithStandardInfos() 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(); @@ -369,34 +368,34 @@ public class CreateIdentityLinkTaskEidNewTest { ArgumentCaptor argument5 = ArgumentCaptor.forClass(Boolean.class); verify(szrMock, times(1)).getStammzahlEncrypted(argument4.capture(), argument5.capture()); - Boolean param5 = argument5.getValue(); - Assert.assertTrue("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.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()); +// Boolean param5 = argument5.getValue(); +// Assert.assertTrue("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.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()); } @@ -404,6 +403,7 @@ public class CreateIdentityLinkTaskEidNewTest { @Test public void getStammzahlEncryptedExceptionTest() throws Exception { try { + setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml"); when(szrMock, "getStammzahlEncrypted", any(), any()).thenReturn(null); task.execute(pendingReq, executionContext); } catch (TaskExecutionException e) { @@ -418,6 +418,7 @@ 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); task.execute(pendingReq, executionContext); @@ -452,6 +453,20 @@ public class CreateIdentityLinkTaskEidNewTest { } + + @Nonnull + private void setSzrResponseIdentityLink(String responseXmlPath) throws JAXBException, SZRException_Exception { + final JAXBContext jaxbContext = JAXBContext + .newInstance(szrservices.ObjectFactory.class, org.w3._2001._04.xmldsig_more.ObjectFactory.class, + org.w3._2000._09.xmldsig.ObjectFactory.class, + at.gv.e_government.reference.namespace.persondata._20020228.ObjectFactory.class); + final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + final GetIdentityLinkEidasResponse szrResponse = (GetIdentityLinkEidasResponse) jaxbUnmarshaller + .unmarshal(this.getClass().getResourceAsStream(responseXmlPath)); + org.mockito.Mockito.when(szrMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenReturn(szrResponse.getGetIdentityLinkReturn()); + + } + @Nonnull private AuthenticationResponse buildDummyAuthResponse(boolean withAll) throws URISyntaxException { final AttributeDefinition attributeDef = attrRegistry.getCoreAttributeRegistry().getByFriendlyName( -- cgit v1.2.3