diff options
author | Thomas <> | 2022-03-03 11:43:59 +0100 |
---|---|---|
committer | Thomas <> | 2022-03-03 11:43:59 +0100 |
commit | 0020b5d6084501b6ee6b6b07fdc40ab47dc30dc7 (patch) | |
tree | af57ea4d39517982054984ffbb9f5650d4704b8e | |
parent | df894a4076abbcb4357509eb453f4c447a8856d5 (diff) | |
download | National_eIDAS_Gateway-0020b5d6084501b6ee6b6b07fdc40ab47dc30dc7.tar.gz National_eIDAS_Gateway-0020b5d6084501b6ee6b6b07fdc40ab47dc30dc7.tar.bz2 National_eIDAS_Gateway-0020b5d6084501b6ee6b6b07fdc40ab47dc30dc7.zip |
test(ernp): add all ERnP integration tests into test that operates in real test ERnP
2 files changed, 382 insertions, 9 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java index f9301505..094b2a9f 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/SimpleEidasData.java @@ -32,7 +32,7 @@ import lombok.Builder; import lombok.Data; @Data -@Builder +@Builder(toBuilder=true) public class SimpleEidasData implements Serializable { private static final long serialVersionUID = 2848914124372968418L; diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientProductionTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientProductionTest.java index 6ebe4c8a..66a426a1 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientProductionTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientProductionTest.java @@ -1,9 +1,14 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.clients; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -17,6 +22,8 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.IErnpClient import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenticationException; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.DeSpecificDetailSearchProcessor; +import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonSuchenRequest; import lombok.SneakyThrows; @IfProfileValue(name = "spring.profiles.active", value = "devEnvironment") @@ -30,18 +37,22 @@ import lombok.SneakyThrows; }) public class ErnpRestClientProductionTest { + //private static final String TEST_PREFIX = "XXX_"; + private static final String TEST_PREFIX = ""; + @Autowired IErnpClient client; @Test @SneakyThrows public void searchWithPersonalIdentifierServerError() { - final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; + String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; + personalIdentifierFirst = ""; final String cc = "DE"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) .familyName("XXXvon Brandenburg") .givenName("XXXClaus - Maria") - .dateOfBirth("1994-12-31") + .dateOfBirth("1994-12-00") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); @@ -59,12 +70,39 @@ public class ErnpRestClientProductionTest { @SneakyThrows public void searchWithPersonalIdentifierSuccess() { final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; - final String cc = "DE"; + final String cc = "CZ"; final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() .citizenCountryCode(cc) - .familyName("XXXvon Brandenburg") - .givenName("XXXClaus - Maria") - .dateOfBirth("1994-12-31") + .familyName("DOPISNÍ") + .givenName("DANA") + .dateOfBirth("1996-01-01") + .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) + .pseudonym(personalIdentifierFirst) + .build(); + + // execute operation + ErnpRegisterResult resp = client.searchWithPersonIdentifier( + eidasDataFirst.getPseudonym(), eidasDataFirst.getCitizenCountryCode()); + + // validate state + assertNotNull("no ERnP response", resp); + assertEquals("wrong resp size", 1, resp.getPersonResult().size()); + checkErnpResult(resp.getPersonResult().get(0), eidasDataFirst, 1); + assertEquals("wrong bpk", "vypyCkyczK7i+cgPWlJasuJphIA=", + resp.getPersonResult().get(0).getBpk()); + + } + + @Test + @SneakyThrows + public void searchWithPersonalIdentifierNoResult() { + final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); + final String cc = "CZ"; + final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName("DOPISNÍ") + .givenName("DANA") + .dateOfBirth("1996-01-01") .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) .pseudonym(personalIdentifierFirst) .build(); @@ -75,13 +113,348 @@ public class ErnpRestClientProductionTest { // validate state assertNotNull("no ERnP response", resp); + assertEquals("wrong resp size", 0, resp.getPersonResult().size()); + + } + + + @Test + @SneakyThrows + public void searchWithMdsSuccess() { + final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; + final String cc = "CZ"; + final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName("DOPISNÍ") + .givenName("DANA") + .dateOfBirth("1996-01-01") + .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) + .pseudonym(personalIdentifierFirst) + .build(); + + // execute operation + ErnpRegisterResult resp = client.searchWithMds(eidasDataFirst.getGivenName(), eidasDataFirst.getFamilyName(), + eidasDataFirst.getDateOfBirth(), eidasDataFirst.getCitizenCountryCode()); + + // validate state + assertNotNull("no ERnP response", resp); assertEquals("wrong resp size", 1, resp.getPersonResult().size()); + checkErnpResult(resp.getPersonResult().get(0), eidasDataFirst, 1); + assertEquals("wrong bpk", "vypyCkyczK7i+cgPWlJasuJphIA=", + resp.getPersonResult().get(0).getBpk()); + + } + + @Test + @SneakyThrows + public void searchWithMdsNoResult() { + final String personalIdentifierFirst = RandomStringUtils.randomAlphanumeric(10); + final String cc = "CZ"; + final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName(RandomStringUtils.randomAlphanumeric(10)) + .givenName(RandomStringUtils.randomAlphanumeric(10)) + .dateOfBirth("1996-10-15") + .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) + .pseudonym(personalIdentifierFirst) + .build(); + + // execute operation + ErnpRegisterResult resp = client.searchWithMds(eidasDataFirst.getGivenName(), eidasDataFirst.getFamilyName(), + eidasDataFirst.getDateOfBirth(), eidasDataFirst.getCitizenCountryCode()); + + // validate state + assertNotNull("no ERnP response", resp); + assertEquals("wrong resp size", 0, resp.getPersonResult().size()); + + } + + @Test + @SneakyThrows + public void addTwiceSameMdsAndMdsSearch() { + // *** add new random first person *** + final String addFirstPersonPersonalIdentifier = RandomStringUtils.randomAlphanumeric(10); + final String cc = "XZ"; + final SimpleEidasData addFirstPersonData = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .givenName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .dateOfBirth("1996-01-01") + .personalIdentifier(cc + "/AT/" + addFirstPersonPersonalIdentifier) + .pseudonym(addFirstPersonPersonalIdentifier) + .build(); + + // add entry + ErnpRegisterResult addFirstPersonResponse = client.add(addFirstPersonData); + + // verify added entry + assertNotNull("no ERnP response", addFirstPersonResponse); + assertEquals("wrong resp size", 1, addFirstPersonResponse.getPersonResult().size()); + checkErnpResult(addFirstPersonResponse.getPersonResult().get(0), addFirstPersonData, 1); + + + // *** add new random second person with same MDS *** + final String addSecondPersonPersonalIdentifier = RandomStringUtils.randomAlphanumeric(10); + final SimpleEidasData addSecondPersonData = addFirstPersonData.toBuilder() + .personalIdentifier(cc + "/AT/" + addSecondPersonPersonalIdentifier) + .pseudonym(addSecondPersonPersonalIdentifier) + .build(); + + // add entry + ErnpRegisterResult addSecondPersonResponse = client.add(addSecondPersonData); + + // verify added entry + assertNotNull("no ERnP response", addSecondPersonResponse); + assertEquals("wrong resp size", 1, addSecondPersonResponse.getPersonResult().size()); + checkErnpResult(addSecondPersonResponse.getPersonResult().get(0), addSecondPersonData, 1); - RegisterResult persInfo = resp.getPersonResult().get(0); - assertEquals("wrong familyname", "XXXSZR", persInfo.getFamilyName()); + // search with MDS + ErnpRegisterResult resp = client.searchWithMds(addFirstPersonData.getGivenName(), addFirstPersonData.getFamilyName(), + addFirstPersonData.getDateOfBirth(), cc); + + // validate state + assertNotNull("no ERnP response", resp); + assertEquals("wrong resp size", 2, resp.getPersonResult().size()); + } + + @Test + @SneakyThrows + public void addSearchAndPersonalIdUpdate() { + // *** add new random entry *** + + final String addPersonPersonalIdentifier = RandomStringUtils.randomAlphanumeric(10); + final String cc = "DE"; + final SimpleEidasData addPersonData = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .givenName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .dateOfBirth("1996-01-01") + .personalIdentifier(cc + "/AT/" + addPersonPersonalIdentifier) + .pseudonym(addPersonPersonalIdentifier) + .birthName(RandomStringUtils.randomAlphabetic(8)) + .placeOfBirth(RandomStringUtils.randomAlphabetic(8)) + .build(); + + // add entry + ErnpRegisterResult addPersonResponse = client.add(addPersonData); + + // verify added entry + assertNotNull("no ERnP response", addPersonResponse); + assertEquals("wrong resp size", 1, addPersonResponse.getPersonResult().size()); + checkErnpResult(addPersonResponse.getPersonResult().get(0), addPersonData, 1); + + + // *** search entry by countrySpecifics *** + final String ccPersonPersonalIdentifier = RandomStringUtils.randomAlphanumeric(10); + SimpleEidasData ccSpecificData = addPersonData.toBuilder() + .personalIdentifier(cc + "/AT/" + ccPersonPersonalIdentifier) + .pseudonym(ccPersonPersonalIdentifier) + .build(); + PersonSuchenRequest ccSearchReq = + new DeSpecificDetailSearchProcessor().generateSearchRequest(ccSpecificData); + + // search CC specific + ErnpRegisterResult ccSearchResponse = client.searchCountrySpecific(ccSearchReq, cc); + + // verify cc specific result + assertNotNull("no ERnP response", ccSearchResponse); + assertEquals("wrong resp size", 1, ccSearchResponse.getPersonResult().size()); + RegisterResult ccSearchPersResult = ccSearchResponse.getPersonResult().get(0); + checkErnpResult(ccSearchResponse.getPersonResult().get(0), addPersonData, 1); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), + ccSearchPersResult.getBpk()); + assertFalse("no PersonalId change detected", ccSpecificData.equalsRegisterData(ccSearchPersResult)); + + + // *** update entry because PersonalId has changed *** + // update ERnP entry + ErnpRegisterResult updateResponse = client.update(ccSearchPersResult, ccSpecificData); + assertNotNull("no ERnP response", updateResponse); + assertEquals("wrong resp size", 1, updateResponse.getPersonResult().size()); + checkErnpResult(updateResponse.getPersonResult().get(0), addPersonData, 2); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), ccSearchPersResult.getBpk()); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), addPersonPersonalIdentifier); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), ccPersonPersonalIdentifier); + + + + // *** search by first personalIdentifier + ErnpRegisterResult persIdSearchFirstResp = client.searchWithPersonIdentifier( + addPersonPersonalIdentifier, cc); + assertNotNull("no ERnP response", persIdSearchFirstResp); + assertEquals("wrong resp size", 1, persIdSearchFirstResp.getPersonResult().size()); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), ccSearchPersResult.getBpk()); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), addPersonPersonalIdentifier); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), ccPersonPersonalIdentifier); + checkErnpResult(updateResponse.getPersonResult().get(0), addPersonData, 2); + + + + // *** search by second personalIdentifier + ErnpRegisterResult persIdSearchSecondResp = client.searchWithPersonIdentifier( + ccPersonPersonalIdentifier, cc); + assertNotNull("no ERnP response", persIdSearchSecondResp); + assertEquals("wrong resp size", 1, persIdSearchSecondResp.getPersonResult().size()); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), ccSearchPersResult.getBpk()); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), addPersonPersonalIdentifier); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), ccPersonPersonalIdentifier); + checkErnpResult(updateResponse.getPersonResult().get(0), addPersonData, 2); + + } + + @Test + @SneakyThrows + public void addSearchAndMdsUpdate() { + // *** add new random entry *** + + final String addPersonPersonalIdentifier = RandomStringUtils.randomAlphanumeric(10); + final String cc = "DE"; + final SimpleEidasData addPersonData = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .givenName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .dateOfBirth("1985-05-05") + .personalIdentifier(cc + "/AT/" + addPersonPersonalIdentifier) + .pseudonym(addPersonPersonalIdentifier) + .birthName(RandomStringUtils.randomAlphabetic(8)) + .placeOfBirth(RandomStringUtils.randomAlphabetic(8)) + .build(); + + // add entry + ErnpRegisterResult addPersonResponse = client.add(addPersonData); + + // verify added entry + assertNotNull("no ERnP response", addPersonResponse); + assertEquals("wrong resp size", 1, addPersonResponse.getPersonResult().size()); + checkErnpResult(addPersonResponse.getPersonResult().get(0), addPersonData, 1); + + + // *** search entry by personalId *** + SimpleEidasData mdsHasChanged = addPersonData.toBuilder() + .givenName(RandomStringUtils.randomAlphanumeric(10)) + .familyName(RandomStringUtils.randomAlphanumeric(10)) + .build(); + + // search by personalId + ErnpRegisterResult personalIdResponse = client.searchWithPersonIdentifier(addPersonPersonalIdentifier, cc); + + // verify personalId result + assertNotNull("no ERnP response", personalIdResponse); + assertEquals("wrong resp size", 1, personalIdResponse.getPersonResult().size()); + RegisterResult persIdSearchResult = personalIdResponse.getPersonResult().get(0); + checkErnpResult(personalIdResponse.getPersonResult().get(0), addPersonData, 1); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), + persIdSearchResult.getBpk()); + assertFalse("no MDS change detected", mdsHasChanged.equalsRegisterData(persIdSearchResult)); + + + // *** update entry because MDS has changed *** + // update ERnP entry + ErnpRegisterResult updateResponse = client.update(persIdSearchResult, mdsHasChanged); + assertNotNull("no ERnP response", updateResponse); + assertEquals("wrong resp size", 1, updateResponse.getPersonResult().size()); + checkErnpResult(updateResponse.getPersonResult().get(0), mdsHasChanged, 1); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), persIdSearchResult.getBpk()); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), addPersonPersonalIdentifier); + + + // *** search by first personalIdentifier + ErnpRegisterResult persIdSearchFirstResp = client.searchWithPersonIdentifier( + addPersonPersonalIdentifier, cc); + assertNotNull("no ERnP response", persIdSearchFirstResp); + assertEquals("wrong resp size", 1, persIdSearchFirstResp.getPersonResult().size()); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), persIdSearchResult.getBpk()); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), addPersonPersonalIdentifier); + checkErnpResult(updateResponse.getPersonResult().get(0), mdsHasChanged, 1); + + // *** search by first personalIdentifier + ErnpRegisterResult mdsSearchResp = client.searchWithMds( + mdsHasChanged.getGivenName(), mdsHasChanged.getFamilyName(), mdsHasChanged.getDateOfBirth(), cc); + assertNotNull("no ERnP response", mdsSearchResp); + assertEquals("wrong resp size", 1, mdsSearchResp.getPersonResult().size()); + assertEquals("wrong bPK", addPersonResponse.getPersonResult().get(0).getBpk(), persIdSearchResult.getBpk()); + checkPersonalIdentifier(updateResponse.getPersonResult().get(0), addPersonPersonalIdentifier); + checkErnpResult(updateResponse.getPersonResult().get(0), mdsHasChanged, 1); + + + + } + + + @Ignore + @Test + @SneakyThrows + public void addErnpEntry() { + final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit"; + final String cc = "CZ"; + final SimpleEidasData eidasDataFirst = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName("DOPISNÍ") + .givenName("DANA") + .dateOfBirth("1996-01-01") + .personalIdentifier(cc + "/AT/" + personalIdentifierFirst) + .pseudonym(personalIdentifierFirst) + .build(); + + // execute operation + ErnpRegisterResult resp = client.add(eidasDataFirst); + + // validate state + assertNotNull("no ERnP response", resp); + assertEquals("wrong resp size", 1, resp.getPersonResult().size()); + checkErnpResult(resp.getPersonResult().get(0), eidasDataFirst, 1); + + } + + @Test + @SneakyThrows + public void addRandomErnpEntry() { + final String addPersonPersonalIdentifier = RandomStringUtils.randomAlphanumeric(10); + final String cc = "XZ"; + final SimpleEidasData addPersonData = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .givenName(TEST_PREFIX + RandomStringUtils.randomAlphabetic(8)) + .dateOfBirth("1985-05-05") + .personalIdentifier(cc + "/AT/" + addPersonPersonalIdentifier) + .pseudonym(addPersonPersonalIdentifier) + .birthName(RandomStringUtils.randomAlphabetic(8)) + .placeOfBirth(RandomStringUtils.randomAlphabetic(8)) + .build(); + + // add entry + ErnpRegisterResult addPersonResponse = client.add(addPersonData); + + // verify added entry + assertNotNull("no ERnP response", addPersonResponse); + assertEquals("wrong resp size", 1, addPersonResponse.getPersonResult().size()); + checkErnpResult(addPersonResponse.getPersonResult().get(0), addPersonData, 1); + + } + + + private void checkErnpResult(RegisterResult registerResult, final SimpleEidasData eidasData, int numOfPseudonyms) { + assertEquals("wrong familyname", eidasData.getFamilyName(), registerResult.getFamilyName()); + assertEquals("wrong givenname", eidasData.getGivenName(), registerResult.getGivenName()); + assertEquals("wrong birthday", eidasData.getDateOfBirth(), registerResult.getDateOfBirth()); + assertEquals("wrong personalId size", numOfPseudonyms, registerResult.getPseudonym().size()); + assertEquals("wrong placeOfBirth", eidasData.getPlaceOfBirth(), registerResult.getPlaceOfBirth()); + assertEquals("wrong birthName", eidasData.getBirthName(), registerResult.getBirthName()); + assertTrue("no bPK", StringUtils.isNotEmpty(registerResult.getBpk())); + checkPersonalIdentifier(registerResult, eidasData.getPseudonym()); + + } + + private void checkPersonalIdentifier(RegisterResult registerResult, String pseudonym) { + assertTrue("wrong or no personalId", registerResult.getPseudonym().stream() + .filter(el -> pseudonym.equals(el)) + .findFirst() + .isPresent()); + + } } |