/* * Copyright 2018 A-SIT Plus GmbH * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ, * A-SIT Plus GmbH, A-SIT, and Graz University of Technology. * * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "License"); * You may not use this work except in compliance with the License. * You may obtain a copy of the License at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.validation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; 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 at.asitplus.eidas.specific.core.config.ServiceProviderConfiguration; import at.asitplus.eidas.specific.core.test.config.dummy.MsConnectorDummyConfigMap; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPostProcessingException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPreProcessingException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.CcSpecificEidProcessingService; import at.gv.egiz.eaaf.core.api.data.EaafConfigConstants; import at.gv.egiz.eaaf.core.api.data.EaafConstants; import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl; import eu.eidas.auth.commons.light.impl.LightRequest; import eu.eidas.auth.commons.light.impl.LightRequest.Builder; import lombok.SneakyThrows; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/SpringTest-context_tasks_test.xml", "/SpringTest-context_basic_mapConfig.xml"}) @DirtiesContext(classMode = ClassMode.AFTER_CLASS) public class EidasRequestPreProcessingSecondTest { @Autowired private MsConnectorDummyConfigMap basicConfig; @Autowired private CcSpecificEidProcessingService preProcessor; private TestRequestImpl pendingReq; private ServiceProviderConfiguration oaParam; private Builder authnRequestBuilder; /** * jUnit test set-up. * */ @Before @SneakyThrows public void setUp() { final Map spConfig = new HashMap<>(); spConfig.put(EaafConfigConstants.SERVICE_UNIQUEIDENTIFIER, "testSp"); oaParam = new ServiceProviderConfiguration(spConfig, basicConfig); oaParam.setBpkTargetIdentifier("urn:publicid:gv.at:cdid+XX"); pendingReq = new TestRequestImpl(); pendingReq.setSpConfig(oaParam); pendingReq.setPendingReqId(at.gv.egiz.eaaf.core.impl.utils.Random.nextProcessReferenceValue()); pendingReq.setAuthUrl("http://test.com/"); authnRequestBuilder = LightRequest.builder(); authnRequestBuilder.id(UUID.randomUUID().toString()); authnRequestBuilder.issuer("Test"); authnRequestBuilder.levelOfAssurance(EaafConstants.EIDAS_LOA_HIGH); basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.publicSectorTargets", ".*"); basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.requesterId.lu.useStaticRequesterForAll", "true"); basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.proxyservices.privatesp.notsupported", ""); } @Test @SneakyThrows public void privateSpAllowed() { basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.proxyservices.privatesp.notsupported", "XX,XY"); basicConfig.removeConfigValue("eidas.ms.auth.eIDAS.node_v2.publicSectorTargets"); oaParam.setBpkTargetIdentifier("urn:publicid:gv.at:wbpk+XFN+123456a"); final String testCountry = "DE"; authnRequestBuilder.citizenCountryCode(testCountry); preProcessor.preProcess(testCountry, pendingReq, authnRequestBuilder); final LightRequest lightReq = authnRequestBuilder.build(); Assert.assertEquals("no PublicSP", "private", lightReq.getSpType()); } @Test @SneakyThrows public void privateSpNotAllowed() { basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.proxyservices.privatesp.notsupported", "XX,XY"); basicConfig.removeConfigValue("eidas.ms.auth.eIDAS.node_v2.publicSectorTargets"); oaParam.setBpkTargetIdentifier("urn:publicid:gv.at:wbpk+XFN+123456a"); final String testCountry = "XY"; authnRequestBuilder.citizenCountryCode(testCountry); EidPreProcessingException error = assertThrows("validation error not detected", EidPreProcessingException.class, () -> preProcessor.preProcess(testCountry, pendingReq, authnRequestBuilder)); assertEquals("wrong errorId", "module.eidasauth.07", error.getErrorId()); } @Test @SneakyThrows public void prePreProcessDeUnknownAttribute() throws EidPostProcessingException { basicConfig.putConfigValue("eidas.ms.auth.eIDAS.node_v2.staticProviderNameForPublicSPs", "myNode"); basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.workarounds.useStaticProviderNameForPublicSPs", "true"); final String testCountry = "DE"; authnRequestBuilder.citizenCountryCode(testCountry); preProcessor.preProcess(testCountry, pendingReq, authnRequestBuilder); final LightRequest lightReq = authnRequestBuilder.build(); Assert.assertEquals("ProviderName is not Static", "myNode", lightReq.getProviderName());//Fixme "myNode" Assert.assertEquals("no PublicSP", "public", lightReq.getSpType()); Assert.assertEquals("Requested attribute size not match", 8, lightReq.getRequestedAttributes().size()); } /* * Set ProviderName according to general configuration */ @Test @SneakyThrows public void prePreProcessLuPublicSpWithoutRequestId() throws EidPostProcessingException { basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.requesterId.lu.useStaticRequesterForAll", "false"); final String testCountry = "LU"; authnRequestBuilder.citizenCountryCode(testCountry); preProcessor.preProcess(testCountry, pendingReq, authnRequestBuilder); final LightRequest lightReq = authnRequestBuilder.build(); Assert.assertEquals("ProviderName is not Static", "myNode", lightReq.getProviderName()); Assert.assertNull("RequesterId", lightReq.getRequesterId()); Assert.assertEquals("no PublicSP", "public", lightReq.getSpType()); Assert.assertEquals("Requested attribute size not match", 4, lightReq.getRequestedAttributes().size()); } /* * Always set requesterId and providername in case of country LU */ @Test @SneakyThrows public void prePreProcessLuPublicSpWithStaticRequesterId() throws EidPostProcessingException { final String testCountry = "LU"; authnRequestBuilder.citizenCountryCode(testCountry); preProcessor.preProcess(testCountry, pendingReq, authnRequestBuilder); final LightRequest lightReq = authnRequestBuilder.build(); Assert.assertEquals("ProviderName is not Static", "myNode", lightReq.getProviderName()); Assert.assertEquals("RequesterId is not Static", "myNode", lightReq.getRequesterId()); Assert.assertEquals("no PublicSP", "public", lightReq.getSpType()); Assert.assertEquals("Requested attribute size not match", 4, lightReq.getRequestedAttributes().size()); } @Test @SneakyThrows public void prePreProcessUaWithConfig() throws EidPostProcessingException { basicConfig.putConfigValue( "eidas.ms.auth.eIDAS.node_v2.loa.ua.requested", "http://eidas.europa.eu/NotNotified/LoA/high"); final String testCountry = "UA"; authnRequestBuilder.citizenCountryCode(testCountry); authnRequestBuilder.levelOfAssurance(EaafConstants.EIDAS_LOA_LOW); preProcessor.preProcess(testCountry, pendingReq, authnRequestBuilder); final LightRequest lightReq = authnRequestBuilder.build(); Assert.assertNotSame("RequesterId was set", lightReq.getRequesterId()); Assert.assertEquals("no PublicSP", "public", lightReq.getSpType()); Assert.assertEquals("Requested attribute size not match", 4, lightReq.getRequestedAttributes().size()); Assert.assertEquals("wrong LoA", "http://eidas.europa.eu/NotNotified/LoA/high", lightReq.getLevelsOfAssurance().get(0).getValue()); assertEquals("SP allowed LoA", 2, oaParam.getRequiredLoA().size()); assertTrue("missing not-notified LoA", oaParam.getRequiredLoA().stream() .filter(el -> el.equals("http://eidas.europa.eu/NotNotified/LoA/high")).findFirst().isPresent()); assertEquals("wrong LoA matching-mode", "exact", oaParam.getLoAMatchingMode()); } }