diff options
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java')
-rw-r--r-- | eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java | 131 |
1 files changed, 73 insertions, 58 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java index 086a1817..c957e20c 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java @@ -44,6 +44,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.binding.soap.SoapFault; import org.junit.Assert; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Rule; @@ -74,7 +75,17 @@ import at.gv.egiz.eaaf.core.exceptions.EaafParserException; import at.gv.egiz.eaaf.core.impl.data.Triple; import at.gv.egiz.eaaf.core.impl.idp.auth.data.SimpleIdentityLinkAssertionParser; import at.gv.egiz.eaaf.core.impl.utils.DomUtils; -import szrservices.*; +import szrservices.GetBPKFromStammzahlEncryptedResponse; +import szrservices.GetBPKFromStammzahlEncryptedResponseType; +import szrservices.GetIdentityLinkEidasResponse; +import szrservices.IdentityLinkType; +import szrservices.PersonInfoType; +import szrservices.SZR; +import szrservices.SZRException_Exception; +import szrservices.SignContentEntry; +import szrservices.SignContentResponse; +import szrservices.SignContentResponseType; +import szrservices.TravelDocumentType; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/SpringTest-context_tasks_test.xml") @@ -92,6 +103,12 @@ public class SzrClientTest { private static final String eIDASeID = "IS/AT/1234sdgsdfg56789ABCDEF"; private static final String DUMMY_TARGET = EaafConstants.URN_PREFIX_CDID + "ZP"; + private SZR szrMock = null; + + + @Rule + public SoapServiceRule soap = SoapServiceRule.newInstance(); + /** * jUnit class initializer. * @@ -104,56 +121,59 @@ public class SzrClientTest { } - @Rule - public SoapServiceRule soap = SoapServiceRule.newInstance(); + /** + * Initialize jUnit test. + * + */ + @Before + public void initializer() { + if (szrMock == null) { + szrMock = soap.mock(SZR.class, "http://localhost:1234/demoszr"); + + } + } + + + @Test + public void getStammzahlenEcryptedTest() throws JAXBException, SZRException_Exception { + final GetBPKFromStammzahlEncryptedResponse szrResponse = new GetBPKFromStammzahlEncryptedResponse(); + final GetBPKFromStammzahlEncryptedResponseType result1 = new GetBPKFromStammzahlEncryptedResponseType(); + szrResponse.getOut().add(result1); + + when(szrMock.getBPKFromStammzahlEncrypted(anyList())) + .thenReturn(Arrays.asList(result1)); + +// szrMock.getStammzahlEncrypted() TODO ??? + } + @Test + public void getBcBindValid() throws SZRException_Exception, SzrCommunicationException { + final SignContentResponse szrResponse = new SignContentResponse(); + final SignContentEntry result1 = new SignContentEntry(); + final SignContentResponseType content = new SignContentResponseType(); + content.getOut().add(result1); + szrResponse.setSignContentResponse(content); + + result1.setKey("bcBindReq"); + result1.setValue(RandomStringUtils.randomAlphanumeric(100)); + when(szrMock.signContent(any(), anyList(), anyList())).thenReturn(content); -// @Test -//public void getStammzahlenEcryptedTest() throws JAXBException, SZRException_Exception { -// SZR szrMock = soap.mock(SZR.class, "http://localhost:1234/demoszr"); -// -// final GetBPKFromStammzahlEncryptedResponse szrResponse = new GetBPKFromStammzahlEncryptedResponse(); -// final GetBPKFromStammzahlEncryptedResponseType result1 = new GetBPKFromStammzahlEncryptedResponseType(); -// szrResponse.getOut().add(result1); -// -// when(szrMock.getBPKFromStammzahlEncrypted(anyList())) -// .thenReturn(Arrays.asList(result1)); -// -//// szrMock.getStammzahlEncrypted() TODO ??? -// } -// -// @Test -// public void getBcBindValid() throws SZRException_Exception, SzrCommunicationException { -// SZR szrMock = soap.mock(SZR.class, "http://localhost:1234/demoszr"); -// -// final SignContentResponse szrResponse = new SignContentResponse(); -// final SignContentEntry result1 = new SignContentEntry(); -// final SignContentResponseType content = new SignContentResponseType(); -// content.getOut().add(result1); -// szrResponse.setSignContentResponse(content); -// -// result1.setKey("bcBindReq"); -// result1.setValue(RandomStringUtils.randomAlphanumeric(100)); -// -// when(szrMock.signContent(any(), anyList(), anyList())).thenReturn(content); -// -// final String bcBind = szrClient.getBcBind( -// RandomStringUtils.randomAlphabetic(10), -// RandomStringUtils.randomAlphabetic(10), -// RandomStringUtils.randomAlphabetic(10)); -// -// Assert.assertNotNull("bcBind is null", bcBind); -// Assert.assertEquals("bcBind not match", result1.getValue(), bcBind); -// -// -// } + final String bcBind = szrClient.getBcBind( + RandomStringUtils.randomAlphabetic(10), + RandomStringUtils.randomAlphabetic(10), + RandomStringUtils.randomAlphabetic(10)); + Assert.assertNotNull("bcBind is null", bcBind); + Assert.assertEquals("bcBind not match", result1.getValue(), bcBind); + + } @Test public void getIdentityLinkRawModeValidResponse() throws SZRException_Exception, EaafParserException, - NoSuchProviderException, IOException, InvalidKeyException, EidasSAuthenticationException, JAXBException { - setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml", "http://localhost:1234/demoszr"); + NoSuchProviderException, IOException, InvalidKeyException, EidasSAuthenticationException, + JAXBException { + setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml"); try { log.debug("Starting connecting SZR Gateway"); @@ -188,8 +208,7 @@ public class SzrClientTest { public void getIdentityLinkRawModeErrorTravelerDocExists() throws SZRException_Exception, EaafParserException, NoSuchProviderException, IOException, InvalidKeyException, EidasSAuthenticationException, JAXBException, ParserConfigurationException, SAXException { - setSzrExceptionIdentityLink("/data/szr/szr_resp_error_travelerdocexists.xml", - "http://localhost:1234/demoszr"); + setSzrExceptionIdentityLink("/data/szr/szr_resp_error_travelerdocexists.xml"); try { log.debug("Starting connecting SZR Gateway"); @@ -221,11 +240,11 @@ public class SzrClientTest { "no VKZ defined")); if (bPK.isEmpty()) { - throw new SzrCommunicationException("ernb.01", new Object[]{"bPK list is empty"}); + throw new SzrCommunicationException("ernb.01", new Object[] { "bPK list is empty" }); } - for (String b : bPK) { + for (final String b : bPK) { if (StringUtils.isEmpty(b)) { - throw new SzrCommunicationException("ernb.01", new Object[]{"bPK is null or empty"}); + throw new SzrCommunicationException("ernb.01", new Object[] { "bPK is null or empty" }); } } @@ -237,27 +256,23 @@ public class SzrClientTest { } - private void setSzrResponseIdentityLink(String responseXmlPath, String serviceUrl) throws JAXBException, + private void setSzrResponseIdentityLink(String responseXmlPath) throws JAXBException, SZRException_Exception { - final SZR szrServiceMock = soap.mock(SZR.class, serviceUrl); final JAXBContext jaxbContext = JAXBContext.newInstance( szrservices.ObjectFactory.class, - org.xmlsoap.schemas.ws._2002._04.secext.ObjectFactory.class, org.w3._2001._04.xmldsig_more.ObjectFactory.class, org.w3._2000._09.xmldsig.ObjectFactory.class, - at.gv.egov.pvp1.ObjectFactory.class, at.gv.e_government.reference.namespace.persondata._20020228.ObjectFactory.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final GetIdentityLinkEidasResponse szrResponse = (GetIdentityLinkEidasResponse) jaxbUnmarshaller .unmarshal(this.getClass().getResourceAsStream(responseXmlPath)); - when(szrServiceMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenReturn(szrResponse + when(szrMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenReturn(szrResponse .getGetIdentityLinkReturn()); } - private void setSzrExceptionIdentityLink(String responseXmlPath, String serviceUrl) throws JAXBException, + private void setSzrExceptionIdentityLink(String responseXmlPath) 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"); @@ -267,7 +282,7 @@ public class SzrClientTest { qName); fault.setRole("urn:SZRServices"); fault.setDetail(detailerror); - when(szrServiceMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenThrow(fault); + when(szrMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenThrow(fault); } @@ -279,7 +294,7 @@ public class SzrClientTest { return hashBase64; } catch (final Exception ex) { - throw new EidasSAuthenticationException("internal.03", new Object[]{}, ex); + throw new EidasSAuthenticationException("internal.03", new Object[] {}, ex); } } |