package at.asitplus.eidas.specific.connector.test.config; import java.net.MalformedURLException; import java.net.URL; import java.security.cert.CertificateException; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.opensaml.core.config.InitializationException; 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.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import at.asitplus.eidas.specific.core.config.ServiceProviderConfiguration; import at.gv.egiz.eaaf.core.api.data.EaafConstants; import at.gv.egiz.eaaf.core.api.idp.IConfigurationWithSP; import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration; import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException; import at.gv.egiz.eaaf.core.exceptions.EaafException; import net.shibboleth.utilities.java.support.component.ComponentInitializationException; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "/applicationContext.xml", "/spring/SpringTest_connector.beans.xml", "/eaaf_core.beans.xml", "/eaaf_pvp.beans.xml", "/eaaf_pvp_idp.beans.xml", "/spring/SpringTest-context_simple_storage.xml" }) @WebAppConfiguration @DirtiesContext(classMode = ClassMode.BEFORE_CLASS) @ActiveProfiles(profiles = {"deprecatedConfig"}) public class BasicConfigurationTest { @Autowired private IConfigurationWithSP basicConfig; /** * jUnit class initializer. * @throws ComponentInitializationException In case of an error * @throws InitializationException In case of an error * @throws CertificateException * */ @BeforeClass public static void classInitializer() throws InitializationException, ComponentInitializationException, CertificateException { final String current = new java.io.File(".").toURI().toString(); System.setProperty("eidas.ms.configuration", current + "src/test/resources/config/junit_config_1.properties"); } @Test public void basicConfig() throws MalformedURLException, EaafException { Assert.assertEquals("validate req. URL", "http://localhost", basicConfig.validateIdpUrl(new URL("http://junit/test"))); Assert.assertEquals("validate req. URL", "http://localhost", basicConfig.validateIdpUrl(new URL("http://localhost/test1/test"))); } @Test public void loadSpNotExist() throws EaafConfigurationException { //check ISpConfiguration sp = basicConfig.getServiceProviderConfiguration( "https://not/exist"); //validate state Assert.assertNull("spConfig", sp); } @Test public void loadSpDefault() throws EaafConfigurationException { //check ISpConfiguration sp = basicConfig.getServiceProviderConfiguration( "https://demo.egiz.gv.at/demoportal_moaid-2.0/sp/eidas/metadata"); //validate state Assert.assertNotNull("spConfig", sp); Assert.assertEquals("BaseId transfare restrication", true, sp.hasBaseIdTransferRestriction()); Assert.assertEquals("BaseId process restrication", false, sp.hasBaseIdInternalProcessingRestriction()); Assert.assertEquals("req. LoA size", 1, sp.getRequiredLoA().size()); Assert.assertEquals("req. LoA", EaafConstants.EIDAS_LOA_HIGH, sp.getRequiredLoA().get(0)); Assert.assertEquals("LoA matching mode", EaafConstants.EIDAS_LOA_MATCHING_MINIMUM, sp.getLoAMatchingMode()); } @Test public void loadSpNoBaseIdTransferRestriction() throws EaafException { //check ServiceProviderConfiguration sp = basicConfig.getServiceProviderConfiguration( "https://demo.egiz.gv.at/demoportal_moaid-2.0/sp/eidas/metadata", ServiceProviderConfiguration.class); //validate state Assert.assertNotNull("spConfig", sp); Assert.assertNull("bPKTarget already set", sp.getAreaSpecificTargetIdentifier()); //validate baseId transfer restriction sp.setBpkTargetIdentifier(EaafConstants.URN_PREFIX_CDID + "ZP"); Assert.assertEquals("BaseId restrication", false, sp.hasBaseIdTransferRestriction()); Assert.assertEquals("bPKTarget", EaafConstants.URN_PREFIX_CDID + "ZP", sp.getAreaSpecificTargetIdentifier()); sp.setBpkTargetIdentifier(EaafConstants.URN_PREFIX_WBPK_TARGET_WITH_X + "FN+123456h"); Assert.assertEquals("BaseId restrication", true, sp.hasBaseIdTransferRestriction()); } @Test public void loadSpWithMsSpecificConfig() throws EaafConfigurationException { //check ServiceProviderConfiguration sp = basicConfig.getServiceProviderConfiguration( "https://demo.egiz.gv.at/junit_test", ServiceProviderConfiguration.class); //validate state Assert.assertNotNull("spConfig", sp); Assert.assertEquals("friendlyName", "jUnit test", sp.getFriendlyName()); Assert.assertEquals("UniqueId", "https://demo.egiz.gv.at/junit_test", sp.getUniqueIdentifier()); Assert.assertEquals("BaseId restrication", true, sp.hasBaseIdTransferRestriction()); Assert.assertEquals("generic config value", false, sp.isConfigurationValue("policy.allowed.requested.targets")); Assert.assertEquals("generic config value", "test", sp.getConfigurationValue("policy.allowed.requested.targets")); Assert.assertEquals("not_exist_value", "true", sp.getConfigurationValue("not.exist", "true")); } }