aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas <>2022-02-03 20:30:45 +0100
committerThomas <>2022-02-08 09:37:25 +0100
commit0908fbc33f0ba7a1811cc988a30b571ab53ffa99 (patch)
treeae01784a69209a75b806a9fb2461d6fc14b730a2
parent8d4680da725db89c5fc11767d8892f3fb16aa0e7 (diff)
downloadNational_eIDAS_Gateway-0908fbc33f0ba7a1811cc988a30b571ab53ffa99.tar.gz
National_eIDAS_Gateway-0908fbc33f0ba7a1811cc988a30b571ab53ffa99.tar.bz2
National_eIDAS_Gateway-0908fbc33f0ba7a1811cc988a30b571ab53ffa99.zip
test(ernp): add first simple test to get familary with ERnP client
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java132
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/ernp_handbook_example.json85
2 files changed, 217 insertions, 0 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java
new file mode 100644
index 00000000..9eb574fd
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/clients/ErnpRestClientTest.java
@@ -0,0 +1,132 @@
+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 org.apache.commons.io.IOUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import at.asitplus.eidas.specific.connector.test.config.dummy.MsConnectorDummyConfigMap;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.ErnpRestClient.ErnpRegisterResult;
+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 lombok.SneakyThrows;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import okhttp3.mockwebserver.RecordedRequest;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {
+ "/SpringTest-context_tasks_test.xml",
+ "/SpringTest-context_basic_mapConfig.xml" })
+@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
+public class ErnpRestClientTest {
+
+ @Autowired MsConnectorDummyConfigMap basicConfig;
+ @Autowired IErnpClient client;
+
+ private static MockWebServer mockWebServer;
+
+ /**
+ * JUnit class initializer.
+ *
+ * @throws Exception In case of an OpenSAML3 initialization error
+ */
+ @BeforeClass
+ @SneakyThrows
+ public static void classInitializer() {
+ mockWebServer = new MockWebServer();
+ mockWebServer.start(1718);
+
+ }
+
+ @AfterClass
+ @SneakyThrows
+ public static void resetTestEnviroment() {
+ mockWebServer.shutdown();
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void searchWithPersonalIdentifierServerError() {
+ final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit";
+ final String cc = "DE";
+ final SimpleEidasData eidasDataFirst = SimpleEidasData.builder()
+ .citizenCountryCode(cc)
+ .familyName("XXXvon Brandenburg")
+ .givenName("XXXClaus - Maria")
+ .dateOfBirth("1994-12-31")
+ .personalIdentifier(cc + "/AT/" + personalIdentifierFirst)
+ .pseudonym(personalIdentifierFirst)
+ .build();
+
+ // set ERnP response
+ mockWebServer.enqueue(new MockResponse().setResponseCode(500)
+ .setBody("Internal error"));
+
+ // execute operation
+ EidasSAuthenticationException error = assertThrows("wrong Exception", EidasSAuthenticationException.class,
+ () -> client.searchWithPersonIdentifier(
+ eidasDataFirst.getPseudonym(), eidasDataFirst.getCitizenCountryCode()));
+
+ assertEquals("wrong errorCode", "module.eidasauth.matching.11", error.getErrorId());
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void searchWithPersonalIdentifierSuccess() {
+ final String personalIdentifierFirst = "7cEYWithDEElementsasdfsafsaf4CDVzNT4E7cjkU4VqForjUnit";
+ final String cc = "DE";
+ final SimpleEidasData eidasDataFirst = SimpleEidasData.builder()
+ .citizenCountryCode(cc)
+ .familyName("XXXvon Brandenburg")
+ .givenName("XXXClaus - Maria")
+ .dateOfBirth("1994-12-31")
+ .personalIdentifier(cc + "/AT/" + personalIdentifierFirst)
+ .pseudonym(personalIdentifierFirst)
+ .build();
+
+
+ // set ERnP response
+ mockWebServer.enqueue(new MockResponse().setResponseCode(200)
+ .setBody(IOUtils.toString(
+ ErnpRestClientTest.class.getResourceAsStream("/data/ernp/ernp_handbook_example.json"),
+ "UTF-8"))
+ .setHeader("Content-Type", "application/json;charset=utf-8"));
+
+
+ // execute operation
+ ErnpRegisterResult resp = client.searchWithPersonIdentifier(
+ eidasDataFirst.getPseudonym(), eidasDataFirst.getCitizenCountryCode());
+
+ // validate request
+ final RecordedRequest request = mockWebServer.takeRequest();
+ String reqBody = request.getBody().readUtf8();
+ assertFalse("no request body", reqBody.isEmpty());
+
+ // validate state
+ assertNotNull("no ERnP response", resp);
+ assertEquals("wrong resp size", 1, resp.getPersonResult().size());
+
+ RegisterResult persInfo = resp.getPersonResult().get(0);
+ assertEquals("wrong familyname", "XXXSZR", persInfo.getFamilyName());
+
+
+ }
+
+
+}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/ernp_handbook_example.json b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/ernp_handbook_example.json
new file mode 100644
index 00000000..f4485ff7
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/ernp/ernp_handbook_example.json
@@ -0,0 +1,85 @@
+{
+ "person": [
+ {
+ "type": "Person",
+ "anschrift": {
+ "type": "AnschriftInland",
+ "adressstatus": "XXXXXXXXX",
+ "codes": {
+ "gemeindekennziffer": "09988",
+ "strassenkennziffer": "T80001"
+ },
+ "entityId": 33069800000171092,
+ "gemeinde": "Testgemeinde",
+ "gueltigAb": "2011-09-06T11:23:55.306+02:00",
+ "hausnummer": "99",
+ "postleitzahl": "0077",
+ "postort": "Testpostort 77 mit maximalmögl. Längen",
+ "staat": {
+ "isoCode3": "AUT",
+ "name": "Österreich"
+ },
+ "strasse": "Testgasse"
+ },
+ "entityId": 33069800000171080,
+ "gueltigAb": "2011-09-06T11:23:55.306+02:00",
+ "letzteOperation": {
+ "begruendung": "Testperson",
+ "durchgefuehrtVon": {
+ "behoerdenkennzeichen": "346743",
+ "benutzer": "xlechne@bmi.gv.at"
+ },
+ "vorgang": "PERSON_ANLEGEN",
+ "zeitpunkt": "2011-09-06T11:23:55.306+02:00"
+ },
+ "personendaten": {
+ "basiszahl": "000766083209",
+ "bpkZp": "BC1ifQanMKaDQG0yLBPbQ9AHgb4=",
+ "entityId": 33069800000171080,
+ "familienname": "XXXSZR",
+ "geburtsbundesland": "Wien",
+ "geburtsdatum": {
+ "jahr": 1985,
+ "monat": 1,
+ "tag": 1
+ },
+ "geburtsort": "Wien",
+ "geburtsstaat": {
+ "isoCode3": "AUT",
+ "name": "Österreich"
+ },
+ "geprueft": true,
+ "geschlecht": "Männlich",
+ "gueltigAb": "2011-09-06T11:23:55.306+02:00",
+ "vorname": "XXXTest"
+ },
+ "reisedokument": [
+ {
+ "art": "Personalausweis",
+ "ausgestelltVon": {
+ "behoerde": "Wien",
+ "datum": "1985-01-01T00:00:00.000+01:00",
+ "staat": {
+ "isoCode3": "AUT",
+ "name": "Österreich"
+ }
+ },
+ "entityId": 33069800000171090,
+ "gueltigAb": "2011-09-06T11:23:55.306+02:00",
+ "nummer": "123456789"
+ }
+ ],
+ "staatsangehoerigkeit": [
+ {
+ "entityId": 33069800000171084,
+ "gueltigAb": "2011-09-06T11:23:55.306+02:00",
+ "staat": {
+ "isoCode3": "AUT",
+ "name": "Österreich"
+ }
+ }
+ ],
+ "version": "2011-09-06T11:23:55.306+02:00"
+ }
+ ]
+} \ No newline at end of file