diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-02-05 16:20:34 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-02-05 16:20:34 +0100 |
commit | b1e267a57f896268239df835b45742c752310ed5 (patch) | |
tree | bf3d31b4070b910575d769b05c3fd7c7318705b7 | |
parent | 963d6217f4bb1a1c91ca45b7020d80860038a610 (diff) | |
download | EAAF-Components-b1e267a57f896268239df835b45742c752310ed5.tar.gz EAAF-Components-b1e267a57f896268239df835b45742c752310ed5.tar.bz2 EAAF-Components-b1e267a57f896268239df835b45742c752310ed5.zip |
fix junit test that uses expired metadata for testing
2 files changed, 30 insertions, 37 deletions
diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java index 14a641e6..1b14c92d 100644 --- a/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java +++ b/eaaf_modules/eaaf_module_pvp2_core/src/main/java/at/gv/egiz/eaaf/modules/pvp2/impl/metadata/AbstractChainingMetadataProvider.java @@ -474,28 +474,6 @@ public abstract class AbstractChainingMetadataProvider implements IGarbageCollec } -// private boolean resolveEntityDescriporForRefesh(String entityId) { -// final CriteriaSet criteria = new CriteriaSet(); -// criteria.add(new EntityIdCriterion(entityId)); -// for (final MetadataResolver resolver : internalResolvers) { -// try { -// if (resolver instanceof RefreshableMetadataResolver -// && resolver.resolveSingle(criteria) != null) { -// -// ((RefreshableMetadataResolver)resolver).refresh(); -// return true; -// -// } -// -// } catch (final ResolverException e) { -// continue; -// -// } -// } -// -// return false; -// } - private void destroyMetadataResolver(MetadataResolver resolver) { if (resolver instanceof AbstractMetadataResolver) { final AbstractMetadataResolver httpprovider = (AbstractMetadataResolver) resolver; diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/metadata/MetadataResolverTest.java b/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/metadata/MetadataResolverTest.java index 8995152d..bcdeb765 100644 --- a/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/metadata/MetadataResolverTest.java +++ b/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/metadata/MetadataResolverTest.java @@ -26,6 +26,7 @@ import at.gv.egiz.eaaf.modules.pvp2.impl.validation.metadata.SimpleMetadataSigna import at.gv.egiz.eaaf.modules.pvp2.test.dummy.DummyCredentialProvider; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.RandomStringUtils; import org.joda.time.DateTime; import org.junit.Assert; import org.junit.Before; @@ -281,7 +282,22 @@ public class MetadataResolverTest { ResolverException, XMLParserException, UnmarshallingException, SamlSigningException, CredentialsNotAvailableException, MarshallingException, TransformerException, IOException { - final String metadataUrl = "classpath:/data/pvp_metadata_valid.xml"; + mockWebServer.shutdown(); + mockWebServer = new MockWebServer(); + mockServerUrl = mockWebServer.url("/sp/metadata"); + + final EntityDescriptor metadata = (EntityDescriptor) XMLObjectSupport.unmarshallFromInputStream( + XMLObjectProviderRegistrySupport.getParserPool(), + MetadataResolverTest.class.getResourceAsStream("/data/pvp_metadata_moaid_test.xml")); + metadata.setValidUntil(DateTime.now().plusDays(1)); + metadata.setSignature(null); + metadata.setEntityID(RandomStringUtils.randomAlphabetic(10)); + final EntityDescriptor signedMatadata = + Saml2Utils.signSamlObject(metadata, credentialProvider.getMetaDataSigningCredential(), true); + final Element metadataElement = XMLObjectSupport.marshall(signedMatadata); + mockWebServer.enqueue(new MockResponse().setResponseCode(200) + .setBody(SerializeSupport.nodeToString(metadataElement)) + .setHeader("Content-Type", "text/html;charset=utf-8")); final List<BasicX509Credential> credentials = new ArrayList<>(); final CertificateFactory fact = CertificateFactory.getInstance("X.509"); @@ -296,18 +312,18 @@ public class MetadataResolverTest { filterList.add(new SchemaValidationFilter(true)); filterList.add(new SimpleMetadataSignatureVerificationFilter( credentials, - metadataUrl)); + mockServerUrl.url().toString())); filterList.add(new PvpEntityCategoryFilter(true)); final MetadataFilterChain filterChain = new MetadataFilterChain(); filterChain.setFilters(filterList); final IPvp2MetadataProvider mdResolver = metadataResolverFactory.createMetadataProvider( - metadataUrl, + mockServerUrl.url().toString(), filterChain, "jUnit test", httpClientFactory.getHttpClient()); final EntityDescriptor entityIdNotExists = mdResolver.getEntityDescriptor( - "https://demo.egiz.gv.at/demoportal_moaid-2.0/sp/eid/metadata"); + metadata.getEntityID()); Assert.assertNotNull("No EntityDescripter", entityIdNotExists); } @@ -322,8 +338,10 @@ public class MetadataResolverTest { MetadataResolverTest.class.getResourceAsStream("/data/pvp_metadata_valid_with_entityCategory.xml")); metadata.setValidUntil(DateTime.now().plusDays(1)); metadata.setSignature(null); - Saml2Utils.signSamlObject(metadata, credentialProvider.getMetaDataSigningCredential(), true); - final Element metadataElement = XMLObjectSupport.marshall(metadata); + metadata.setEntityID(RandomStringUtils.randomAlphabetic(10)); + final EntityDescriptor signedMatadata = + Saml2Utils.signSamlObject(metadata, credentialProvider.getMetaDataSigningCredential(), true); + final Element metadataElement = XMLObjectSupport.marshall(signedMatadata); mockWebServer.enqueue(new MockResponse().setResponseCode(200) .setBody(SerializeSupport.nodeToString(metadataElement)) .setHeader("Content-Type", "text/html;charset=utf-8")); @@ -353,8 +371,7 @@ public class MetadataResolverTest { - final EntityDescriptor descr = mdResolver.getEntityDescriptor( - "https://demo.egiz.gv.at/demoportal_moaid-2.0/sp/eid/metadata"); + final EntityDescriptor descr = mdResolver.getEntityDescriptor(metadata.getEntityID()); Assert.assertNotNull("No EntityDescripter", descr); final List<RequestedAttribute> reqAttr = descr.getSPSSODescriptor(SAMLConstants.SAML20P_NS) @@ -374,8 +391,10 @@ public class MetadataResolverTest { MetadataResolverTest.class.getResourceAsStream("/data/pvp_metadata_valid_with_entityCategory_egov.xml")); metadata.setValidUntil(DateTime.now().plusDays(1)); metadata.setSignature(null); - Saml2Utils.signSamlObject(metadata, credentialProvider.getMetaDataSigningCredential(), true); - final Element metadataElement = XMLObjectSupport.marshall(metadata); + metadata.setEntityID(RandomStringUtils.randomAlphabetic(10)); + final EntityDescriptor signedMatadata = + Saml2Utils.signSamlObject(metadata, credentialProvider.getMetaDataSigningCredential(), true); + final Element metadataElement = XMLObjectSupport.marshall(signedMatadata); mockWebServer.enqueue(new MockResponse().setResponseCode(200) .setBody(SerializeSupport.nodeToString(metadataElement)) .setHeader("Content-Type", "text/html;charset=utf-8")); @@ -405,8 +424,7 @@ public class MetadataResolverTest { - final EntityDescriptor descr = mdResolver.getEntityDescriptor( - "https://demo.egiz.gv.at/demoportal_moaid-2.0/sp/eid/metadata"); + final EntityDescriptor descr = mdResolver.getEntityDescriptor(metadata.getEntityID()); Assert.assertNotNull("No EntityDescripter", descr); final List<RequestedAttribute> reqAttr = descr.getSPSSODescriptor(SAMLConstants.SAML20P_NS) @@ -631,13 +649,10 @@ public class MetadataResolverTest { final EntityDescriptor entityId = mdResolver.getEntityDescriptor(entityIdToResolve); Assert.assertNotNull("No EntityDescripter", entityId); - final DateTime lastRefresh = mdResolver.getLastRefresh(); - // refresh metadata mdResolver.refresh(); Assert.assertTrue("Refresh not sucessful", mdResolver.wasLastRefreshSuccess()); - Assert.assertTrue("Wrong last refresh date", lastRefresh.isBefore(mdResolver.getLastRefresh())); } |