diff options
author | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2020-12-09 08:53:28 +0100 |
---|---|---|
committer | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-01-04 14:15:40 +0100 |
commit | d1c4bc0619b95564f6f7db5798479449e88e4793 (patch) | |
tree | f0fb2fcdf1cbe316d0965bb4493881d4466d99a4 /eidas_modules | |
parent | 078fb6a05a4bff2bb7595458b4154f76fe1caea7 (diff) | |
download | National_eIDAS_Gateway-d1c4bc0619b95564f6f7db5798479449e88e4793.tar.gz National_eIDAS_Gateway-d1c4bc0619b95564f6f7db5798479449e88e4793.tar.bz2 National_eIDAS_Gateway-d1c4bc0619b95564f6f7db5798479449e88e4793.zip |
added (non working) test
Diffstat (limited to 'eidas_modules')
3 files changed, 178 insertions, 11 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java index 6f4cfefc..907ed443 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java @@ -64,7 +64,7 @@ import java.util.List; import java.util.Map; /** - * Task that creates the IdentityLink for an eIDAS authenticated person. + * Task that searches ErnB and ZMR before adding person to SZR. * * @author tlenz */ @@ -150,16 +150,13 @@ public class InitialSearchTask extends AbstractAuthServletTask { String personIdentifier = eidData.getPseudonym(); //search in register(step 2) MergedRegisterSearchResult result = searchInZmrAndErnp(personIdentifier); - switch (result.getResultCount()) { - case 0: - step5(result, eidData); - break; - case 1: - step3(result, eidData); - break; - default://should not happen - throw new TaskExecutionException(pendingReq, "Initial search - Kitt Process necessary.", - new ManualFixNecessaryException(personIdentifier)); + if (result.getResultCount() == 0) { + step5(result, eidData); + } else if (result.getResultCount() == 1) { + step3(result, eidData); + } else if (result.getResultCount() > 1) { + throw new TaskExecutionException(pendingReq, "Initial search - Kitt Process necessary.", + new ManualFixNecessaryException(personIdentifier)); } } diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java new file mode 100644 index 00000000..30f88ec8 --- /dev/null +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java @@ -0,0 +1,160 @@ +package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks; + +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.dao.SimpleEidasData; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.InitialSearchTask; +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.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.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 eu.eidas.auth.commons.attribute.AttributeDefinition; +import eu.eidas.auth.commons.attribute.ImmutableAttributeMap; +import eu.eidas.auth.commons.attribute.PersonType; +import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse; +import lombok.val; +import org.apache.commons.lang3.RandomStringUtils; +import org.jetbrains.annotations.NotNull; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.powermock.api.mockito.PowerMockito; +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.annotation.DirtiesContext.ClassMode; +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 javax.xml.namespace.QName; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import static org.mockito.Mockito.times; +import static org.powermock.api.mockito.PowerMockito.verifyPrivate; + +@RunWith(SpringJUnit4ClassRunner.class) +//@RunWith(PowerMockRunner.class) +//@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class) +@ContextConfiguration("/SpringTest-context_tasks_test.xml") +@DirtiesContext(classMode = ClassMode.BEFORE_CLASS) +//@RunWith(PowerMockRunner.class) +//@PrepareForTest(InitialSearchTaskFirstTest.class) +public class InitialSearchTaskFirstTest { + + @Autowired(required = true) + @Mock + private InitialSearchTask task; + + @Autowired(required = true) + private IConfiguration basicConfig; + + final ExecutionContext executionContext = new ExecutionContextImpl(); + private MockHttpServletRequest httpReq; + private MockHttpServletResponse httpResp; + private TestRequestImpl pendingReq; + private DummySpConfiguration oaParam; + + /** + * jUnit class initializer. + * + * @throws IOException In case of an error + */ + @BeforeClass + public static void classInitializer() throws IOException { + final String current = new java.io.File(".").toURI().toString(); + System.setProperty("eidas.ms.configuration", current + + "src/test/resources/config/junit_config_1.properties"); + + } + + /** + * jUnit test set-up. + * + */ + @Before + public void setUp() throws URISyntaxException, EaafStorageException { + + task = PowerMockito.spy(task); + + httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); + httpResp = new MockHttpServletResponse(); + RequestContextHolder.resetRequestAttributes(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); + + final AuthenticationResponse response = buildDummyAuthResponse(); + pendingReq = new TestRequestImpl(); + pendingReq.getSessionData(AuthProcessDataWrapper.class) + .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); + + } + + @Test + @DirtiesContext + public void testInitialSearch() throws Exception { + + try { + task.execute(pendingReq, executionContext); + + } catch (final TaskExecutionException e) { + // forward URL is not set in example config + // org.springframework.util.Assert.isInstanceOf(EaafConfigurationException.class, e.getOriginalException(), + // "Wrong exception"); + // Assert.assertEquals("wrong errorCode", "config.08", ((EaafException) e.getOriginalException()) + // .getErrorId()); + // Assert.assertEquals("wrong parameter size", 1, ((EaafException) e.getOriginalException()) + // .getParams().length); + // Assert.assertEquals("wrong errorMsg", Constants.CONIG_PROPS_EIDAS_NODE_FORWARD_URL, ((EaafException) e + // .getOriginalException()).getParams()[0]); + + } +// verifyPrivate(task, times(1)).invoke("step2", ArgumentMatchers.any(SimpleEidasData.class)); +// verifyPrivate(task, times(0)).invoke("step3", ArgumentMatchers.any()); +// verifyPrivate(task, times(0)).invoke("step4", ArgumentMatchers.any()); + + } + + + @NotNull + private AuthenticationResponse buildDummyAuthResponse() throws URISyntaxException { + final AttributeDefinition attributeDef = AttributeDefinition.builder() + .friendlyName(Constants.eIDAS_ATTR_PERSONALIDENTIFIER).nameUri(new URI("ad", "sd", "ff")) + .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "af")) + .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); + final AttributeDefinition attributeDef2 = AttributeDefinition.builder() + .friendlyName(Constants.eIDAS_ATTR_CURRENTFAMILYNAME).nameUri(new URI("ad", "sd", "fff")) + .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "aff")) + .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); + final AttributeDefinition attributeDef3 = AttributeDefinition.builder() + .friendlyName(Constants.eIDAS_ATTR_CURRENTGIVENNAME).nameUri(new URI("ad", "sd", "ffff")) + .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "afff")) + .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); + final AttributeDefinition attributeDef4 = AttributeDefinition.builder() + .friendlyName(Constants.eIDAS_ATTR_DATEOFBIRTH).nameUri(new URI("ad", "sd", "fffff")) + .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "affff")) + .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.DateTimeAttributeValueMarshaller").build(); + + final ImmutableAttributeMap attributeMap = ImmutableAttributeMap.builder() + .put(attributeDef, "de/st/" + RandomStringUtils.randomNumeric(64)) + .put(attributeDef2, RandomStringUtils.randomAlphabetic(10)) + .put(attributeDef3, RandomStringUtils.randomAlphabetic(10)).put(attributeDef4, "2001-01-01").build(); + + val b = new AuthenticationResponse.Builder(); + return b.id("aasdf").issuer("asd").subject("asf").statusCode("200").inResponseTo("asdf").subjectNameIdFormat("afaf") + .attributes(attributeMap).build(); + } +} diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml index 7d5a4c53..6610fe04 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml @@ -61,4 +61,14 @@ class="at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.CreateIdentityLinkTask" scope="prototype" /> + <bean id="InitialSearchTask" + class="at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.InitialSearchTask" + scope="prototype" /> + + <bean id="ErnbClientForeIDAS" + class="at.asitplus.eidas.specific.modules.auth.eidas.v2.ernb.DummyErnbClient" /> + + <bean id="ZmrClientForeIDAS" + class="at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.DummyZmrClient" /> + </beans>
\ No newline at end of file |