From 2491f68f97b8aa956a1f1e106fa2cf3540d8f86b Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Fri, 7 Oct 2022 17:13:27 +0200 Subject: fix(eIDAS-ERnP): eIDAS documents can by 'null' in ERnP response --- .../auth/eidas/v2/clients/ernp/ErnpRestClient.java | 8 ++- .../eidas/v2/test/clients/ErnpRestClientTest.java | 61 ++++++++++++++++++++++ .../2_kitt_search_latest_resp_no_eidas_docs.json | 33 ++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/2_kitt_search_latest_resp_no_eidas_docs.json (limited to 'modules') diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java index feb2853a..4212aae8 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/clients/ernp/ErnpRestClient.java @@ -572,8 +572,12 @@ public class ErnpRestClient implements IErnpClient { } + // get all eIDAS documents from current ERnP entry or an empty list of no exists + List currentEidasDocs = ernpPersonToKitt.getEidas() != null + ? ernpPersonToKitt.getEidas() : Collections.emptyList(); + // check if eIDAS attribute is already includes an eIDAS-Document - boolean alreadyExist = ernpPersonToKitt.getEidas().stream() + boolean alreadyExist = currentEidasDocs.stream() .filter(el -> el.getWert().equals(attrValue) && el.getArt().equals(attrName) && el.getStaatscode2().equals(citizenCountryCode)) @@ -582,7 +586,7 @@ public class ErnpRestClient implements IErnpClient { if (!alreadyExist) { // check eIDAS documents already contains a document with this pair of country-code and attribute-name - Optional oneDocWithNameExists = ernpPersonToKitt.getEidas().stream() + Optional oneDocWithNameExists = currentEidasDocs.stream() .filter(el -> el.getStaatscode2().equals(citizenCountryCode) && el.getArt().equals(attrName)) .findAny(); diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java index 9404b5a5..93d8ab74 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java @@ -1054,6 +1054,67 @@ public class ErnpRestClientTest { } + @Test + @SneakyThrows + public void updateUpdateRequiredAnyEidasDocs() { + final String cc = "DE"; + final String personalIdentifierFirst = "nj1m79jm9z"; + final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName("mRjMKAQc") + .givenName("vdqZZIaA") + .dateOfBirth("1996-01-01") + .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) + .pseudonym(personalIdentifierFirst) + .birthName(RandomStringUtils.randomAlphabetic(10)) + .build(); + + // set ERnP response + mockWebServer.enqueue(new MockResponse().setResponseCode(200) + .setBody(IOUtils.toString( + ErnpRestClientTest.class.getResourceAsStream("/data/ernp/2_kitt_search_latest_resp_no_eidas_docs.json"), + "UTF-8")) + .setHeader("Content-Type", "application/json;charset=utf-8")); + mockWebServer.enqueue(new MockResponse().setResponseCode(200) + .setBody(IOUtils.toString( + ErnpRestClientTest.class.getResourceAsStream("/data/ernp/2_kitt_update_resp.json"), + "UTF-8")) + .setHeader("Content-Type", "application/json;charset=utf-8")); + + RegisterResult ernpResult = RegisterResult.builder() + .familyName("mRjMKAQc") + .givenName("vdqZZIaA") + .dateOfBirth("1996-01-01") + .bpk("TBGoMlirU881e2jMGETa9WLx1+A=") + .pseudonym(Arrays.asList("88hvWzUaIX")) + .birthName("VRNCAylF") + .placeOfBirth("miEklFHC") + .build(); + + // execute operation + ErnpRegisterResult resp = client.update(ernpResult, eidasDataFirst); + + // validate request + // check get-latest-version request + mockWebServer.takeRequest(); + + // check update request + final RecordedRequest requestKitt = mockWebServer.takeRequest(); + String reqBodyKitt = requestKitt.getBody().readUtf8(); + assertFalse("no request body", reqBodyKitt.isEmpty()); + JsonNode reqJsonKitt = mapper.readTree(reqBodyKitt); + checkJsonElement(reqJsonKitt, "begruendung", "KITT update dataset"); + checkJsonElement(reqJsonKitt, "entityId", "1933000000000498"); + checkJsonElement(reqJsonKitt, "version", "2022-03-03T10:14:59.712Z"); + JsonNode personChange = getJsonObject(reqJsonKitt, "anlegen"); + checkEidasDocument(personChange, "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier", + cc, eidasDataFirst.getPseudonym()); + checkEidasDocument(personChange, "http://eidas.europa.eu/attributes/naturalperson/BirthName", + cc, eidasDataFirst.getBirthName()); + assertFalse("find 'aendern' element", reqJsonKitt.has("aendern")); + + } + private SimpleEidasData generateRandomEidasData(String cc) { final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); diff --git a/modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/2_kitt_search_latest_resp_no_eidas_docs.json b/modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/2_kitt_search_latest_resp_no_eidas_docs.json new file mode 100644 index 00000000..c7131922 --- /dev/null +++ b/modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/2_kitt_search_latest_resp_no_eidas_docs.json @@ -0,0 +1,33 @@ +{ + "person": [ + { + "type": "Person", + "entityId": "1933000000000498", + "gueltigAb": "2022-03-03T11:14:59.712+01:00", + "letzteOperation": { + "begruendung": "Add new person", + "durchgefuehrtVon": { + "behoerdenkennzeichen": "380630", + "benutzer": "eidtapp@bmi.gv.at" + }, + "vorgang": "PersonAnlegen", + "zeitpunkt": "2022-03-03T11:14:59.712+01:00" + }, + "personendaten": { + "basiszahl": "000951265372", + "bpkZp": "TBGoMlirU881e2jMGETa9WLx1+A=", + "entityId": "1933000000000498", + "familienname": "mRjMKAQc", + "geburtsdatum": { + "jahr": 1996, + "monat": 1, + "tag": 1 + }, + "geprueft": false, + "gueltigAb": "2022-03-03T11:14:59.712+01:00", + "vorname": "vdqZZIaA" + }, + "version": "2022-03-03T11:14:59.712+01:00" + } + ] +} -- cgit v1.2.3