@Test public void testEmptyConfig() { System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, getHomeDirName("conf-empty/conf/empty")); GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getGatewayPort(), is(8888)); // assertThat( config.getShiroConfigFile(), is( "shiro.ini") ); }
@Test public void testDefaultDeploymentDir() { String homeDirName = getHomeDirName("conf-site/conf/gateway-site.xml"); System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName); System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName); GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getGatewayDeploymentDir(), is(homeDirName + File.separator + "deployments")); }
@Test public void testForUpdatedDeploymentDir() { String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml"); System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName); System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName); GatewayConfig config = new GatewayConfigImpl(); assertTrue(("target/test").equalsIgnoreCase(config.getGatewayDeploymentDir())); }
@Test public void testForDataDirSetAsConfiguration() { String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml"); System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName); System.clearProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR); GatewayConfig config = new GatewayConfigImpl(); assertTrue(("target/testDataDir").equalsIgnoreCase(config.getGatewayDataDir())); }
@Test public void testDemoConfig() { System.setProperty( GatewayConfigImpl.GATEWAY_HOME_VAR, getHomeDirName("conf-demo/conf/gateway-default.xml")); GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getGatewayPort(), is(8888)); assertTrue(config.getExcludedSSLProtocols().get(0).equals("SSLv3")); // assertThat( config.getShiroConfigFile(), is( "full-shiro.ini") ); }
@Test public void testForDefaultDataDir() { String homeDirName = getHomeDirName("conf-site/conf/gateway-site.xml"); System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName); System.clearProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR); GatewayConfig config = new GatewayConfigImpl(); assertTrue( (homeDirName + File.separator + "data").equalsIgnoreCase(config.getGatewayDataDir())); }
@Test public void testFullConfig() { System.setProperty( GatewayConfigImpl.GATEWAY_HOME_VAR, getHomeDirName("conf-full/conf/gateway-default.xml")); GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getGatewayPort(), is(7777)); assertThat(config.isClientAuthNeeded(), is(false)); assertNull("ssl.exclude.protocols should be null.", config.getExcludedSSLProtocols()); // assertThat( config.getShiroConfigFile(), is( "full-shiro.ini") ); }
@Test public void testStacksServicesDir() { System.clearProperty(GatewayConfigImpl.GATEWAY_HOME_VAR); GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getGatewayServicesDir(), Matchers.endsWith("data/services")); String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml"); System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName); config = new GatewayConfigImpl(); assertEquals("target/test", config.getGatewayServicesDir()); }
/** * When data dir is set at both system property and configuration level , then system property * value should be considered */ @Test public void testDataDirSetAsBothSystemPropertyAndConfig() { String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml"); System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName); System.setProperty( GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName + File.separator + "DataDirSystemProperty"); GatewayConfig config = new GatewayConfigImpl(); assertTrue( (homeDirName + File.separator + "DataDirSystemProperty") .equalsIgnoreCase(config.getGatewayDataDir())); }
@Override public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException { // set any JSSE or security related system properties System.setProperty(EPHEMERAL_DH_KEY_SIZE_PROPERTY, config.getEphemeralDHKeySize()); try { if (!ks.isCredentialStoreForClusterAvailable(GATEWAY_CREDENTIAL_STORE_NAME)) { log.creatingCredentialStoreForGateway(); ks.createCredentialStoreForCluster(GATEWAY_CREDENTIAL_STORE_NAME); // LET'S NOT GENERATE A DIFFERENT KEY PASSPHRASE BY DEFAULT ANYMORE // IF A DEPLOYMENT WANTS TO CHANGE THE KEY PASSPHRASE TO MAKE IT MORE SECURE THEN // THEY CAN ADD THE ALIAS EXPLICITLY WITH THE CLI // as.generateAliasForCluster(GATEWAY_CREDENTIAL_STORE_NAME, GATEWAY_IDENTITY_PASSPHRASE); } else { log.credentialStoreForGatewayFoundNotCreating(); } } catch (KeystoreServiceException e) { throw new ServiceLifecycleException( "Keystore was not loaded properly - the provided (or persisted) master secret may not match the password for the keystore.", e); } try { if (!ks.isKeystoreForGatewayAvailable()) { log.creatingKeyStoreForGateway(); ks.createKeystoreForGateway(); char[] passphrase = null; try { passphrase = as.getGatewayIdentityPassphrase(); } catch (AliasServiceException e) { throw new ServiceLifecycleException( "Error accessing credential store for the gateway.", e); } if (passphrase == null) { passphrase = ms.getMasterSecret(); } ks.addSelfSignedCertForGateway("gateway-identity", passphrase); } else { log.keyStoreForGatewayFoundNotCreating(); } logAndValidateCertificate(); } catch (KeystoreServiceException e) { throw new ServiceLifecycleException( "Keystore was not loaded properly - the provided (or persisted) master secret may not match the password for the keystore.", e); } keystoreType = config.getKeystoreType(); sslExcludeProtocols = config.getExcludedSSLProtocols(); clientAuthNeeded = config.isClientAuthNeeded(); truststorePath = config.getTruststorePath(); trustAllCerts = config.getTrustAllCerts(); trustStoreType = config.getTruststoreType(); }
@Test public void testSiteConfig() { System.setProperty( GatewayConfigImpl.GATEWAY_HOME_VAR, getHomeDirName("conf-site/conf/gateway-site.xml")); GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getGatewayPort(), is(5555)); assertThat(config.isClientAuthNeeded(), is(true)); assertThat(config.getTruststorePath(), is("./gateway-trust.jks")); assertThat(config.getTruststoreType(), is("PKCS12")); assertThat(config.getKeystoreType(), is("JKS")); }
public String getUrl(String serviceRole, boolean real) { String url; String localHostName = getLocalHostName(); Service service = services.get(serviceRole); if (useGateway && !real) { url = "http://" + localHostName + ":" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath() + service.gatewayPath; } else if (service.mock) { url = "http://" + localHostName + ":" + service.server.getPort(); } else { url = service.realUrl.toASCIIString(); } return url; }
public void cleanup() throws Exception { gateway.stop(); FileUtils.deleteQuietly(new File(config.getGatewayTopologyDir())); FileUtils.deleteQuietly(new File(config.getGatewayConfDir())); FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir())); FileUtils.deleteQuietly(new File(config.getGatewayDeploymentDir())); FileUtils.deleteQuietly(new File(config.getGatewayDataDir())); FileUtils.deleteQuietly(new File(config.getGatewayServicesDir())); for (Service service : services.values()) { service.server.stop(); } services.clear(); ldap.stop(true); }
public static void setupGateway() throws Exception { File targetDir = new File(System.getProperty("user.dir"), "target"); File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID()); gatewayDir.mkdirs(); GatewayTestConfig testConfig = new GatewayTestConfig(); config = testConfig; testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath()); File topoDir = new File(testConfig.getGatewayTopologyDir()); topoDir.mkdirs(); File deployDir = new File(testConfig.getGatewayDeploymentDir()); deployDir.mkdirs(); File descriptor = new File(topoDir, "test-cluster.xml"); FileOutputStream stream = new FileOutputStream(descriptor); createTopology().toStream(stream); stream.close(); DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String, String> options = new HashMap<String, String>(); options.put("persist-master", "false"); options.put("master", "password"); try { srvcs.init(testConfig, options); } catch (ServiceLifecycleException e) { e.printStackTrace(); // I18N not required. } gateway = GatewayServer.startGateway(testConfig, srvcs); MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue()); LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort()); gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath(); clusterUrl = gatewayUrl + "/test-cluster"; }
@Test public void testDefaultAppRedirectPath() { GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getDefaultAppRedirectPath(), is("/gateway/sandbox")); }
@Test public void testDefaultTopologyName() { GatewayConfig config = new GatewayConfigImpl(); assertThat(config.getDefaultTopologyName(), is("sandbox")); }