Repository: knox Updated Branches: refs/heads/master f51d09e05 -> 82b2f45df
KNOX-1613 - LDAP related tests time out after waiting 10 seconds Signed-off-by: Kevin Risden <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/82b2f45d Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/82b2f45d Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/82b2f45d Branch: refs/heads/master Commit: 82b2f45dfc4e6b6e59d8f4b905c01d18dcbfbc0d Parents: f51d09e Author: Kevin Risden <[email protected]> Authored: Mon Nov 19 10:10:16 2018 -0500 Committer: Kevin Risden <[email protected]> Committed: Tue Nov 20 13:36:03 2018 -0500 ---------------------------------------------------------------------- .../apache/knox/gateway/GatewayTestDriver.java | 18 ++- .../GatewayLdapDynamicGroupFuncTest.java | 125 ++++-------------- .../knox/gateway/GatewayLdapGroupFuncTest.java | 128 ++++--------------- .../gateway/GatewayLdapPosixGroupFuncTest.java | 103 ++++----------- .../apache/knox/gateway/Knox242FuncTest.java | 105 ++++----------- 5 files changed, 102 insertions(+), 377 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/82b2f45d/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java ---------------------------------------------------------------------- diff --git a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java index 1a1f784..aa41bea 100644 --- a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java +++ b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java @@ -72,6 +72,7 @@ public class GatewayTestDriver { public GatewayServer gateway; public GatewayConfig config; public String clusterName; + public DefaultGatewayServices srvcs; /** * Sets the class from which relative test resource names should be resolved. @@ -148,26 +149,33 @@ public class GatewayTestDriver { topology.toStream( stream ); stream.close(); - DefaultGatewayServices srvcs = new DefaultGatewayServices(); + this.srvcs = new DefaultGatewayServices(); Map<String,String> options = new HashMap<>(); options.put("persist-master", "false"); options.put("master", "password"); try { - srvcs.init(config, options); + this.srvcs.init(config, options); } catch (ServiceLifecycleException e) { e.printStackTrace(); // I18N not required. } + start(); + } + + public void start() throws Exception { gateway = GatewayServer.startGateway( config, srvcs ); MatcherAssert.assertThat( "Failed to start gateway.", gateway, CoreMatchers.notNullValue() ); - log.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() ); } - public void cleanup() throws Exception { - if ( gateway != null ) { + public void stop() throws Exception { + if (gateway != null) { gateway.stop(); } + } + + public void cleanup() throws Exception { + stop(); if ( config != null ) { FileUtils.deleteQuietly( new File( config.getGatewayTopologyDir() ) ); FileUtils.deleteQuietly( new File( config.getGatewayConfDir() ) ); http://git-wip-us.apache.org/repos/asf/knox/blob/82b2f45d/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapDynamicGroupFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapDynamicGroupFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapDynamicGroupFuncTest.java index c8d2e8e..436f2ba 100755 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapDynamicGroupFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapDynamicGroupFuncTest.java @@ -21,33 +21,20 @@ import static io.restassured.RestAssured.given; import static org.apache.knox.test.TestUtils.LOG_ENTER; import static org.apache.knox.test.TestUtils.LOG_EXIT; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; import java.net.URL; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.apache.knox.gateway.config.GatewayConfig; -import org.apache.knox.gateway.services.DefaultGatewayServices; import org.apache.knox.gateway.services.GatewayServices; -import org.apache.knox.gateway.services.ServiceLifecycleException; import org.apache.knox.gateway.services.security.AliasService; import org.apache.knox.test.TestUtils; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; -import org.hamcrest.MatcherAssert; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; @@ -58,21 +45,12 @@ import com.mycila.xmltool.XMLTag; * */ public class GatewayLdapDynamicGroupFuncTest { - - private static Logger LOG = LoggerFactory.getLogger( GatewayLdapDynamicGroupFuncTest.class ); - - public static Enumeration<Appender> appenders; - public static GatewayConfig config; - public static GatewayServer gateway; - public static String gatewayUrl; - public static String clusterUrl; - public static String serviceUrl; - private static GatewayTestDriver driver = new GatewayTestDriver(); + private static final GatewayTestDriver driver = new GatewayTestDriver(); + private static final String cluster = "test-cluster"; @BeforeClass public static void setupSuite() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUp(); String basedir = System.getProperty("basedir"); if (basedir == null) { basedir = new File(".").getCanonicalPath(); @@ -80,89 +58,35 @@ public class GatewayLdapDynamicGroupFuncTest { Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/users-dynamic.ldif"); driver.setupLdap( 0, path.toFile() ); setupGateway(); - TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); LOG_EXIT(); } @AfterClass public static void cleanupSuite() throws Exception { LOG_ENTER(); - gateway.stop(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.tearDown( appenders ); LOG_EXIT(); } - public static void setupGateway() throws IOException, 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(); - - DefaultGatewayServices srvcs = new DefaultGatewayServices(); - Map<String,String> options = new HashMap<>(); - options.put( "persist-master", "false" ); - options.put( "master", "password" ); - try { - srvcs.init( testConfig, options ); - } catch ( ServiceLifecycleException e ) { - e.printStackTrace(); // I18N not required. - } - - /* - System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath()); - System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR)); - ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - System.setOut(new PrintStream(outContent)); - String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "testdg-cluster"}; - KnoxCLI cli = new KnoxCLI(); - cli.setConf(new GatewayConfigImpl()); - cli.run(argvals); - - outContent.reset(); - String[] args1 = {"list-alias", "--cluster", "testdg-cluster", "--master", "hadoop"}; - cli = new KnoxCLI(); - cli.run(args1); - System.err.println("ALIAS LIST: " + outContent.toString()); - - AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE); - char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword"); - System.err.println("ALIAS value1: " + new String(passwordChars1)); - */ - - 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 + "/testdg-cluster"; - serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + public static void setupGateway() throws Exception { + GatewayTestConfig config = new GatewayTestConfig(); + XMLTag topology = createTopology(); + driver.setupGateway(config, cluster, topology, true); + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); - ///* GatewayServices services = GatewayServer.getGatewayServices(); - AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE); - aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password"); + AliasService aliasService = services.getService(GatewayServices.ALIAS_SERVICE); + aliasService.addAliasForCluster(cluster, "ldcSystemPassword", "guest-password"); - //char[] password1 = aliasService.getPasswordFromAliasForCluster( "testdg-cluster", "ldcSystemPassword"); - //System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1))); + driver.stop(); + driver.start(); - File descriptor = new File( topoDir, "testdg-cluster.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + File descriptor = new File( driver.config.getGatewayTopologyDir(), cluster + ".xml" ); + assertTrue(descriptor.setLastModified(System.currentTimeMillis())); + serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); } private static XMLTag createTopology() { @@ -215,7 +139,7 @@ public class GatewayLdapDynamicGroupFuncTest { .addTag( "value" ).addText( "uid=guest,ou=people,dc=hadoop,dc=apache,dc=org" ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.clusterName" ) - .addTag( "value" ).addText( "testdg-cluster" ) + .addTag( "value" ).addText( cluster ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemPassword" ) .addTag( "value" ).addText( "S{ALIAS=ldcSystemPassword}" ) @@ -245,17 +169,12 @@ public class GatewayLdapDynamicGroupFuncTest { return xml; } - // @Test - public void waitForManualTesting() throws IOException { - System.in.read(); - } - @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testGroupMember() throws ClassNotFoundException, Exception { + public void testGroupMember() { LOG_ENTER(); String username = "bob"; String password = "bob-password"; - String serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password ) @@ -269,11 +188,11 @@ public class GatewayLdapDynamicGroupFuncTest { } @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testNonGroupMember() throws ClassNotFoundException { + public void testNonGroupMember() { LOG_ENTER(); String username = "guest"; String password = "guest-password"; - String serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password ) http://git-wip-us.apache.org/repos/asf/knox/blob/82b2f45d/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapGroupFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapGroupFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapGroupFuncTest.java index c439328..2956ecf 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapGroupFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapGroupFuncTest.java @@ -21,33 +21,18 @@ import static io.restassured.RestAssured.given; import static org.apache.knox.test.TestUtils.LOG_ENTER; import static org.apache.knox.test.TestUtils.LOG_EXIT; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; import java.net.URL; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.knox.gateway.config.GatewayConfig; -import org.apache.knox.gateway.services.DefaultGatewayServices; import org.apache.knox.gateway.services.GatewayServices; -import org.apache.knox.gateway.services.ServiceLifecycleException; import org.apache.knox.gateway.services.security.AliasService; import org.apache.knox.test.TestUtils; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; -import org.hamcrest.MatcherAssert; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; @@ -58,106 +43,43 @@ import com.mycila.xmltool.XMLTag; * */ public class GatewayLdapGroupFuncTest { - - private static Logger LOG = LoggerFactory.getLogger( GatewayLdapGroupFuncTest.class ); - - public static Enumeration<Appender> appenders; - public static GatewayConfig config; - public static GatewayServer gateway; - public static String gatewayUrl; - public static String clusterUrl; - public static String serviceUrl; - private static GatewayTestDriver driver = new GatewayTestDriver(); + private static final GatewayTestDriver driver = new GatewayTestDriver(); + private static final String cluster = "test-cluster"; @BeforeClass public static void setupSuite() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUp(); driver.setupLdap(0); setupGateway(); - TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); LOG_EXIT(); } @AfterClass public static void cleanupSuite() throws Exception { LOG_ENTER(); - gateway.stop(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.tearDown( appenders ); LOG_EXIT(); } public static void setupGateway() throws Exception { + GatewayTestConfig config = new GatewayTestConfig(); + XMLTag topology = createTopology(); + driver.setupGateway(config, cluster, topology, true); + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); - 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(); - - DefaultGatewayServices srvcs = new DefaultGatewayServices(); - Map<String,String> options = new HashMap<>(); - options.put( "persist-master", "true" ); - options.put( "master", "hadoop" ); - - try { - srvcs.init( testConfig, options ); - } catch ( ServiceLifecycleException e ) { - e.printStackTrace(); // I18N not required. - } - - /* - System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath()); - System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR)); - ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - System.setOut(new PrintStream(outContent)); - String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "test-cluster"}; - KnoxCLI cli = new KnoxCLI(); - cli.setConf(new GatewayConfigImpl()); - cli.run(argvals); - - outContent.reset(); - String[] args1 = {"list-alias", "--cluster", "test-cluster", "--master", "hadoop"}; - cli = new KnoxCLI(); - cli.run(args1); - System.err.println("ALIAS LIST: " + outContent.toString()); - - AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE); - char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword"); - System.err.println("ALIAS value1: " + new String(passwordChars1)); - */ - - 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"; - serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; - - ///* GatewayServices services = GatewayServer.getGatewayServices(); - AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE); - aliasService.addAliasForCluster("test-cluster", "ldcSystemPassword", "guest-password"); + AliasService aliasService = services.getService(GatewayServices.ALIAS_SERVICE); + aliasService.addAliasForCluster(cluster, "ldcSystemPassword", "guest-password"); + + driver.stop(); + driver.start(); - // char[] password1 = aliasService.getPasswordFromAliasForCluster( "test-cluster", "ldcSystemPassword"); - //System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1))); + File descriptor = new File( driver.config.getGatewayTopologyDir(), cluster + ".xml" ); + assertTrue(descriptor.setLastModified(System.currentTimeMillis())); - File descriptor = new File( topoDir, "test-cluster.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); } private static XMLTag createTopology() { @@ -207,7 +129,7 @@ public class GatewayLdapGroupFuncTest { .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.clusterName" ) - .addTag( "value" ).addText( "test-cluster" ) + .addTag( "value" ).addText( cluster ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemUsername" ) .addTag( "value" ).addText( "uid=guest,ou=people,dc=hadoop,dc=apache,dc=org" ) @@ -239,18 +161,12 @@ public class GatewayLdapGroupFuncTest { return xml; } - @Ignore - // @Test - public void waitForManualTesting() throws IOException { - System.in.read(); - } - @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testGroupMember() throws ClassNotFoundException, Exception { + public void testGroupMember() { LOG_ENTER(); String username = "sam"; String password = "sam-password"; - String serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password ) @@ -264,11 +180,11 @@ public class GatewayLdapGroupFuncTest { } @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testNonGroupMember() throws ClassNotFoundException { + public void testNonGroupMember() { LOG_ENTER(); String username = "guest"; String password = "guest-password"; - String serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password ) http://git-wip-us.apache.org/repos/asf/knox/blob/82b2f45d/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapPosixGroupFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapPosixGroupFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapPosixGroupFuncTest.java index 2baddf4..e4872ae 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapPosixGroupFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayLdapPosixGroupFuncTest.java @@ -19,39 +19,24 @@ package org.apache.knox.gateway; import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; -import org.apache.knox.gateway.config.GatewayConfig; -import org.apache.knox.gateway.services.DefaultGatewayServices; import org.apache.knox.gateway.services.GatewayServices; -import org.apache.knox.gateway.services.ServiceLifecycleException; import org.apache.knox.gateway.services.security.AliasService; import org.apache.knox.test.TestUtils; import org.apache.knox.test.category.ReleaseTest; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; -import org.hamcrest.MatcherAssert; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; import java.net.URL; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; import static io.restassured.RestAssured.given; import static org.apache.knox.test.TestUtils.LOG_ENTER; import static org.apache.knox.test.TestUtils.LOG_EXIT; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertTrue; /** * Functional test to verify : looking up ldap groups from directory @@ -60,85 +45,45 @@ import static org.hamcrest.CoreMatchers.notNullValue; */ @Category(ReleaseTest.class) public class GatewayLdapPosixGroupFuncTest { - - private static Logger LOG = LoggerFactory.getLogger( GatewayLdapPosixGroupFuncTest.class ); - - public static Enumeration<Appender> appenders; - public static GatewayConfig config; - public static GatewayServer gateway; - public static String gatewayUrl; - public static String clusterUrl; - public static String serviceUrl; - private static GatewayTestDriver driver = new GatewayTestDriver(); + private static final GatewayTestDriver driver = new GatewayTestDriver(); + private static final String cluster = "test-cluster"; @BeforeClass public static void setupSuite() throws Exception { LOG_ENTER(); - //appenders = NoOpAppender.setUp(); URL usersUrl = TestUtils.getResourceUrl( GatewayLdapPosixGroupFuncTest.class, "users.ldif" ); driver.setupLdap( 0, new File( usersUrl.toURI() ) ); setupGateway(); - TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); LOG_EXIT(); } @AfterClass public static void cleanupSuite() throws Exception { LOG_ENTER(); - gateway.stop(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.tearDown( appenders ); LOG_EXIT(); } 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(); - - DefaultGatewayServices srvcs = new DefaultGatewayServices(); - Map<String,String> options = new HashMap<>(); - options.put( "persist-master", "true" ); - options.put( "master", "hadoop" ); - - 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"; - serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + String cluster = "test-cluster"; + GatewayTestConfig config = new GatewayTestConfig(); + XMLTag topology = createTopology(); + driver.setupGateway(config, cluster, topology, true); + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); GatewayServices services = GatewayServer.getGatewayServices(); - AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE); - aliasService.addAliasForCluster("test-cluster", "ldcSystemPassword", "guest-password"); + AliasService aliasService = services.getService(GatewayServices.ALIAS_SERVICE); + aliasService.addAliasForCluster(cluster, "ldcSystemPassword", "guest-password"); - char[] password1 = aliasService.getPasswordFromAliasForCluster( "test-cluster", "ldcSystemPassword"); + driver.stop(); + driver.start(); - File descriptor = new File( topoDir, "test-cluster.xml" ); - OutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + File descriptor = new File( driver.config.getGatewayTopologyDir(), cluster + ".xml" ); + assertTrue(descriptor.setLastModified(System.currentTimeMillis())); + serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); } private static XMLTag createTopology() { @@ -188,7 +133,7 @@ public class GatewayLdapPosixGroupFuncTest { .addTag( "value" ).addText( "uid={0}" ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.clusterName" ) - .addTag( "value" ).addText( "test-cluster" ) + .addTag( "value" ).addText( cluster ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemUsername" ) .addTag( "value" ).addText( "uid=guest,ou=people,dc=hadoop,dc=apache,dc=org" ) @@ -220,17 +165,12 @@ public class GatewayLdapPosixGroupFuncTest { return xml; } - @Ignore - // @Test - public void waitForManualTesting() throws IOException { - System.in.read(); - } - @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testGroupMember() throws ClassNotFoundException, Exception { + public void testGroupMember() { LOG_ENTER(); String username = "sam"; String password = "sam-password"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password ) @@ -244,10 +184,11 @@ public class GatewayLdapPosixGroupFuncTest { } @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testNonGroupMember() throws ClassNotFoundException { + public void testNonGroupMember() { LOG_ENTER(); String username = "guest"; String password = "guest-password"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password ) http://git-wip-us.apache.org/repos/asf/knox/blob/82b2f45d/gateway-test/src/test/java/org/apache/knox/gateway/Knox242FuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/Knox242FuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/Knox242FuncTest.java index ab88f79..bd86f9b 100755 --- a/gateway-test/src/test/java/org/apache/knox/gateway/Knox242FuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/Knox242FuncTest.java @@ -21,34 +21,20 @@ import static io.restassured.RestAssured.given; import static org.apache.knox.test.TestUtils.LOG_ENTER; import static org.apache.knox.test.TestUtils.LOG_EXIT; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; import java.net.URL; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.apache.knox.gateway.config.GatewayConfig; -import org.apache.knox.gateway.services.DefaultGatewayServices; import org.apache.knox.gateway.services.GatewayServices; -import org.apache.knox.gateway.services.ServiceLifecycleException; import org.apache.knox.gateway.services.security.AliasService; import org.apache.knox.test.TestUtils; import org.apache.http.HttpStatus; -import org.apache.log4j.Appender; -import org.hamcrest.MatcherAssert; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; @@ -60,16 +46,8 @@ import com.mycila.xmltool.XMLTag; * */ public class Knox242FuncTest { - - private static Logger LOG = LoggerFactory.getLogger( Knox242FuncTest.class ); - - public static Enumeration<Appender> appenders; - public static GatewayConfig config; - public static GatewayServer gateway; - public static String gatewayUrl; - public static String clusterUrl; - public static String serviceUrl; - private static GatewayTestDriver driver = new GatewayTestDriver(); + private static final GatewayTestDriver driver = new GatewayTestDriver(); + private static final String cluster = "test-cluster"; @BeforeClass public static void setupSuite() throws Exception { @@ -82,66 +60,35 @@ public class Knox242FuncTest { Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/users-dynamic.ldif"); driver.setupLdap( 0 , path.toFile() ); setupGateway(); - TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); LOG_EXIT(); } @AfterClass public static void cleanupSuite() throws Exception { LOG_ENTER(); - gateway.stop(); driver.cleanup(); - //FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) ); - //NoOpAppender.tearDown( appenders ); LOG_EXIT(); } - public static void setupGateway() throws IOException, 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(); - - DefaultGatewayServices srvcs = new DefaultGatewayServices(); - Map<String,String> options = new HashMap<>(); - 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 + "/testdg-cluster"; - serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + public static void setupGateway() throws Exception { + GatewayTestConfig config = new GatewayTestConfig(); + XMLTag topology = createTopology(); + driver.setupGateway(config, cluster, topology, true); + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); GatewayServices services = GatewayServer.getGatewayServices(); - AliasService aliasService = (AliasService)services.getService(GatewayServices.ALIAS_SERVICE); - aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password"); + AliasService aliasService = services.getService(GatewayServices.ALIAS_SERVICE); + aliasService.addAliasForCluster(cluster, "ldcSystemPassword", "guest-password"); - // char[] password1 = aliasService.getPasswordFromAliasForCluster( "testdg-cluster", "ldcSystemPassword"); - //System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1))); + driver.stop(); + driver.start(); - File descriptor = new File( topoDir, "testdg-cluster.xml" ); - FileOutputStream stream = new FileOutputStream( descriptor ); - createTopology().toStream( stream ); - stream.close(); + File descriptor = new File( driver.config.getGatewayTopologyDir(), cluster + ".xml" ); + assertTrue(descriptor.setLastModified(System.currentTimeMillis())); + + serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; + TestUtils.awaitNon404HttpStatus( new URL( serviceUrl ), 10000, 100 ); } private static XMLTag createTopology() { @@ -209,7 +156,7 @@ public class Knox242FuncTest { .addTag( "value" ).addText( "uid=guest,ou=people,dc=hadoop,dc=apache,dc=org" ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.clusterName" ) - .addTag( "value" ).addText( "testdg-cluster" ) + .addTag( "value" ).addText( cluster ) .gotoParent().addTag( "param" ) .addTag( "name" ).addText( "main.ldapRealm.contextFactory.systemPassword" ) .addTag( "value" ).addText( "S{ALIAS=ldcSystemPassword}" ) @@ -239,18 +186,12 @@ public class Knox242FuncTest { return xml; } - @Ignore - // @Test - public void waitForManualTesting() throws IOException { - System.in.read(); - } - @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testGroupMember() throws ClassNotFoundException, Exception { + public void testGroupMember() { LOG_ENTER(); String username = "joe"; String password = "joe-password"; - String serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password ) @@ -264,11 +205,11 @@ public class Knox242FuncTest { } @Test( timeout = TestUtils.MEDIUM_TIMEOUT ) - public void testNonGroupMember() throws ClassNotFoundException { + public void testNonGroupMember() { LOG_ENTER(); String username = "guest"; String password = "guest-password"; - String serviceUrl = clusterUrl + "/test-service-path/test-service-resource"; + String serviceUrl = driver.getClusterUrl() + "/test-service-path/test-service-resource"; given() //.log().all() .auth().preemptive().basic( username, password )
