From cdec2bbf39649f0fbe3d1655f5b47f62a5d0bae6 Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Thu, 25 Feb 2021 08:33:16 +0100 Subject: Prepare for Mockito testing of MobilePhoneSignature task --- connector/pom.xml | 27 ++++++++++++-------- eidas_modules/authmodule-eIDAS-v2/pom.xml | 25 +++++++++++-------- .../auth/eidas/v2/test/EidasSignalServletTest.java | 1 - ...eceiveMobilePhoneSignatureResponseTaskTest.java | 11 +++++++- pom.xml | 29 ++++++++++++++++------ 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index c2039ad7..0386e1f1 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -52,7 +52,7 @@ eaaf_module_pvp2_sp - + org.springframework.boot spring-boot-starter-actuator @@ -66,7 +66,7 @@ spring-boot-starter-tomcat - + de.codecentric spring-boot-admin-starter-client @@ -94,7 +94,7 @@ org.hibernate.validator hibernate-validator - + @@ -112,7 +112,7 @@ org.springframework.boot spring-boot-starter-test test - + at.gv.egiz.eaaf eaaf_core_utils @@ -135,11 +135,16 @@ spring-boot-starter-tomcat test + + org.springframework.boot + spring-boot-starter-test + test + at.gv.egiz.eaaf eaaf-springboot-utils test - + com.github.skjolber mockito-soap-cxf @@ -161,9 +166,9 @@ com.squareup.okhttp3 mockwebserver test - + - + default @@ -173,7 +178,7 @@ default - + javax.servlet javax.servlet-api @@ -191,12 +196,12 @@ at.gv.egiz.eaaf eaaf-springboot-utils - + - + - + ms_connector diff --git a/eidas_modules/authmodule-eIDAS-v2/pom.xml b/eidas_modules/authmodule-eIDAS-v2/pom.xml index 1b2681c3..561c4307 100644 --- a/eidas_modules/authmodule-eIDAS-v2/pom.xml +++ b/eidas_modules/authmodule-eIDAS-v2/pom.xml @@ -103,7 +103,7 @@ org.springframework.boot spring-boot-starter-actuator - + org.apache.commons commons-lang3 @@ -167,6 +167,11 @@ spring-test test + + org.springframework.boot + spring-boot-starter-test + test + com.github.skjolber mockito-soap-cxf @@ -184,14 +189,14 @@ 2.0.7 test - + at.asitplus.eidas.ms_specific connector_lib test test-jar - + at.gv.egiz.eaaf eaaf_core_utils @@ -209,19 +214,19 @@ eaaf_module_pvp2_core test test-jar - + at.gv.egiz.eaaf eaaf_module_pvp2_idp test test-jar - + com.squareup.okhttp3 mockwebserver test - + @@ -284,7 +289,7 @@ - + com.github.spotbugs spotbugs-maven-plugin @@ -312,8 +317,8 @@ **/org/w3/_2000/_09/* **/org/w3/_2001/_04/* **/szrservices/* - **/generated/cxf/* - + **/generated/cxf/* + @@ -335,4 +340,4 @@ - \ No newline at end of file + diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java index 62d5c556..f1987e33 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java @@ -52,7 +52,6 @@ import eu.eidas.specificcommunication.exception.SpecificCommunicationException; @ContextConfiguration(locations = { "/SpringTest-context_tasks_test.xml", "/SpringTest-context_basic_mapConfig.xml"}) -@EnableWebMvc public class EidasSignalServletTest { @Autowired private MsConnectorDummyConfigMap basicConfig; diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java index 5ea7b59b..c180e6f9 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java @@ -2,6 +2,7 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks; import at.asitplus.eidas.specific.connector.test.config.dummy.MsConnectorDummyConfigMap; import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.MergedRegisterSearchResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.InvalidUserInputException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.idaustriaclient.IdAustriaClientAuthConstants; @@ -31,12 +32,15 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; import org.opensaml.core.xml.io.MarshallingException; import org.opensaml.core.xml.util.XMLObjectSupport; import org.opensaml.saml.saml2.core.Issuer; import org.opensaml.saml.saml2.core.Response; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ContextConfiguration; @@ -49,9 +53,11 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.Collections; import java.util.Objects; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.eq; import static org.springframework.util.Assert.isInstanceOf; @RunWith(SpringJUnit4ClassRunner.class) @@ -73,6 +79,8 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { private PvpMetadataResolverFactory metadataFactory; @Autowired private ReceiveMobilePhoneSignatureResponseTask task; + @MockBean + private RegisterSearchService registerSearchService; private final ExecutionContext executionContext = new ExecutionContextImpl(); private MockHttpServletRequest httpReq; @@ -96,6 +104,7 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { */ @Before public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); httpReq.setScheme("https"); httpReq.setServerPort(443); @@ -320,13 +329,13 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { @Test public void httpPostValidSignedAssertionEidValid() throws Exception { - // klar darstellen: was ist input, was ist dann expected output ... eigentlich für alle tasks! metadataProvider.addMetadataResolverIntoChain(metadataFactory.createMetadataProvider( METADATA_PATH, null, "jUnit IDP", null)); initResponse("/data/Response_with_EID.xml", true); AuthProcessDataWrapper authProcessData = pendingReq.getSessionData(AuthProcessDataWrapper.class); SimpleEidasData eidData = createEidasDataMatchingToSamlResponse(); authProcessData.setGenericDataToSession(Constants.DATA_SIMPLE_EIDAS, eidData); + Mockito.when(registerSearchService.searchWithBpkZp(eq("BF:QVGm48cqcM4UcyhDTNGYmVdrIoY="))).thenReturn(new MergedRegisterSearchResult(Collections.emptyList(), Collections.emptyList())); task.execute(pendingReq, executionContext); diff --git a/pom.xml b/pom.xml index 796b640c..734ce689 100644 --- a/pom.xml +++ b/pom.xml @@ -10,12 +10,12 @@ MS specific eIDAS components - + UTF-8 ${maven.build.timestamp} yyyy-MM-dd HH:mm - + ${project.version} @@ -82,6 +82,16 @@ + + central + https://repo.maven.apache.org/maven2 + + never + + + false + + egiz-commons https://apps.egiz.gv.at/maven/ @@ -231,7 +241,6 @@ spring-boot-admin-starter-client ${spring-boot-admin-starter-client.version} - org.springframework spring-webmvc @@ -333,7 +342,13 @@ spring-boot-starter-test ${spring-boot-starter-web.version} test - + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot-starter-web.version} + test + com.github.skjolber mockito-soap-cxf @@ -360,14 +375,14 @@ ${eaaf-core.version} test test-jar - + at.gv.egiz.eaaf eaaf_module_pvp2_idp ${eaaf-core.version} test test-jar - + at.asitplus.eidas.ms_specific connector_lib @@ -599,7 +614,7 @@ - false + false utf-8 100 1.8 -- cgit v1.2.3