aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2019-08-06 08:15:52 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2019-08-06 08:15:52 +0200
commit204bb9f7c21964377455563a5e106ea191c1d590 (patch)
treee32afd88df9a5538e792341e7cd7540802adc0af /eidas_modules/authmodule-eIDAS-v2
parent36a0c4b55779c138235ae37216b900415a64f0eb (diff)
downloadNational_eIDAS_Gateway-204bb9f7c21964377455563a5e106ea191c1d590.tar.gz
National_eIDAS_Gateway-204bb9f7c21964377455563a5e106ea191c1d590.tar.bz2
National_eIDAS_Gateway-204bb9f7c21964377455563a5e106ea191c1d590.zip
add jUnit test with mockup of SZR WebService
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/szr/SZRClient.java5
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTest.java111
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTestProduction.java3
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/szr/szr_resp_error_travelerdocexists.xml6
4 files changed, 83 insertions, 42 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/szr/SZRClient.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/szr/SZRClient.java
index d004ac0e..9d213109 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/szr/SZRClient.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/szr/SZRClient.java
@@ -161,10 +161,7 @@ public class SZRClient {
idl.setPersonInfo(jaxbElement.getGetIdentityLinkReturn().getPersonInfo());
return idl;
-
-
- //IdentityLinkType idlResp = this.szr.getIdentityLink(personInfo, keyValue, insertERnP);
-
+
} catch ( Exception e) {
log.warn("SZR communication FAILED. Reason: " + e.getMessage(), e);
throw new SZRCommunicationException("ernb.02", new Object[] {e.getMessage()}, e);
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTest.java
index 01af6b00..3e903849 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTest.java
@@ -34,8 +34,12 @@ import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.ws.soap.SOAPFaultException;
import org.apache.commons.lang3.StringUtils;
+import org.apache.cxf.binding.soap.SoapFault;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
@@ -49,6 +53,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Base64Utils;
import org.w3._2000._09.xmldsig.KeyValueType;
import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
import com.skjolberg.mockito.soap.SoapServiceRule;
@@ -65,6 +70,7 @@ import at.gv.egiz.eaaf.core.api.idp.auth.data.IIdentityLink;
import at.gv.egiz.eaaf.core.exceptions.EAAFParserException;
import at.gv.egiz.eaaf.core.impl.data.Trible;
import at.gv.egiz.eaaf.core.impl.idp.auth.data.SimpleIdentityLinkAssertionParser;
+import at.gv.egiz.eaaf.core.impl.utils.DOMUtils;
import szrservices.GetIdentityLinkEidasResponse;
import szrservices.IdentityLinkType;
import szrservices.PersonInfoType;
@@ -102,46 +108,59 @@ public class SZRClientTest {
public SoapServiceRule soap = SoapServiceRule.newInstance();
@Test
- public void getIdentityLinkRawMode() throws SZRException_Exception, EAAFParserException, NoSuchProviderException, IOException, InvalidKeyException, eIDASAuthenticationException, JAXBException {
- setSZRResponse("/data/szr/szr_resp_valid_1.xml", "http://localhost/demoszr");
-
- log.debug("Starting connecting SZR Gateway");
- IdentityLinkType result = szrClient.getIdentityLinkInRawMode(
- getPersonInfo());
-
- Element idlFromSZR = (Element)result.getAssertion();
- IIdentityLink identityLink = new SimpleIdentityLinkAssertionParser(idlFromSZR).parseIdentityLink();
-
- if (identityLink == null)
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO IDL object"});
-
- System.out.println(identityLink.getSerializedSamlAssertion());
-
- if (StringUtils.isEmpty(identityLink.getFamilyName()))
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO FamilyName from IDL"});
-
- if (StringUtils.isEmpty(identityLink.getGivenName()))
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO GivenName from IDL"});
-
- if (StringUtils.isEmpty(identityLink.getDateOfBirth()))
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO DateOfBirthName from IDL"});
-
- if (StringUtils.isEmpty(identityLink.getIdentificationType()))
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO baseIdType from IDL"});
-
- if (StringUtils.isEmpty(identityLink.getIdentificationValue()))
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO baseId from IDL"});
-
- if (StringUtils.isEmpty(identityLink.getSerializedSamlAssertion()))
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO serialized IDL"});
-
- if (identityLink.getSamlAssertion() == null )
- throw new SZRCommunicationException("ernb.00", new Object[] {"NO raw IDL"});
+ public void getIdentityLinkRawModeValidResponse() throws SZRException_Exception, EAAFParserException, NoSuchProviderException, IOException, InvalidKeyException, eIDASAuthenticationException, JAXBException {
+ setSZRResponseIdentityLink("/data/szr/szr_resp_valid_1.xml", "http://localhost/demoszr");
+ try {
+ log.debug("Starting connecting SZR Gateway");
+ IdentityLinkType result = szrClient.getIdentityLinkInRawMode(
+ getPersonInfo());
-
+ Assert.assertNotNull(result);
+ Assert.assertNotNull(result.getAssertion());
+
+ IIdentityLink identityLink = new SimpleIdentityLinkAssertionParser((Element)result.getAssertion()).parseIdentityLink();
+ Assert.assertNotNull(identityLink);
+
+ System.out.println(identityLink.getSerializedSamlAssertion());
+
+ checkElement("Mustermann", identityLink.getFamilyName());
+ checkElement("Hans", identityLink.getGivenName());
+ checkElement("1989-05-05", identityLink.getDateOfBirth());
+ checkElement("urn:publicid:gv.at:baseid", identityLink.getIdentificationType());
+ checkElement("k+zDM1BVpN1WJO4x7ZQ3ng==", identityLink.getIdentificationValue());
+ Assert.assertNotNull(identityLink.getSerializedSamlAssertion());
+ Assert.assertNotNull(identityLink.getSamlAssertion());
+
+ } catch (SZRCommunicationException e) {
+ Assert.fail();
+
+ }
+
}
+ @Test
+ public void getIdentityLinkRawModeErrorTravelerDocExists() throws SZRException_Exception, EAAFParserException, NoSuchProviderException, IOException, InvalidKeyException, eIDASAuthenticationException, JAXBException, ParserConfigurationException, SAXException {
+ setSZRExceptionIdentityLink("/data/szr/szr_resp_error_travelerdocexists.xml", "http://localhost/demoszr");
+
+ try {
+ log.debug("Starting connecting SZR Gateway");
+ IdentityLinkType result = szrClient.getIdentityLinkInRawMode(
+ getPersonInfo());
+ Assert.fail();
+
+ } catch (SZRCommunicationException e) {
+ checkElement("ernb.02", e.getErrorId());
+ Assert.assertNotNull(e.getCause());
+ org.springframework.util.Assert.isInstanceOf(SOAPFaultException.class, e.getCause());
+ Assert.assertNotNull(((SOAPFaultException)e.getCause()).getFault());
+ checkElement("p344:F455", ((SOAPFaultException)e.getCause()).getFault().getFaultCode());
+ checkElement("The travel document you sent to insert a person already exists for another person. Either check the document or have the person altered accordingly", ((SOAPFaultException)e.getCause()).getFault().getFaultString());
+
+ }
+
+ }
+
@Ignore
@Test
public void getbPKTest() throws SZRException_Exception, eIDASAuthenticationException {
@@ -156,7 +175,14 @@ public class SZRClientTest {
}
- private void setSZRResponse(String responseXmlPath, String serviceURL) throws JAXBException, SZRException_Exception {
+ private void checkElement(String expected, String value) {
+ Assert.assertNotNull(value);
+ Assert.assertEquals(expected, value);
+
+ }
+
+
+ private void setSZRResponseIdentityLink(String responseXmlPath, String serviceURL) throws JAXBException, SZRException_Exception {
final SZR szrServiceMock = soap.mock(SZR.class, serviceURL);
final JAXBContext jaxbContext = JAXBContext.newInstance(
szrservices.ObjectFactory.class,
@@ -171,6 +197,17 @@ public class SZRClientTest {
}
+ private void setSZRExceptionIdentityLink(String responseXmlPath, String serviceURL) throws JAXBException,ParserConfigurationException, SAXException, IOException, SZRException_Exception {
+ final SZR szrServiceMock = soap.mock(SZR.class, serviceURL);
+ final Element detailerror = DOMUtils.parseXmlNonValidating(this.getClass().getResourceAsStream(responseXmlPath));
+ final javax.xml.namespace.QName qName = new javax.xml.namespace.QName("urn:SZRServices","F455", "p344");
+ final SoapFault fault = new SoapFault("The travel document you sent to insert a person already exists for another person. Either check the document or have the person altered accordingly", qName);
+ fault.setRole("urn:SZRServices");
+ fault.setDetail(detailerror);
+ when(szrServiceMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenThrow(fault);
+
+ }
+
private String createHashFromUniqueId(String uniqueId) throws eIDASAuthenticationException {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTestProduction.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTestProduction.java
index 065c13f8..db4f2417 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTestProduction.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/SZRClientTestProduction.java
@@ -70,7 +70,8 @@ public class SZRClientTestProduction {
private static final String givenName = "Franz";
private static final String familyName = "Mustermann";
- private static final String dateOfBirth = "1989-05-05";
+ //private static final String dateOfBirth = "1989-05-05";
+ private static final String dateOfBirth = "1989-05-04";
private static final String eIDASeID = "IS/AT/1234sdgsdfg56789ABCDEF";
//Dummy public RSA Key
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/szr/szr_resp_error_travelerdocexists.xml b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/szr/szr_resp_error_travelerdocexists.xml
new file mode 100644
index 00000000..d627ded2
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/data/szr/szr_resp_error_travelerdocexists.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+ <faultcode xmlns:p344="urn:SZRServices" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">p344:F455</faultcode>
+ <faultstring>The travel document you sent to insert a person already exists for another person. Either check the document or have the person altered accordingly</faultstring>
+ <faultactor>urn:SZRServices</faultactor>
+</SOAP-ENV:Fault>