Search in sources :

Example 1 with GatewayTestConfig

use of org.apache.knox.gateway.GatewayTestConfig in project knox by apache.

the class DeploymentFactoryFuncTest method testDeploymentWithApplication.

@Test(timeout = MEDIUM_TIMEOUT)
public void testDeploymentWithApplication() throws Exception {
    LOG_ENTER();
    GatewayConfig config = new GatewayTestConfig();
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    ((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File deployDir = new File(config.getGatewayDeploymentDir());
    deployDir.mkdirs();
    URL serviceUrl = TestUtils.getResourceUrl(DeploymentFactoryFuncTest.class, "test-apps/minimal-test-app/service.xml");
    File serviceFile = new File(serviceUrl.toURI());
    File appsDir = serviceFile.getParentFile().getParentFile();
    ((GatewayTestConfig) config).setGatewayApplicationsDir(appsDir.getAbsolutePath());
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        DeploymentFactory.setGatewayServices(srvcs);
        srvcs.init(config, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    Topology topology = new Topology();
    topology.setName("test-topology");
    Application app;
    app = new Application();
    app.setName("minimal-test-app");
    app.addUrl("/minimal-test-app-path");
    topology.addApplication(app);
    EnterpriseArchive archive = DeploymentFactory.createDeployment(config, topology);
    assertThat(archive, notNullValue());
    Document doc;
    doc = XmlUtils.readXml(archive.get("META-INF/topology.xml").getAsset().openStream());
    assertThat(doc, notNullValue());
    doc = XmlUtils.readXml(archive.get("%2Fminimal-test-app-path/WEB-INF/gateway.xml").getAsset().openStream());
    assertThat(doc, notNullValue());
    // dump( doc );
    assertThat(doc, hasXPath("/gateway/resource/pattern", equalTo("/**?**")));
    assertThat(doc, hasXPath("/gateway/resource/filter[1]/role", equalTo("xforwardedheaders")));
    assertThat(doc, hasXPath("/gateway/resource/filter[1]/name", equalTo("XForwardedHeaderFilter")));
    assertThat(doc, hasXPath("/gateway/resource/filter[1]/class", equalTo(XForwardedHeaderFilter.class.getName())));
    assertThat(doc, hasXPath("/gateway/resource/filter[2]/role", equalTo("rewrite")));
    assertThat(doc, hasXPath("/gateway/resource/filter[2]/name", equalTo("url-rewrite")));
    assertThat(doc, hasXPath("/gateway/resource/filter[2]/class", equalTo(UrlRewriteServletFilter.class.getName())));
    LOG_EXIT();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) UrlRewriteServletFilter(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) URL(java.net.URL) XForwardedHeaderFilter(org.apache.knox.gateway.filter.XForwardedHeaderFilter) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) Application(org.apache.knox.gateway.topology.Application) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 2 with GatewayTestConfig

use of org.apache.knox.gateway.GatewayTestConfig in project knox by apache.

the class DeploymentFactoryFuncTest method testDeploymentWithServiceParams.

@Test(timeout = LONG_TIMEOUT)
public void testDeploymentWithServiceParams() throws Exception {
    LOG_ENTER();
    GatewayConfig config = new GatewayTestConfig();
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    ((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File deployDir = new File(config.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        DeploymentFactory.setGatewayServices(srvcs);
        srvcs.init(config, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    Service service;
    Param param;
    Topology topology = new Topology();
    topology.setName("test-cluster");
    service = new Service();
    service.setRole("HIVE");
    service.setUrls(Arrays.asList(new String[] { "http://hive-host:50001/" }));
    param = new Param();
    param.setName("someparam");
    param.setValue("somevalue");
    service.addParam(param);
    topology.addService(service);
    service = new Service();
    service.setRole("WEBHBASE");
    service.setUrls(Arrays.asList(new String[] { "http://hbase-host:50002/" }));
    param = new Param();
    param.setName("replayBufferSize");
    param.setValue("33");
    service.addParam(param);
    topology.addService(service);
    service = new Service();
    service.setRole("OOZIE");
    service.setUrls(Arrays.asList(new String[] { "http://hbase-host:50003/" }));
    param = new Param();
    param.setName("otherparam");
    param.setValue("65");
    service.addParam(param);
    topology.addService(service);
    EnterpriseArchive war = DeploymentFactory.createDeployment(config, topology);
    Document doc = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
    // dump( doc );
    Node resourceNode, filterNode, paramNode;
    String value;
    resourceNode = node(doc, "gateway/resource[role/text()='HIVE']");
    assertThat(resourceNode, is(not(nullValue())));
    filterNode = node(resourceNode, "filter[role/text()='dispatch']");
    assertThat(filterNode, is(not(nullValue())));
    paramNode = node(filterNode, "param[name/text()='someparam']");
    value = value(paramNode, "value/text()");
    assertThat(value, is("somevalue"));
    resourceNode = node(doc, "gateway/resource[role/text()='WEBHBASE']");
    assertThat(resourceNode, is(not(nullValue())));
    filterNode = node(resourceNode, "filter[role/text()='dispatch']");
    assertThat(filterNode, is(not(nullValue())));
    paramNode = node(filterNode, "param[name/text()='replayBufferSize']");
    value = value(paramNode, "value/text()");
    assertThat(value, is("33"));
    resourceNode = node(doc, "gateway/resource[role/text()='OOZIE']");
    assertThat(resourceNode, is(not(nullValue())));
    filterNode = node(resourceNode, "filter[role/text()='dispatch']");
    assertThat(filterNode, is(not(nullValue())));
    paramNode = node(filterNode, "param[name/text()='otherparam']");
    value = value(paramNode, "value/text()");
    assertThat(value, is("65"));
    FileUtils.deleteQuietly(deployDir);
    LOG_EXIT();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) Param(org.apache.knox.gateway.topology.Param) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 3 with GatewayTestConfig

use of org.apache.knox.gateway.GatewayTestConfig in project knox by apache.

the class DeploymentFactoryFuncTest method testWebXmlGeneration.

@Test(timeout = LONG_TIMEOUT)
public void testWebXmlGeneration() throws IOException, SAXException, ParserConfigurationException, URISyntaxException {
    LOG_ENTER();
    GatewayConfig config = new GatewayTestConfig();
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    ((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File deployDir = new File(config.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        DeploymentFactory.setGatewayServices(srvcs);
        srvcs.init(config, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    Topology topology = new Topology();
    topology.setName("test-cluster");
    Service service = new Service();
    service.setRole("WEBHDFS");
    service.addUrl("http://localhost:50070/webhdfs");
    topology.addService(service);
    Provider provider = new Provider();
    provider.setRole("authentication");
    provider.setName("ShiroProvider");
    provider.setEnabled(true);
    Param param = new Param();
    param.setName("contextConfigLocation");
    param.setValue("classpath:app-context-security.xml");
    provider.addParam(param);
    topology.addProvider(provider);
    Provider asserter = new Provider();
    asserter.setRole("identity-assertion");
    asserter.setName("Default");
    asserter.setEnabled(true);
    topology.addProvider(asserter);
    Provider authorizer = new Provider();
    authorizer.setRole("authorization");
    authorizer.setName("AclsAuthz");
    authorizer.setEnabled(true);
    topology.addProvider(authorizer);
    Provider ha = new Provider();
    ha.setRole("ha");
    ha.setName("HaProvider");
    ha.setEnabled(true);
    topology.addProvider(ha);
    for (int i = 0; i < 10; i++) {
        createAndTestDeployment(config, topology);
    }
    LOG_EXIT();
}
Also used : HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) Provider(org.apache.knox.gateway.topology.Provider) Param(org.apache.knox.gateway.topology.Param) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 4 with GatewayTestConfig

use of org.apache.knox.gateway.GatewayTestConfig in project knox by apache.

the class DeploymentFactoryFuncTest method testServiceAnonAuth.

/**
 * Test the case where topology has federation provider configured
 * and service uses anonymous authentication in which case we should
 * add AnonymousFilter to the filter chain.
 * @since 1.1.0
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws URISyntaxException
 * @throws TransformerException
 */
@Test(timeout = MEDIUM_TIMEOUT)
public void testServiceAnonAuth() throws IOException, SAXException, ParserConfigurationException, URISyntaxException, TransformerException {
    LOG_ENTER();
    final GatewayConfig config = new GatewayTestConfig();
    ((GatewayTestConfig) config).setXForwardedEnabled(false);
    final File targetDir = new File(System.getProperty("user.dir"), "target");
    final File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    ((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
    final File deployDir = new File(config.getGatewayDeploymentDir());
    deployDir.mkdirs();
    final DefaultGatewayServices srvcs = new DefaultGatewayServices();
    final Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        DeploymentFactory.setGatewayServices(srvcs);
        srvcs.init(config, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    final Topology federationTopology = new Topology();
    final Topology authenticationTopology = new Topology();
    federationTopology.setName("test-cluster");
    authenticationTopology.setName("test-cluster");
    final Service service = new Service();
    service.setRole("RANGER");
    service.addUrl("http://localhost:50070/");
    federationTopology.addService(service);
    authenticationTopology.addService(service);
    /* Add federation provider to first topology */
    final Provider provider = new Provider();
    provider.setRole("federation");
    provider.setName("SSOCookieProvider");
    provider.setEnabled(true);
    Param param = new Param();
    param.setName("sso.authentication.provider.url");
    param.setValue("https://www.local.com:8443/gateway/knoxsso/api/v1/websso");
    provider.addParam(param);
    federationTopology.addProvider(provider);
    /* Add authentication provider to second topology */
    final Provider provider2 = new Provider();
    provider2.setRole("authentication");
    provider2.setName("ShiroProvider");
    provider2.setEnabled(true);
    Param param2 = new Param();
    param2.setName("contextConfigLocation");
    param2.setValue("classpath:app-context-security.xml");
    provider2.addParam(param2);
    authenticationTopology.addProvider(provider2);
    final Provider asserter = new Provider();
    asserter.setRole("identity-assertion");
    asserter.setName("Default");
    asserter.setEnabled(true);
    federationTopology.addProvider(asserter);
    Provider authorizer = new Provider();
    authorizer.setRole("authorization");
    authorizer.setName("AclsAuthz");
    authorizer.setEnabled(true);
    federationTopology.addProvider(authorizer);
    authenticationTopology.addProvider(authorizer);
    final EnterpriseArchive war = DeploymentFactory.createDeployment(config, federationTopology);
    final EnterpriseArchive war2 = DeploymentFactory.createDeployment(config, federationTopology);
    final Document web = XmlUtils.readXml(war.get("%2F/WEB-INF/web.xml").getAsset().openStream());
    final Document web2 = XmlUtils.readXml(war2.get("%2F/WEB-INF/web.xml").getAsset().openStream());
    /* Make sure AnonymousAuthFilter is added to the chain */
    final Document gateway = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
    assertThat(gateway, hasXPath("/gateway/resource[1]/pattern", equalTo("/ranger/service/public/**")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/role", equalTo("authentication")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[1]/class", equalTo("org.apache.knox.gateway.filter.AnonymousAuthFilter")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/role", equalTo("rewrite")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[2]/class", equalTo("org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[3]/role", equalTo("authorization")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[3]/class", equalTo("org.apache.knox.gateway.filter.AclsAuthorizationFilter")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/role", equalTo("dispatch")));
    assertThat(gateway, hasXPath("/gateway/resource[1]/filter[4]/class", equalTo("org.apache.knox.gateway.dispatch.GatewayDispatchFilter")));
    final Document gateway2 = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
    assertThat(gateway2, hasXPath("/gateway/resource[1]/pattern", equalTo("/ranger/service/public/**")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[1]/role", equalTo("authentication")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[1]/class", equalTo("org.apache.knox.gateway.filter.AnonymousAuthFilter")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[2]/role", equalTo("rewrite")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[2]/class", equalTo("org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[3]/role", equalTo("authorization")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[3]/class", equalTo("org.apache.knox.gateway.filter.AclsAuthorizationFilter")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[4]/role", equalTo("dispatch")));
    assertThat(gateway2, hasXPath("/gateway/resource[1]/filter[4]/class", equalTo("org.apache.knox.gateway.dispatch.GatewayDispatchFilter")));
    LOG_EXIT();
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) HashMap(java.util.HashMap) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Service(org.apache.knox.gateway.topology.Service) Topology(org.apache.knox.gateway.topology.Topology) Document(org.w3c.dom.Document) GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) Provider(org.apache.knox.gateway.topology.Provider) Param(org.apache.knox.gateway.topology.Param) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 5 with GatewayTestConfig

use of org.apache.knox.gateway.GatewayTestConfig in project testcases by coheigea.

the class KnoxRangerTest method setupSuite.

@BeforeClass
public static void setupSuite() throws Exception {
    driver.setResourceBase(KnoxRangerTest.class);
    driver.setupLdap(0);
    GatewayTestConfig config = new GatewayTestConfig();
    driver.setupService("WEBHDFS", "http://localhost:50070/webhdfs", "/cluster/webhdfs", true);
    driver.setupService("STORM", "http://localhost:8477", "/cluster/storm", true);
    driver.setupService("SOLR", "http://localhost:8983", "/cluster/solr", true);
    driver.setupService("WEBHBASE", "http://localhost:60080", "/cluster/hbase", true);
    driver.setupService("KAFKA", "http://localhost:8477", "/cluster/kafka", true);
    driver.setupGateway(config, "cluster", createTopology(), true);
}
Also used : GatewayTestConfig(org.apache.knox.gateway.GatewayTestConfig) BeforeClass(org.junit.BeforeClass)

Aggregations

GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)11 File (java.io.File)8 HashMap (java.util.HashMap)8 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)8 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)8 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)8 Topology (org.apache.knox.gateway.topology.Topology)8 Test (org.junit.Test)8 Service (org.apache.knox.gateway.topology.Service)7 Param (org.apache.knox.gateway.topology.Param)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)6 Document (org.w3c.dom.Document)6 Provider (org.apache.knox.gateway.topology.Provider)5 BeforeClass (org.junit.BeforeClass)3 URL (java.net.URL)2 Application (org.apache.knox.gateway.topology.Application)2 XForwardedHeaderFilter (org.apache.knox.gateway.filter.XForwardedHeaderFilter)1 UrlRewriteServletFilter (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletFilter)1 NoOpAppender (org.apache.knox.test.log.NoOpAppender)1 Appender (org.apache.log4j.Appender)1