public static ConfigOverride[] withDefaultOverrides(ConfigOverride ... configOverrides) { List<ConfigOverride> overrides = Stream.of( config("saml.entityId", HUB_ENTITY_ID), config("server.applicationConnectors[0].port", "0"), config("server.adminConnectors[0].port", "0"), config("clientTrustStoreConfiguration.path", idpTrustStore.getAbsolutePath()), config("clientTrustStoreConfiguration.password", idpTrustStore.getPassword()), config("rpTrustStoreConfiguration.path", rpTrustStore.getAbsolutePath()), config("rpTrustStoreConfiguration.password", rpTrustStore.getPassword()), config("metadata.trustStorePath", metadataTrustStore.getAbsolutePath()), config("metadata.trustStorePassword", metadataTrustStore.getPassword()), config("metadata.uri", "http://localhost:" + verifyMetadataServer.getPort() + VERIFY_METADATA_PATH), config("metadata.expectedEntityId", HUB_ENTITY_ID) ).collect(Collectors.toList()); overrides.addAll(Arrays.asList(configOverrides)); return overrides.toArray(new ConfigOverride[overrides.size()]); }
public VerifyServiceProviderAppRule(MockMsaServer msaServer, String secondaryEncryptionKey, String serviceEntityIdOverride) { super( VerifyServiceProviderApplication.class, "verify-service-provider.yml", ConfigOverride.config("serviceEntityIds", serviceEntityIdOverride), ConfigOverride.config("server.connector.port", String.valueOf(0)), ConfigOverride.config("logging.loggers.uk\\.gov", "DEBUG"), ConfigOverride.config("samlSigningKey", TEST_RP_PRIVATE_SIGNING_KEY), ConfigOverride.config("verifyHubConfiguration.environment", "COMPLIANCE_TOOL"), ConfigOverride.config("samlPrimaryEncryptionKey", TEST_RP_PRIVATE_ENCRYPTION_KEY), ConfigOverride.config("samlSecondaryEncryptionKey", secondaryEncryptionKey), ConfigOverride.config("msaMetadata.uri", () -> { IdaSamlBootstrap.bootstrap(); msaServer.serveDefaultMetadata(); return msaServer.getUri(); }), ConfigOverride.config("msaMetadata.expectedEntityId", MockMsaServer.MSA_ENTITY_ID) ); }
@Test public void grantsAccessToResourcesForm() throws Exception { setup(ConfigOverride.config("pac4j.servlet.security[0].clients", DirectFormClient.class.getSimpleName())); // username == password Form form = new Form(); form.param("username", "rosebud"); form.param("password", "rosebud"); final String dogName = client.target(getUrlPrefix() + "/dogs/pierre") .request(MediaType.APPLICATION_JSON) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class); assertThat(dogName).isEqualTo("pierre"); }
@Test public void grantsAccessToResourcesForm() throws Exception { setup(ConfigOverride.config("pac4j.globalFilters[0].clients", DirectFormClient.class.getSimpleName())); // username == password Form form = new Form(); form.param("username", "rosebud"); form.param("password", "rosebud"); final String dogName = client.target(getUrlPrefix() + "/dogs/pierre") .request(MediaType.APPLICATION_JSON) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class); assertThat(dogName).isEqualTo("pierre"); }
public DropwizardAppWithPostgresRule(String configPath, ConfigOverride... configOverrides) { configFilePath = resourceFilePath(configPath); postgres = new PostgresDockerRule(); List<ConfigOverride> cfgOverrideList = newArrayList(configOverrides); cfgOverrideList.add(config("database.url", postgres.getConnectionUrl())); cfgOverrideList.add(config("database.user", postgres.getUsername())); cfgOverrideList.add(config("database.password", postgres.getPassword())); app = new DropwizardAppRule<>( AdminUsersApp.class, configFilePath, cfgOverrideList.toArray(new ConfigOverride[cfgOverrideList.size()]) ); createJpaModule(postgres); rules = RuleChain.outerRule(postgres).around(app); registerShutdownHook(); }
@Test public void createsServerWithTls() throws Exception { final DropwizardTestSupport<TestConfiguration> testSupport = new DropwizardTestSupport<>(TestApplication.class, resourceFilePath("grpc-test-config.yaml"), Optional.empty(), ConfigOverride.config("grpcServer.certChainFile", getURIForResource("cert/server.crt")), ConfigOverride.config("grpcServer.privateKeyFile", getURIForResource("cert/server.key"))); ManagedChannel channel = null; try { testSupport.before(); channel = createClientChannelForEncryptedServer(testSupport); final PersonServiceGrpc.PersonServiceBlockingStub client = PersonServiceGrpc.newBlockingStub(channel); final GetPersonResponse resp = client.getPerson(GetPersonRequest.newBuilder().setName(TEST_PERSON_NAME).build()); assertEquals(TEST_PERSON_NAME, resp.getPerson().getName()); } finally { testSupport.after(); shutdownChannel(channel); } }
public static DropwizardTestSupport<ApplicationConfiguration> startApplicationWith( int initialDelayInMillis, Class testClass, int periodInMillis) { ConfigOverride[] configOverrides = { ConfigOverride.config("testClasses", testClass.getName()), ConfigOverride.config("initialDelayInMillis", String.valueOf(initialDelayInMillis)), ConfigOverride.config("periodInMillis", String.valueOf(periodInMillis)) }; DropwizardTestSupport<ApplicationConfiguration> applicationConfigurationDropwizardTestSupport = new DropwizardTestSupport<>(Atam4jTestApplication.class, ResourceHelpers.resourceFilePath("atam4j-config.yml"), configOverrides); applicationConfigurationDropwizardTestSupport.before(); return applicationConfigurationDropwizardTestSupport; }
public static ConfigOverride[] withDefaultOverrides(final ConfigOverride... configOverrides) { ImmutableList<ConfigOverride> mergedConfigOverrides = ImmutableList.<ConfigOverride>builder() .add(config("clientTrustStoreConfiguration.path", clientTrustStore.getAbsolutePath())) .add(config("clientTrustStoreConfiguration.password", clientTrustStore.getPassword())) .add(configOverrides) .build(); return mergedConfigOverrides.toArray(new ConfigOverride[mergedConfigOverrides.size()]); }
public SamlEngineAppRule(boolean isCountryEnabled, ConfigOverride... configOverrides) { super(SamlEngineIntegrationApplication.class, ResourceHelpers.resourceFilePath("saml-engine.yml"), withDefaultOverrides(isCountryEnabled, configOverrides) ); BootstrapUtils.reset(); }
public static ConfigOverride[] withDefaultOverrides(ConfigOverride ... configOverrides) { ImmutableList<ConfigOverride> overrides = ImmutableList.<ConfigOverride>builder() .add(config("clientTrustStoreConfiguration.path", clientTrustStore.getAbsolutePath())) .add(config("clientTrustStoreConfiguration.password", clientTrustStore.getPassword())) .add(config("rpTrustStoreConfiguration.path", rpTrustStore.getAbsolutePath())) .add(config("rpTrustStoreConfiguration.password", rpTrustStore.getPassword())) .add(config("rootDataDirectory", FED_CONFIG_ROOT.getAbsolutePath())) .add(configOverrides) .build(); return overrides.toArray(new ConfigOverride[overrides.size()]); }
public void setup( Class<? extends Application<TestConfiguration>> applicationClass, String configPath, ConfigOverride... configOverrides) { dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass, ResourceHelpers.resourceFilePath(configPath), configOverrides); dropwizardTestSupport.before(); }
@Test public void grantsAccessToResources() throws Exception { setup(ConfigOverride.config("pac4j.servlet.security[0].clients", DirectBasicAuthClient.class.getSimpleName())); final String dogName = client.target(getUrlPrefix() + "/dogs/pierre") .request(MediaType.APPLICATION_JSON) // username == password .header(HttpHeaders.AUTHORIZATION, mkAuthField("rosebud", "rosebud")) .get(String.class); assertThat(dogName).isEqualTo("pierre"); }
@Test public void restrictsAccessToResources() throws Exception { setup(ConfigOverride.config("pac4j.servlet.security[0].clients", DirectBasicAuthClient.class.getSimpleName())); final Response response = client.target(getUrlPrefix() + "/dogs/pierre") .request(MediaType.APPLICATION_JSON) // username != password .header(HttpHeaders.AUTHORIZATION, mkAuthField("boy", "howdy")) .get(); assertThat(response.getStatusInfo()) .isEqualTo(Response.Status.UNAUTHORIZED); }
@Test public void grantsAccessToResources() throws Exception { setup(ConfigOverride.config("pac4j.globalFilters[0].clients", DirectBasicAuthClient.class.getSimpleName())); final String dogName = client.target(getUrlPrefix() + "/dogs/pierre") .request(MediaType.APPLICATION_JSON) // username == password .header(HttpHeaders.AUTHORIZATION, mkAuthField("rosebud", "rosebud")) .get(String.class); assertThat(dogName).isEqualTo("pierre"); }
@Test public void restrictsAccessToResources() throws Exception { setup(ConfigOverride.config("pac4j.globalFilters[0].clients", DirectBasicAuthClient.class.getSimpleName())); final Response response = client.target(getUrlPrefix() + "/dogs/pierre") .request(MediaType.APPLICATION_JSON) // username != password .header(HttpHeaders.AUTHORIZATION, mkAuthField("boy", "howdy")) .get(); assertThat(response.getStatusInfo()) .isEqualTo(Response.Status.UNAUTHORIZED); }
private ReaperJettyTestSupport(String configFile, AppContext context) { super(ReaperApplication.class, new File(configFile).getAbsolutePath(), ConfigOverride.config("server.adminConnectors[0].port", "" + getAnyAvailablePort()), ConfigOverride.config("server.applicationConnectors[0].port", "" + getAnyAvailablePort()) ); this.context = context; }
/** * Utility method to convert configuration overrides from annotation to rule compatible format. * * @param overrides override annotations * @return dropwizard config override objects */ protected ConfigOverride[] convertOverrides( final ru.vyarus.dropwizard.guice.test.spock.ConfigOverride... overrides) { final ConfigOverride[] configOverride = new ConfigOverride[overrides.length]; int i = 0; for (ru.vyarus.dropwizard.guice.test.spock.ConfigOverride override : overrides) { configOverride[i++] = ConfigOverride.config(override.key(), override.value()); } return configOverride; }
public GuiceyAppRule(final Class<? extends Application<C>> applicationClass, @Nullable final String configPath, final ConfigOverride... configOverrides) { this.applicationClass = applicationClass; this.configPath = configPath; for (ConfigOverride configOverride : configOverrides) { configOverride.addToSystemProperties(); } }
public SamlProxyAppRule(ConfigOverride... configOverrides) { this(true, configOverrides); }
public SamlProxyAppRule(boolean isCountryEnabled, ConfigOverride... configOverrides) { super(SamlProxyApplication.class, ResourceHelpers.resourceFilePath("saml-proxy.yml"), withDefaultOverrides(isCountryEnabled, configOverrides) ); }
public static ConfigOverride[] withDefaultOverrides(boolean isCountryEnabled, ConfigOverride ... configOverrides) { List<ConfigOverride> overrides = Stream.of( config("saml.entityId", HUB_ENTITY_ID), config("server.applicationConnectors[0].port", "0"), config("server.adminConnectors[0].port", "0"), config("clientTrustStoreConfiguration.path", clientTrustStore.getAbsolutePath()), config("clientTrustStoreConfiguration.password", clientTrustStore.getPassword()), config("rpTrustStoreConfiguration.path", rpTrustStore.getAbsolutePath()), config("rpTrustStoreConfiguration.password", rpTrustStore.getPassword()), config("metadata.trustStorePath", metadataTrustStore.getAbsolutePath()), config("metadata.trustStorePassword", metadataTrustStore.getPassword()), config("metadata.uri", "http://localhost:" + verifyMetadataServer.getPort() + VERIFY_METADATA_PATH) ).collect(Collectors.toList()); if (isCountryEnabled) { List<ConfigOverride> countryOverrides = Stream.of( config("eidas", "true"), //config("country.metadata.uri", "http://localhost:" + countryMetadataServer.getPort() + COUNTRY_METADATA_PATH), config("country.metadata.trustStorePath", metadataTrustStore.getAbsolutePath()), config("country.metadata.trustStorePassword", metadataTrustStore.getPassword()), config("country.metadata.minRefreshDelay", "60000"), config("country.metadata.maxRefreshDelay", "600000"), //config("country.metadata.expectedEntityId", "http://thecountry/metadata"), config("country.metadata.jerseyClientName", "country-metadata-client"), config("country.metadata.client.timeout", "2s"), config("country.metadata.client.timeToLive", "10m"), config("country.metadata.client.cookiesEnabled", "false"), config("country.metadata.client.connectionTimeout", "1s"), config("country.metadata.client.retries", "3"), config("country.metadata.client.keepAlive", "60s"), config("country.metadata.client.chunkedEncodingEnabled", "false"), config("country.metadata.client.validateAfterInactivityPeriod", "5s"), config("country.metadata.client.tls.protocol", "TLSv1.2"), config("country.metadata.client.tls.verifyHostname", "false"), config("country.metadata.client.tls.trustSelfSignedCertificates", "true") ).collect(Collectors.toList()); overrides.addAll(countryOverrides); } overrides.addAll(Arrays.asList(configOverrides)); return overrides.toArray(new ConfigOverride[overrides.size()]); }
public PolicyAppRule(final ConfigOverride... configOverrides) { super(PolicyIntegrationApplication.class, ResourceHelpers.resourceFilePath("policy.yml"), withDefaultOverrides(configOverrides)); }
public SamlEngineAppRule(ConfigOverride... configOverrides) { this(true, configOverrides); }
public static ConfigOverride[] withDefaultOverrides(boolean isCountryEnabled, ConfigOverride ... configOverrides) { List<ConfigOverride> overrides = Stream.of( config("saml.entityId", HUB_ENTITY_ID), config("saml.expectedDestination", "http://localhost"), config("server.applicationConnectors[0].port", "0"), config("server.adminConnectors[0].port", "0"), config("privateSigningKeyConfiguration.key", HUB_TEST_PRIVATE_SIGNING_KEY), config("publicSigningCert.x509", HUB_TEST_PUBLIC_SIGNING_CERT), config("primaryPrivateEncryptionKeyConfiguration.key", HUB_TEST_PRIVATE_ENCRYPTION_KEY), config("primaryPublicEncryptionCert.x509", HUB_TEST_PUBLIC_ENCRYPTION_CERT), config("secondaryPrivateEncryptionKeyConfiguration.key", TEST_PRIVATE_KEY), config("secondaryPublicEncryptionCert.x509", TEST_PUBLIC_CERT), config("clientTrustStoreConfiguration.path", clientTrustStore.getAbsolutePath()), config("clientTrustStoreConfiguration.password", clientTrustStore.getPassword()), config("rpTrustStoreConfiguration.path", rpTrustStore.getAbsolutePath()), config("rpTrustStoreConfiguration.password", rpTrustStore.getPassword()), config("metadata.trustStorePath", metadataTrustStore.getAbsolutePath()), config("metadata.trustStorePassword", metadataTrustStore.getPassword()), config("metadata.uri", "http://localhost:" + verifyMetadataServer.getPort() + VERIFY_METADATA_PATH) ).collect(Collectors.toList()); if (isCountryEnabled) { List<ConfigOverride> countryOverrides = Stream.of( config("eidas", "true"), config("country.metadata.uri", "http://localhost:" + countryMetadataServer.getPort() + COUNTRY_METADATA_PATH), config("country.metadata.trustStorePath", metadataTrustStore.getAbsolutePath()), config("country.metadata.trustStorePassword", metadataTrustStore.getPassword()), config("country.metadata.minRefreshDelay", "60000"), config("country.metadata.maxRefreshDelay", "600000"), config("country.metadata.expectedEntityId", EIDAS_ENTITY_ID), config("country.metadata.jerseyClientName", "country-metadata-client"), config("country.metadata.client.timeout", "2s"), config("country.metadata.client.timeToLive", "10m"), config("country.metadata.client.cookiesEnabled", "false"), config("country.metadata.client.connectionTimeout", "1s"), config("country.metadata.client.retries", "3"), config("country.metadata.client.keepAlive", "60s"), config("country.metadata.client.chunkedEncodingEnabled", "false"), config("country.metadata.client.validateAfterInactivityPeriod", "5s"), config("country.metadata.client.tls.protocol", "TLSv1.2"), config("country.metadata.client.tls.verifyHostname", "false"), config("country.metadata.client.tls.trustSelfSignedCertificates", "true"), config("country.saml.entityId", EIDAS_ENTITY_ID) ).collect(Collectors.toList()); overrides.addAll(countryOverrides); } overrides.addAll(Arrays.asList(configOverrides)); return overrides.toArray(new ConfigOverride[overrides.size()]); }
public SamlSoapProxyAppRule(ConfigOverride... configOverrides) { super(SamlSoapProxyApplication.class, io.dropwizard.testing.ResourceHelpers.resourceFilePath("saml-soap-proxy.yml"), withDefaultOverrides(configOverrides) ); }
public ConfigAppRule(ConfigOverride... configOverrides) { super(ConfigApplication.class, ResourceHelpers.resourceFilePath("config.yml"), withDefaultOverrides(configOverrides) ); }
@Before public void setUp() { KeyStoreResource keyStoreResource = aKeyStoreResource() .withCertificate("any-alias", aCertificate().build().getCertificate()) .build(); keyStoreResource.create(); application = new DropwizardAppRule<>( VerifyServiceProviderApplication.class, "verify-service-provider.yml", ConfigOverride.config("logging.loggers.uk\\.gov", "DEBUG"), ConfigOverride.config("verifyHubConfiguration.metadata.trustStore.path", keyStoreResource.getAbsolutePath()), ConfigOverride.config("verifyHubConfiguration.metadata.trustStore.password", keyStoreResource.getPassword()) ); }
public MatchingServiceAdapterAppRule(ConfigOverride... otherConfigOverrides) { this(false, otherConfigOverrides); }
public MatchingServiceAdapterAppRule(boolean isCountryEnabled, ConfigOverride... otherConfigOverrides) { super(MatchingServiceAdapterApplication.class, ResourceHelpers.resourceFilePath("verify-matching-service-adapter.yml"), MatchingServiceAdapterAppRule.withDefaultOverrides(isCountryEnabled, otherConfigOverrides) ); }
public static ConfigOverride[] withDefaultOverrides(boolean isCountryEnabled, ConfigOverride... otherConfigOverrides) { List<ConfigOverride> overrides = Stream.of( ConfigOverride.config("server.applicationConnectors[0].port", "0"), ConfigOverride.config("server.adminConnectors[0].port", "0"), ConfigOverride.config("encryptionKeys[0].privateKey.key", TEST_RP_MS_PRIVATE_ENCRYPTION_KEY), ConfigOverride.config("encryptionKeys[0].publicKey.cert", getCertificate(getPrimaryPublicEncryptionCert(HUB_ENTITY_ID))), ConfigOverride.config("signingKeys.primary.privateKey.key", TEST_RP_MS_PRIVATE_SIGNING_KEY), ConfigOverride.config("signingKeys.primary.publicKey.cert", getCertificate(TEST_RP_MS_PUBLIC_SIGNING_CERT)), ConfigOverride.config("signingKeys.secondary.privateKey.key", TEST_RP_PRIVATE_SIGNING_KEY), ConfigOverride.config("signingKeys.secondary.publicKey.cert", getCertificate(TEST_RP_PUBLIC_SIGNING_CERT)), ConfigOverride.config("metadata.trustStore.type", "file"), ConfigOverride.config("metadata.trustStore.store", metadataTrustStore.getAbsolutePath()), ConfigOverride.config("metadata.trustStore.password", metadataTrustStore.getPassword()), ConfigOverride.config("metadata.hubEntityId", HUB_ENTITY_ID), ConfigOverride.config("metadata.url", "http://localhost:" + verifyMetadataServer.getPort() + VERIFY_METADATA_PATH), ConfigOverride.config("hub.hubEntityId", HUB_ENTITY_ID), ConfigOverride.config("hub.trustStore.type", "file"), ConfigOverride.config("hub.trustStore.path", clientTrustStore.getAbsolutePath()), ConfigOverride.config("hub.trustStore.password", clientTrustStore.getPassword()) ).collect(Collectors.toList()); if (isCountryEnabled) { List<ConfigOverride> countryOverrides = Stream.of( ConfigOverride.config("returnStackTraceInResponse", "true"), // Until eiDAS happy-path through MSA is complete (EID-270) ConfigOverride.config("country.hubConnectorEntityId", HUB_SECONDARY_ENTITY_ID), ConfigOverride.config("country.metadata.uri", "http://localhost:" + countryMetadataServer.getPort() + COUNTRY_METADATA_PATH), ConfigOverride.config("country.metadata.trustStore.path", countryMetadataTrustStore.getAbsolutePath()), ConfigOverride.config("country.metadata.trustStore.password", countryMetadataTrustStore.getPassword()), ConfigOverride.config("country.metadata.minRefreshDelay", "60000"), ConfigOverride.config("country.metadata.maxRefreshDelay", "600000"), ConfigOverride.config("country.metadata.expectedEntityId", "http://stub_idp.acme.org/stub-idp-one/SSO/POST"), ConfigOverride.config("country.metadata.jerseyClientName", "country-metadata-client"), ConfigOverride.config("country.metadata.client.timeout", "2s"), ConfigOverride.config("country.metadata.client.timeToLive", "10m"), ConfigOverride.config("country.metadata.client.cookiesEnabled", "false"), ConfigOverride.config("country.metadata.client.connectionTimeout", "1s"), ConfigOverride.config("country.metadata.client.retries", "3"), ConfigOverride.config("country.metadata.client.keepAlive", "60s"), ConfigOverride.config("country.metadata.client.chunkedEncodingEnabled", "false"), ConfigOverride.config("country.metadata.client.validateAfterInactivityPeriod", "5s"), ConfigOverride.config("country.metadata.client.tls.protocol", "TLSv1.2"), ConfigOverride.config("country.metadata.client.tls.verifyHostname", "false"), ConfigOverride.config("country.metadata.client.tls.trustSelfSignedCertificates", "true") ).collect(Collectors.toList()); overrides.addAll(countryOverrides); } overrides.addAll(Arrays.asList(otherConfigOverrides)); return overrides.toArray(new ConfigOverride[overrides.size()]); }
private void setup(ConfigOverride config) { super.setup(App.class, "end-to-end-servlet-test.yaml", config); }
private void setup(ConfigOverride config) { super.setup(App.class, "end-to-end-test.yaml", config); }
protected void setup(Class<? extends Application<TestConfiguration>> applicationClass) { dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass, ResourceHelpers.resourceFilePath("integration-test.yaml"), ConfigOverride.config("dataSource.url", "jdbc:hsqldb:mem:DbTest" + System.nanoTime() + "?hsqldb.translate_dti_types=false")); dropwizardTestSupport.before(); }
public OregamiAppRule(Class applicationClass, String configPath, ConfigOverride... configOverrides) { super(applicationClass, configPath, configOverrides); StartHelper.init(configPath); RestTestHelper.initRestAssured(); }