aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-11-03 11:43:11 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-11-03 11:43:11 +0100
commit5c1635840f3e0826d0003f915d29b01e62344e4f (patch)
tree352fed195e6c24ce14ef3bc00c63b112a5e32c21 /eidas_modules
parent578841c3723da27525d5fffb37d4ccc3dffa7bb4 (diff)
downloadNational_eIDAS_Gateway-5c1635840f3e0826d0003f915d29b01e62344e4f.tar.gz
National_eIDAS_Gateway-5c1635840f3e0826d0003f915d29b01e62344e4f.tar.bz2
National_eIDAS_Gateway-5c1635840f3e0826d0003f915d29b01e62344e4f.zip
fix broken jUnit tests that use SZR MockUp
Diffstat (limited to 'eidas_modules')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java131
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java97
2 files changed, 111 insertions, 117 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);
}
}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
index 7a214744..031ea825 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateIdentityLinkTaskEidNewTest.java
@@ -1,82 +1,59 @@
package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;
+import static org.mockito.ArgumentMatchers.any;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.jetbrains.annotations.NotNull;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import com.skjolberg.mockito.soap.SoapServiceRule;
+
import at.asitplus.eidas.specific.connector.MsEidasNodeConstants;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
-import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.DeEidProcessor;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.EidasAttributeRegistry;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.CreateIdentityLinkTask;
-import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.GenerateAuthnRequestTask;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.test.dummy.DummySpecificCommunicationService;
-import at.gv.e_government.reference.namespace.persondata._20020228.PostalAddressType;
import at.gv.egiz.eaaf.core.api.data.EaafConfigConstants;
import at.gv.egiz.eaaf.core.api.data.EaafConstants;
import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext;
-import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
-import at.gv.egiz.eaaf.core.exceptions.EaafException;
import at.gv.egiz.eaaf.core.exceptions.EaafStorageException;
-import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper;
-import at.gv.egiz.eaaf.core.impl.idp.controller.tasks.FinalizeAuthenticationTask;
import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySpConfiguration;
import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.Maps;
-import com.skjolberg.mockito.soap.SoapServiceRule;
-import eu.eidas.auth.commons.EIDASStatusCode;
import eu.eidas.auth.commons.attribute.AttributeDefinition;
-import eu.eidas.auth.commons.attribute.AttributeValueMarshaller;
import eu.eidas.auth.commons.attribute.ImmutableAttributeMap;
import eu.eidas.auth.commons.attribute.PersonType;
-import eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller;
-import eu.eidas.auth.commons.attribute.impl.StringAttributeValueMarshaller;
-import eu.eidas.auth.commons.light.ILightRequest;
-import eu.eidas.auth.commons.light.ILightResponse;
-import eu.eidas.auth.commons.light.impl.LightRequest;
-import eu.eidas.auth.commons.light.impl.LightResponse;
-import eu.eidas.auth.commons.light.impl.ResponseStatus;
import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse;
-import eu.eidas.specificcommunication.exception.SpecificCommunicationException;
import lombok.val;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.jetbrains.annotations.NotNull;
-import org.joda.time.DateTime;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.internal.builders.JUnit3Builder;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatchers;
-import org.mockito.Mockito;
-import org.mockito.Spy;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-import szrservices.*;
-
-import javax.xml.namespace.QName;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.powermock.api.mockito.PowerMockito.*;
+import szrservices.PersonInfoType;
+import szrservices.SZR;
+import szrservices.SignContentEntry;
+import szrservices.SignContentResponseType;
@RunWith(SpringJUnit4ClassRunner.class)
//@RunWith(PowerMockRunner.class)
@@ -104,7 +81,9 @@ public class CreateIdentityLinkTaskEidNewTest {
private TestRequestImpl pendingReq;
private DummySpConfiguration oaParam;
private SZR szrMock;
- final SoapServiceRule soap = SoapServiceRule.newInstance();
+
+ @Rule
+ public final SoapServiceRule soap = SoapServiceRule.newInstance();
/**
* jUnit class initializer.