use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class GatewayGlobalConfigTest method testForUpdatedSecurityDataDir.
@Test
public void testForUpdatedSecurityDataDir() {
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.getGatewaySecurityDir()));
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class GatewayGlobalConfigTest method testEmptyConfig.
@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") );
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class GatewayGlobalConfigTest method testForDataDirSetAsSystemProperty.
@Test
public void testForDataDirSetAsSystemProperty() {
String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml");
System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName + File.separator + "DataDirSystemProperty");
GatewayConfig config = new GatewayConfigImpl();
assertTrue((homeDirName + File.separator + "DataDirSystemProperty").equalsIgnoreCase(config.getGatewayDataDir()));
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class GatewayGlobalConfigTest method testDefaultAppRedirectPath.
@Test(timeout = TestUtils.SHORT_TIMEOUT)
public void testDefaultAppRedirectPath() {
GatewayConfig config = new GatewayConfigImpl();
assertThat(config.getDefaultAppRedirectPath(), nullValue());
((GatewayConfigImpl) config).set("default.app.topology.name", "test-topo-name");
assertThat(config.getDefaultAppRedirectPath(), is("/gateway/test-topo-name"));
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class ServiceDefinitionDeploymentContributorTest method testServiceAttributeUseTwoWaySSLParamOverride.
/**
* Test that service param useTwoWaySsl in topologies overrides the corresponding custom dispatch property.
*/
@Test
public void testServiceAttributeUseTwoWaySSLParamOverride() throws Exception {
final String TEST_SERVICE_ROLE = "Test";
final String USE_TWO_WAY_SSL_PARAM = "useTwoWaySsl";
UrlRewriteRulesDescriptor clusterRules = EasyMock.createNiceMock(UrlRewriteRulesDescriptor.class);
EasyMock.replay(clusterRules);
UrlRewriteRulesDescriptor svcRules = EasyMock.createNiceMock(UrlRewriteRulesDescriptor.class);
EasyMock.replay(svcRules);
ServiceDefinition svcDef = EasyMock.createNiceMock(ServiceDefinition.class);
EasyMock.expect(svcDef.getRole()).andReturn(TEST_SERVICE_ROLE).anyTimes();
List<Route> svcRoutes = new ArrayList<>();
Route route = EasyMock.createNiceMock(Route.class);
List<Rewrite> filters = new ArrayList<>();
EasyMock.expect(route.getRewrites()).andReturn(filters).anyTimes();
svcRoutes.add(route);
EasyMock.replay(route);
EasyMock.expect(svcDef.getRoutes()).andReturn(svcRoutes).anyTimes();
CustomDispatch cd = EasyMock.createNiceMock(CustomDispatch.class);
EasyMock.expect(cd.getClassName()).andReturn("TestDispatch").anyTimes();
EasyMock.expect(cd.getHaClassName()).andReturn("TestHADispatch").anyTimes();
EasyMock.expect(cd.getHaContributorName()).andReturn(null).anyTimes();
// Let useTwoWaySsl be FALSE by default
EasyMock.expect(cd.getUseTwoWaySsl()).andReturn(false).anyTimes();
EasyMock.replay(cd);
EasyMock.expect(svcDef.getDispatch()).andReturn(cd).anyTimes();
EasyMock.replay(svcDef);
ServiceDefinitionDeploymentContributor sddc = new ServiceDefinitionDeploymentContributor(svcDef, svcRules);
DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
EasyMock.expect(context.getDescriptor("rewrite")).andReturn(clusterRules).anyTimes();
GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(gc.isXForwardedEnabled()).andReturn(false).anyTimes();
EasyMock.expect(gc.isCookieScopingToPathEnabled()).andReturn(false).anyTimes();
EasyMock.replay(gc);
EasyMock.expect(context.getGatewayConfig()).andReturn(gc).anyTimes();
// Configure the HaProvider
Topology topology = EasyMock.createNiceMock(Topology.class);
List<Provider> providers = new ArrayList<>();
Provider haProvider = EasyMock.createNiceMock(Provider.class);
EasyMock.expect(haProvider.getRole()).andReturn("ha").anyTimes();
EasyMock.expect(haProvider.isEnabled()).andReturn(true).anyTimes();
Map<String, String> providerParams = new HashMap<>();
providerParams.put(TEST_SERVICE_ROLE, "whatever");
EasyMock.expect(haProvider.getParams()).andReturn(providerParams).anyTimes();
EasyMock.replay(haProvider);
providers.add(haProvider);
EasyMock.expect(topology.getProviders()).andReturn(providers).anyTimes();
EasyMock.replay(topology);
EasyMock.expect(context.getTopology()).andReturn(topology).anyTimes();
TestGatewayDescriptor gd = new TestGatewayDescriptor();
EasyMock.expect(context.getGatewayDescriptor()).andReturn(gd).anyTimes();
EasyMock.replay(context);
// Configure the service with the useTwoWaySsl param to OVERRIDE the value in the service definition
Service service = EasyMock.createNiceMock(Service.class);
Map<String, String> svcParams = new HashMap<>();
svcParams.put(USE_TWO_WAY_SSL_PARAM, "true");
EasyMock.expect(service.getParams()).andReturn(svcParams).anyTimes();
EasyMock.replay(service);
sddc.contributeService(context, service);
List<ResourceDescriptor> resources = gd.resources();
assertEquals(1, gd.resources().size());
ResourceDescriptor res = gd.resources().get(0);
assertNotNull(res);
List<FilterDescriptor> filterList = res.filters();
assertEquals(1, filterList.size());
FilterDescriptor f = filterList.get(0);
assertNotNull(f);
assertEquals("dispatch", f.role());
List<FilterParamDescriptor> fParams = f.params();
assertNotNull(fParams);
// Collect the values of filter params named useTwoWaySsl
List<String> useTwoWaySslFilterParamValues = new ArrayList<>();
for (FilterParamDescriptor param : fParams) {
if (param.name().equals(USE_TWO_WAY_SSL_PARAM)) {
useTwoWaySslFilterParamValues.add(param.value());
}
}
assertEquals("Expected only a single filter param named " + USE_TWO_WAY_SSL_PARAM, 1, useTwoWaySslFilterParamValues.size());
assertEquals("Expected the service param to override the service definition value for " + USE_TWO_WAY_SSL_PARAM, "true", useTwoWaySslFilterParamValues.get(0));
}
Aggregations