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 --- eidas_modules/authmodule-eIDAS-v2/pom.xml | 25 +++++++++++++--------- .../auth/eidas/v2/test/EidasSignalServletTest.java | 1 - ...eceiveMobilePhoneSignatureResponseTaskTest.java | 11 +++++++++- 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'eidas_modules/authmodule-eIDAS-v2') 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); -- cgit v1.2.3