From dfbd513a2cfefadc82bdc32fca171496332c13e2 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Tue, 21 Sep 2021 16:14:28 +0200 Subject: fix some bugs in ZMRClient that we found during first testing with ZMR T-Stage --- .../v2/test/clients/ZmrClientProductionTest.java | 163 ++++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-) (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java/at') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java index 5f3c5a55..8ac6fff6 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ZmrClientProductionTest.java @@ -1,19 +1,35 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.clients; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.util.List; + +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.IfProfileValue; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClient.ZmrRegisterResult; +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.utils.LoggingHandler; +import at.gv.bmi.namespace.zmr_su.zmr._20040201.EidasSuchdatenType; +import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonSuchenRequest; +import at.gv.e_government.reference.namespace.persondata.de._20040201.NatuerlichePersonTyp; +import at.gv.e_government.reference.namespace.persondata.de._20040201.PersonenNameTyp; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; @IfProfileValue(name = "spring.profiles.active", value = "devEnvironment") @RunWith(SpringJUnit4ClassRunner.class) @@ -29,14 +45,159 @@ public class ZmrClientProductionTest { @Autowired ZmrSoapClient client; @Autowired IConfiguration basicConfig; + @BeforeClass + public static void classInitializer() { + Logger logger1 = (Logger) LoggerFactory.getLogger(LoggingHandler.class); + logger1.setLevel(Level.TRACE); + + Logger logger2 = (Logger) LoggerFactory.getLogger(ZmrSoapClient.class); + logger2.setLevel(Level.TRACE); + + Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); + rootLogger.setLevel(Level.INFO); + + } + @Test - public void mdsSearch() throws EidasSAuthenticationException { + public void searchWithMdsOnly() throws EidasSAuthenticationException { ZmrRegisterResult result = client.searchWithMds(null, "Thomas", "Lenz", "1982-09-06", "AT"); assertNotNull("ZMR response", result); + assertNotNull("ZMR processId", result.getProcessId()); + assertNotNull("ZMR personResult", result.getPersonResult()); + assertEquals("personResult size", 1, result.getPersonResult().size()); + + } + + @Test + public void searchWithMdsOnlyTestIdentity() throws EidasSAuthenticationException { + + ZmrRegisterResult result = client.searchWithMds(null, + "XXXHildegard", "XXXĂ–hlinger", "1971-02-18", + "AT"); + + assertNotNull("ZMR response", result); + assertNotNull("ZMR processId", result.getProcessId()); + assertNotNull("ZMR personResult", result.getPersonResult()); + assertEquals("personResult size", 1, result.getPersonResult().size()); + + } + + @Test + public void searchWithCountrySpecificsNoExits() throws EidasSAuthenticationException { + ZmrRegisterResult result = client.searchCountrySpecific(null, + generateCustomRequest("AT", "Lenz", "Thomas", "1982-09-06", + null, + RandomStringUtils.randomAlphabetic(5), + RandomStringUtils.randomAlphabetic(5)), + "AT"); + + assertNotNull("ZMR response", result); + assertNotNull("ZMR processId", result.getProcessId()); + assertNotNull("ZMR personResult", result.getPersonResult()); + assertEquals("personResult size", 0, result.getPersonResult().size()); + + } + + @Test + public void searchWithPersonalIdOnly() throws EidasSAuthenticationException { + + ZmrRegisterResult result = client.searchWithPersonIdentifier(null, + RandomStringUtils.randomAlphanumeric(25), + "AT"); + + assertNotNull("ZMR response", result); + assertNotNull("ZMR processId", result.getProcessId()); + assertNotNull("ZMR personResult", result.getPersonResult()); + assertEquals("personResult size", 0, result.getPersonResult().size()); + + } + + @Test + public void updateZmrEntry() throws EidasSAuthenticationException { + String personalIdentifier = "7cEYSvKZvon+V4CDVzNT4E7cjkU4Vq"; + String cc = "EE"; + + SimpleEidasData eidasData = SimpleEidasData.builder() + .citizenCountryCode(cc) + .familyName("Lenz") + .givenName("Thomas") + .dateOfBirth("1982-09-06") + .personalIdentifier(cc + "/AT/" + personalIdentifier) + .pseudonym(personalIdentifier) + .build(); + + // get initial result + ZmrRegisterResult result = client.searchWithMds(null, + eidasData.getGivenName(), + eidasData.getFamilyName(), + eidasData.getDateOfBirth(), + eidasData.getCitizenCountryCode()); + assertNotNull("ZMR response", result); + assertEquals("personResult size", 1, result.getPersonResult().size()); + + + //update ZMR entry + ZmrRegisterResult updateResult = + client.update(result.getProcessId(), + result.getPersonResult().get(0), + eidasData); + + assertNotNull("ZMR response", updateResult); + assertEquals("personResult size", 1, updateResult.getPersonResult().size()); + + + + ZmrRegisterResult afterUpdateResult = client.searchWithPersonIdentifier(null, + personalIdentifier, cc); + + assertNotNull("ZMR response", afterUpdateResult); + assertEquals("personResult size", 1, afterUpdateResult.getPersonResult().size()); + + + } + + + + private PersonSuchenRequest generateCustomRequest(String cc, String familyName, String givenName, + String dateOfBirth, String personalId, String placeOfBirth, String birthName) { + PersonSuchenRequest req = new PersonSuchenRequest(); + + //set basic MDS information + final NatuerlichePersonTyp searchNatPerson = new NatuerlichePersonTyp(); + req.setNatuerlichePerson(searchNatPerson); + final PersonenNameTyp searchNatPersonName = new PersonenNameTyp(); + searchNatPerson.setPersonenName(searchNatPersonName); + searchNatPersonName.setFamilienname(familyName); + searchNatPersonName.setVorname(givenName); + searchNatPerson.setGeburtsdatum(dateOfBirth); + + //add addtional eIDAS attributes if available + addIfAvailable(req.getEidasSuchdaten(), cc, Constants.eIDAS_ATTRURN_PLACEOFBIRTH, placeOfBirth); + addIfAvailable(req.getEidasSuchdaten(), cc, Constants.eIDAS_ATTRURN_BIRTHNAME, birthName); + addIfAvailable(req.getEidasSuchdaten(), cc, Constants.eIDAS_ATTRURN_PERSONALIDENTIFIER, personalId); + + return req; + + } + + private void addIfAvailable(List eidasSuchdaten, + String cc, String attrName, String attrValue) { + if (StringUtils.isNotEmpty(attrValue)) { + eidasSuchdaten.add(buildEidasSuchData(cc, attrName, attrValue)); + + } + } + + private EidasSuchdatenType buildEidasSuchData(String cc, String attrName, String attrValue) { + EidasSuchdatenType eidasInfos = new EidasSuchdatenType(); + eidasInfos.setStaatscode2(cc); + eidasInfos.setEidasArt(attrName); + eidasInfos.setEidasWert(attrValue); + return eidasInfos; } -- cgit v1.2.3