use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class GatewayFilterTest method testNoFilters.
@Test
public void testNoFilters() throws ServletException, IOException {
FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.replay(config);
HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(request.getPathInfo()).andReturn("source").anyTimes();
EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig).anyTimes();
EasyMock.expect(gatewayConfig.getHeaderNameForRemoteAddress()).andReturn("Custom-Forwarded-For").anyTimes();
EasyMock.replay(request);
EasyMock.replay(context);
EasyMock.replay(gatewayConfig);
HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
EasyMock.replay(response);
FilterChain chain = EasyMock.createNiceMock(FilterChain.class);
EasyMock.replay(chain);
GatewayFilter gateway = new GatewayFilter();
gateway.init(config);
gateway.doFilter(request, response, chain);
gateway.destroy();
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class GatewayFilterTest method testTargetServiceRoleRequestAttribute.
@Test
public void testTargetServiceRoleRequestAttribute() throws Exception {
FilterConfig config = EasyMock.createNiceMock(FilterConfig.class);
EasyMock.replay(config);
HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(request.getPathInfo()).andReturn("test-path/test-resource").anyTimes();
EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes();
EasyMock.expect(context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig).anyTimes();
EasyMock.expect(gatewayConfig.getHeaderNameForRemoteAddress()).andReturn("Custom-Forwarded-For").anyTimes();
request.setAttribute(AbstractGatewayFilter.TARGET_SERVICE_ROLE, "test-role");
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(request.getAttribute(AbstractGatewayFilter.TARGET_SERVICE_ROLE)).andReturn("test-role").anyTimes();
EasyMock.replay(request);
EasyMock.replay(context);
EasyMock.replay(gatewayConfig);
HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
EasyMock.replay(response);
TestRoleFilter filter = new TestRoleFilter();
GatewayFilter gateway = new GatewayFilter();
gateway.addFilter("test-path/**", "test-filter", filter, null, "test-role");
gateway.init(config);
gateway.doFilter(request, response);
gateway.destroy();
assertThat((String) filter.role, is("test-role"));
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class TopologiesResource method getTopologies.
@GET
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Path(TOPOLOGIES_API_PATH)
public SimpleTopologyWrapper getTopologies() {
GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
ArrayList<SimpleTopology> st = new ArrayList<SimpleTopology>();
GatewayConfig conf = (GatewayConfig) request.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
for (org.apache.knox.gateway.topology.Topology t : ts.getTopologies()) {
st.add(getSimpleTopology(t, conf));
}
Collections.sort(st, new TopologyComparator());
SimpleTopologyWrapper stw = new SimpleTopologyWrapper();
for (SimpleTopology t : st) {
stw.topologies.add(t);
}
return stw;
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class DefaultServiceDefinitionRegistryTest method matchSimplePattern.
@Test
public void matchSimplePattern() throws Exception {
DefaultServiceDefinitionRegistry registry = new DefaultServiceDefinitionRegistry();
GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
URL url = ClassLoader.getSystemResource("services");
EasyMock.expect(config.getGatewayServicesDir()).andReturn(new File(url.getFile()).getAbsolutePath()).anyTimes();
EasyMock.replay(config);
registry.init(config, null);
ServiceDefEntry entry = registry.getMatchingService("/foo/somepath");
assertThat(entry.getRole(), is("FOO"));
entry = registry.getMatchingService("/bar/?somepath");
assertThat(entry.getRole(), is("BAR"));
}
use of org.apache.knox.gateway.config.GatewayConfig in project knox by apache.
the class CryptoServiceTest method testConfigurableEncryptor.
@Test
public void testConfigurableEncryptor() throws Exception {
GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(config.getAlgorithm()).andReturn("AES");
EasyMock.expect(config.getPBEAlgorithm()).andReturn("PBKDF2WithHmacSHA1");
EasyMock.expect(config.getSaltSize()).andReturn("16");
EasyMock.expect(config.getIterationCount()).andReturn("65536");
EasyMock.expect(config.getKeyLength()).andReturn("128");
EasyMock.expect(config.getTransformation()).andReturn("AES/CBC/PKCS5Padding");
EasyMock.replay(config);
// password to create key - same Encryptor
ConfigurableEncryptor aes = new ConfigurableEncryptor("Test");
aes.init(config);
EncryptionResult result = aes.encrypt("larry".getBytes("UTF8"));
byte[] decrypted = aes.decrypt(result.salt, result.iv, result.cipher);
assertEquals(new String(decrypted, "UTF8"), "larry");
// password to create key - different Encryptor
ConfigurableEncryptor aes2 = new ConfigurableEncryptor("Test");
aes2.init(config);
decrypted = aes2.decrypt(result.salt, result.iv, result.cipher);
assertEquals(new String(decrypted, "UTF8"), "larry");
// password to create key resolved from alias - same Encryptor
ConfigurableEncryptor aes3 = new ConfigurableEncryptor(new String(as.getPasswordFromAliasForCluster("test", "encrypt_url")));
aes3.init(config);
result = aes3.encrypt("larry".getBytes("UTF8"));
decrypted = aes3.decrypt(result.salt, result.iv, result.cipher);
assertEquals(new String(decrypted, "UTF8"), "larry");
// password to create key resolved from alias - different Encryptor
ConfigurableEncryptor aes4 = new ConfigurableEncryptor(new String(as.getPasswordFromAliasForCluster("test", "encrypt_url")));
aes4.init(config);
decrypted = aes4.decrypt(result.salt, result.iv, result.cipher);
assertEquals(new String(decrypted, "UTF8"), "larry");
}
Aggregations