Repository: incubator-atlas Updated Branches: refs/heads/master 985465fc7 -> bca454e16
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java index e64e949..f38cffe 100644 --- a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java +++ b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java @@ -33,6 +33,8 @@ import static org.testng.Assert.assertEquals; @Guice(modules = NotificationModule.class) public class NotificationHookConsumerIT extends BaseResourceIT { + private static final String TEST_USER = "testuser"; + @Inject private NotificationInterface kafka; @@ -57,7 +59,7 @@ public class NotificationHookConsumerIT extends BaseResourceIT { entity.set("name", "db" + randomString()); entity.set("description", randomString()); - sendHookMessage(new HookNotification.EntityCreateRequest(entity)); + sendHookMessage(new HookNotification.EntityCreateRequest(TEST_USER, entity)); waitFor(MAX_WAIT_TIME, new Predicate() { @Override @@ -79,7 +81,8 @@ public class NotificationHookConsumerIT extends BaseResourceIT { final Referenceable newEntity = new Referenceable(DATABASE_TYPE); newEntity.set("owner", randomString()); - sendHookMessage(new HookNotification.EntityPartialUpdateRequest(DATABASE_TYPE, "name", dbName, newEntity)); + sendHookMessage( + new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "name", dbName, newEntity)); waitFor(MAX_WAIT_TIME, new Predicate() { @Override public boolean evaluate() throws Exception { @@ -105,7 +108,8 @@ public class NotificationHookConsumerIT extends BaseResourceIT { final String newName = "db" + randomString(); newEntity.set("name", newName); - sendHookMessage(new HookNotification.EntityPartialUpdateRequest(DATABASE_TYPE, "name", dbName, newEntity)); + sendHookMessage( + new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "name", dbName, newEntity)); waitFor(MAX_WAIT_TIME, new Predicate() { @Override public boolean evaluate() throws Exception { @@ -135,7 +139,7 @@ public class NotificationHookConsumerIT extends BaseResourceIT { newEntity.set("owner", randomString()); //updating unique attribute - sendHookMessage(new HookNotification.EntityUpdateRequest(newEntity)); + sendHookMessage(new HookNotification.EntityUpdateRequest(TEST_USER, newEntity)); waitFor(MAX_WAIT_TIME, new Predicate() { @Override public boolean evaluate() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationKerberosFilterIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationKerberosFilterIT.java b/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationKerberosFilterIT.java new file mode 100644 index 0000000..9e1e08f --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationKerberosFilterIT.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.web.filters; + +import org.apache.atlas.RequestContext; +import org.apache.atlas.web.security.BaseSecurityTest; +import org.apache.atlas.web.service.EmbeddedServer; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.io.FileUtils; +import org.apache.hadoop.hdfs.web.URLConnectionFactory; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.webapp.WebAppContext; +import org.testng.annotations.Test; + +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.PrivilegedExceptionAction; +import java.util.Properties; + +import static org.testng.Assert.assertEquals; + +/** + * + */ +public class AtlasAuthenticationKerberosFilterIT extends BaseSecurityTest { + public static final String TEST_USER_JAAS_SECTION = "TestUser"; + public static final String TESTUSER = "testuser"; + public static final String TESTPASS = "testpass"; + + private File userKeytabFile; + private File httpKeytabFile; + + class TestEmbeddedServer extends EmbeddedServer { + public TestEmbeddedServer(int port, String path) throws IOException { + super(port, path); + } + + Server getServer() { + return server; + } + + @Override + protected WebAppContext getWebAppContext(String path) { + WebAppContext application = new WebAppContext(path, "/"); + application.setDescriptor(System.getProperty("projectBaseDir") + "/webapp/src/test/webapp/WEB-INF/web.xml"); + application.setClassLoader(Thread.currentThread().getContextClassLoader()); + return application; + } + } + + @Test(enabled = false) + public void testKerberosBasedLogin() throws Exception { + String originalConf = System.getProperty("atlas.conf"); + System.setProperty("atlas.conf", System.getProperty("user.dir")); + + setupKDCAndPrincipals(); + TestEmbeddedServer server = null; + + try { + // setup the atlas-application.properties file + generateKerberosTestProperties(); + + // need to create the web application programmatically in order to control the injection of the test + // application properties + server = new TestEmbeddedServer(23000, "webapp/target/apache-atlas"); + + startEmbeddedServer(server.getServer()); + + final URLConnectionFactory connectionFactory = URLConnectionFactory.DEFAULT_SYSTEM_CONNECTION_FACTORY; + // attempt to hit server and get rejected + URL url = new URL("http://localhost:23000/"); + HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, false); + connection.setRequestMethod("GET"); + connection.connect(); + + assertEquals(connection.getResponseCode(), 401); + + // need to populate the ticket cache with a local user, so logging in... + Subject subject = loginTestUser(); + + Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { + @Override + public Object run() throws Exception { + // attempt to hit server and get rejected + URL url = new URL("http://localhost:23000/"); + HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, true); + connection.setRequestMethod("GET"); + connection.connect(); + + assertEquals(connection.getResponseCode(), 200); + assertEquals(RequestContext.get().getUser(), TESTUSER); + return null; + } + }); + } finally { + server.getServer().stop(); + kdc.stop(); + + if (originalConf != null) { + System.setProperty("atlas.conf", originalConf); + } else { + System.clearProperty("atlas.conf"); + } + + } + + + } + + protected Subject loginTestUser() throws LoginException, IOException { + LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() { + + @Override + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof PasswordCallback) { + PasswordCallback passwordCallback = (PasswordCallback) callbacks[i]; + passwordCallback.setPassword(TESTPASS.toCharArray()); + } + if (callbacks[i] instanceof NameCallback) { + NameCallback nameCallback = (NameCallback) callbacks[i]; + nameCallback.setName(TESTUSER); + } + } + } + }); + // attempt authentication + lc.login(); + return lc.getSubject(); + } + + protected void generateKerberosTestProperties() throws IOException, ConfigurationException { + Properties props = new Properties(); + props.setProperty("atlas.http.authentication.enabled", "true"); + props.setProperty("atlas.http.authentication.type", "kerberos"); + props.setProperty("atlas.http.authentication.kerberos.principal", "HTTP/localhost@" + kdc.getRealm()); + props.setProperty("atlas.http.authentication.kerberos.keytab", httpKeytabFile.getAbsolutePath()); + props.setProperty("atlas.http.authentication.kerberos.name.rules", + "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT"); + + generateTestProperties(props); + } + + public void setupKDCAndPrincipals() throws Exception { + // set up the KDC + File kdcWorkDir = startKDC(); + + userKeytabFile = createKeytab(kdc, kdcWorkDir, "dgi", "dgi.keytab"); + httpKeytabFile = createKeytab(kdc, kdcWorkDir, "HTTP", "spnego.service.keytab"); + + // create a test user principal + kdc.createPrincipal(TESTUSER, TESTPASS); + + StringBuilder jaas = new StringBuilder(1024); + jaas.append("TestUser {\n" + + " com.sun.security.auth.module.Krb5LoginModule required\nuseTicketCache=true;\n" + + "};\n"); + jaas.append(createJAASEntry("Client", "dgi", userKeytabFile)); + jaas.append(createJAASEntry("Server", "HTTP", httpKeytabFile)); + + File jaasFile = new File(kdcWorkDir, "jaas.txt"); + FileUtils.write(jaasFile, jaas.toString()); + bindJVMtoJAASFile(jaasFile); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterIT.java b/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterIT.java new file mode 100644 index 0000000..ca53096 --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterIT.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.web.filters; + +import org.apache.atlas.RequestContext; +import org.apache.atlas.web.security.BaseSecurityTest; +import org.apache.atlas.web.service.EmbeddedServer; +import org.apache.commons.configuration.ConfigurationException; +import org.eclipse.jetty.server.Server; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Properties; + +import static org.testng.Assert.assertEquals; + +/** + * + */ +public class AtlasAuthenticationSimpleFilterIT extends BaseSecurityTest { + public static final String TESTUSER = "testuser"; + + class TestEmbeddedServer extends EmbeddedServer { + public TestEmbeddedServer(int port, String path) throws IOException { + super(port, path); + } + + Server getServer() { + return server; + } + } + + @Test(enabled = false) + public void testSimpleLogin() throws Exception { + String originalConf = System.getProperty("atlas.conf"); + System.setProperty("atlas.conf", System.getProperty("user.dir")); + generateSimpleLoginConfiguration(); + + TestEmbeddedServer server = new TestEmbeddedServer(23001, "webapp/target/apache-atlas"); + + try { + startEmbeddedServer(server.getServer()); + + URL url = new URL("http://localhost:23001"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + + try { + assertEquals(connection.getResponseCode(), 403); + } catch (Exception e) { + e.printStackTrace(); + } + + url = new URL("http://localhost:23001/?user.name=testuser"); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + + assertEquals(connection.getResponseCode(), 200); + assertEquals(RequestContext.get().getUser(), TESTUSER); + } finally { + server.getServer().stop(); + if (originalConf != null) { + System.setProperty("atlas.conf", originalConf); + } else { + System.clearProperty("atlas.conf"); + } + } + + + } + + protected void generateSimpleLoginConfiguration() throws IOException, ConfigurationException { + Properties config = new Properties(); + config.setProperty("atlas.http.authentication.enabled", "true"); + config.setProperty("atlas.http.authentication.type", "simple"); + + generateTestProperties(config); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationKerberosFilterIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationKerberosFilterIT.java b/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationKerberosFilterIT.java deleted file mode 100644 index a658497..0000000 --- a/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationKerberosFilterIT.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.atlas.web.filters; - -import org.apache.atlas.web.security.BaseSecurityTest; -import org.apache.atlas.web.service.EmbeddedServer; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.io.FileUtils; -import org.apache.hadoop.hdfs.web.URLConnectionFactory; -import org.eclipse.jetty.server.Server; -import org.testng.Assert; -import org.testng.annotations.Test; - -import javax.security.auth.Subject; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; -import javax.security.auth.login.LoginContext; -import javax.security.auth.login.LoginException; -import java.io.File; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.PrivilegedExceptionAction; -import java.util.Properties; - -/** - * - */ -public class MetadataAuthenticationKerberosFilterIT extends BaseSecurityTest { - public static final String TEST_USER_JAAS_SECTION = "TestUser"; - public static final String TESTUSER = "testuser"; - public static final String TESTPASS = "testpass"; - - private File userKeytabFile; - private File httpKeytabFile; - - class TestEmbeddedServer extends EmbeddedServer { - public TestEmbeddedServer(int port, String path) throws IOException { - super(port, path); - } - - Server getServer() { - return server; - } - } - - @Test(enabled = false) - public void testKerberosBasedLogin() throws Exception { - String originalConf = System.getProperty("atlas.conf"); - System.setProperty("atlas.conf", System.getProperty("user.dir")); - - setupKDCAndPrincipals(); - TestEmbeddedServer server = null; - - try { - // setup the atlas-application.properties file - generateKerberosTestProperties(); - - // need to create the web application programmatically in order to control the injection of the test - // application properties - server = new TestEmbeddedServer(23000, "webapp/target/apache-atlas"); - - startEmbeddedServer(server.getServer()); - - final URLConnectionFactory connectionFactory = URLConnectionFactory.DEFAULT_SYSTEM_CONNECTION_FACTORY; - // attempt to hit server and get rejected - URL url = new URL("http://localhost:23000/"); - HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, false); - connection.setRequestMethod("GET"); - connection.connect(); - - Assert.assertEquals(connection.getResponseCode(), 401); - - // need to populate the ticket cache with a local user, so logging in... - Subject subject = loginTestUser(); - - Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { - @Override - public Object run() throws Exception { - // attempt to hit server and get rejected - URL url = new URL("http://localhost:23000/"); - HttpURLConnection connection = (HttpURLConnection) connectionFactory.openConnection(url, true); - connection.setRequestMethod("GET"); - connection.connect(); - - Assert.assertEquals(connection.getResponseCode(), 200); - - return null; - } - }); - } finally { - server.getServer().stop(); - kdc.stop(); - - if (originalConf != null) { - System.setProperty("atlas.conf", originalConf); - } else { - System.clearProperty("atlas.conf"); - } - - } - - - } - - protected Subject loginTestUser() throws LoginException, IOException { - LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() { - - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { - for (int i = 0; i < callbacks.length; i++) { - if (callbacks[i] instanceof PasswordCallback) { - PasswordCallback passwordCallback = (PasswordCallback) callbacks[i]; - passwordCallback.setPassword(TESTPASS.toCharArray()); - } - if (callbacks[i] instanceof NameCallback) { - NameCallback nameCallback = (NameCallback) callbacks[i]; - nameCallback.setName(TESTUSER); - } - } - } - }); - // attempt authentication - lc.login(); - return lc.getSubject(); - } - - protected void generateKerberosTestProperties() throws IOException, ConfigurationException { - Properties props = new Properties(); - props.setProperty("atlas.http.authentication.enabled", "true"); - props.setProperty("atlas.http.authentication.type", "kerberos"); - props.setProperty("atlas.http.authentication.kerberos.principal", "HTTP/localhost@" + kdc.getRealm()); - props.setProperty("atlas.http.authentication.kerberos.keytab", httpKeytabFile.getAbsolutePath()); - props.setProperty("atlas.http.authentication.kerberos.name.rules", - "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT"); - - generateTestProperties(props); - } - - public void setupKDCAndPrincipals() throws Exception { - // set up the KDC - File kdcWorkDir = startKDC(); - - userKeytabFile = createKeytab(kdc, kdcWorkDir, "dgi", "dgi.keytab"); - httpKeytabFile = createKeytab(kdc, kdcWorkDir, "HTTP", "spnego.service.keytab"); - - // create a test user principal - kdc.createPrincipal(TESTUSER, TESTPASS); - - StringBuilder jaas = new StringBuilder(1024); - jaas.append("TestUser {\n" + - " com.sun.security.auth.module.Krb5LoginModule required\nuseTicketCache=true;\n" + - "};\n"); - jaas.append(createJAASEntry("Client", "dgi", userKeytabFile)); - jaas.append(createJAASEntry("Server", "HTTP", httpKeytabFile)); - - File jaasFile = new File(kdcWorkDir, "jaas.txt"); - FileUtils.write(jaasFile, jaas.toString()); - bindJVMtoJAASFile(jaasFile); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationSimpleFilterIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationSimpleFilterIT.java b/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationSimpleFilterIT.java deleted file mode 100644 index 77659ee..0000000 --- a/webapp/src/test/java/org/apache/atlas/web/filters/MetadataAuthenticationSimpleFilterIT.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.atlas.web.filters; - -import org.apache.atlas.web.security.BaseSecurityTest; -import org.apache.atlas.web.service.EmbeddedServer; -import org.apache.commons.configuration.ConfigurationException; -import org.eclipse.jetty.server.Server; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Properties; - -/** - * - */ -public class MetadataAuthenticationSimpleFilterIT extends BaseSecurityTest { - - class TestEmbeddedServer extends EmbeddedServer { - public TestEmbeddedServer(int port, String path) throws IOException { - super(port, path); - } - - Server getServer() { - return server; - } - } - - @Test(enabled = false) - public void testSimpleLogin() throws Exception { - String originalConf = System.getProperty("atlas.conf"); - System.setProperty("atlas.conf", System.getProperty("user.dir")); - generateSimpleLoginConfiguration(); - - TestEmbeddedServer server = new TestEmbeddedServer(23001, "webapp/target/apache-atlas"); - - try { - startEmbeddedServer(server.getServer()); - - URL url = new URL("http://localhost:23001"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - - try { - Assert.assertEquals(connection.getResponseCode(), 403); - } catch (Exception e) { - e.printStackTrace(); - } - - url = new URL("http://localhost:23001/?user.name=testuser"); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - - Assert.assertEquals(connection.getResponseCode(), 200); - } finally { - server.getServer().stop(); - if (originalConf != null) { - System.setProperty("atlas.conf", originalConf); - } else { - System.clearProperty("atlas.conf"); - } - } - - - } - - protected void generateSimpleLoginConfiguration() throws IOException, ConfigurationException { - Properties config = new Properties(); - config.setProperty("atlas.http.authentication.enabled", "true"); - config.setProperty("atlas.http.authentication.type", "simple"); - - generateTestProperties(config); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java b/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java index a4f8cce..08bb125 100644 --- a/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java +++ b/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java @@ -17,6 +17,7 @@ package org.apache.atlas.web.listeners; import com.google.inject.Key; +import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.TypeLiteral; import com.thinkaurelius.titan.core.TitanGraph; @@ -60,6 +61,11 @@ public class TestGuiceServletConfig extends GuiceServletConfig { } @Override + protected Module getRepositoryModule() { + return new TestModule(); + } + + @Override protected void startServices() { try { Configuration conf = ApplicationProperties.get(); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java b/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java new file mode 100644 index 0000000..9cb76d3 --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.web.listeners; + +import com.google.inject.Binder; +import org.apache.atlas.RepositoryMetadataModule; +import org.apache.atlas.repository.audit.EntityAuditRepository; +import org.apache.atlas.repository.audit.InMemoryEntityAuditRepository; + +public class TestModule extends RepositoryMetadataModule { + @Override + protected void bindAuditRepository(Binder binder) { + //Map EntityAuditRepository interface to hbase based implementation + binder.bind(EntityAuditRepository.class).to(InMemoryEntityAuditRepository.class).asEagerSingleton(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/security/BaseSSLAndKerberosTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/BaseSSLAndKerberosTest.java b/webapp/src/test/java/org/apache/atlas/web/security/BaseSSLAndKerberosTest.java index 08f4b68..d497230 100644 --- a/webapp/src/test/java/org/apache/atlas/web/security/BaseSSLAndKerberosTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/security/BaseSSLAndKerberosTest.java @@ -24,6 +24,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.webapp.WebAppContext; import java.io.File; import java.io.IOException; @@ -51,8 +52,11 @@ public class BaseSSLAndKerberosTest extends BaseSecurityTest { } @Override - public org.apache.commons.configuration.Configuration getConfiguration() { - return super.getConfiguration(); + protected WebAppContext getWebAppContext(String path) { + WebAppContext application = new WebAppContext(path, "/"); + application.setDescriptor(System.getProperty("projectBaseDir") + "/webapp/src/test/webapp/WEB-INF/web.xml"); + application.setClassLoader(Thread.currentThread().getContextClassLoader()); + return application; } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java b/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java index e010537..270a20d 100644 --- a/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/security/BaseSecurityTest.java @@ -32,11 +32,15 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.net.URL; import java.nio.file.Files; import java.util.Locale; import java.util.Properties; -import static org.apache.atlas.security.SecurityProperties.*; +import static org.apache.atlas.security.SecurityProperties.CERT_STORES_CREDENTIAL_PROVIDER_PATH; +import static org.apache.atlas.security.SecurityProperties.KEYSTORE_FILE_KEY; +import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED; +import static org.apache.atlas.security.SecurityProperties.TRUSTSTORE_FILE_KEY; /** * @@ -135,4 +139,23 @@ public class BaseSecurityTest { return configuration; } + public static String writeConfiguration(final PropertiesConfiguration configuration) throws Exception { + String persistDir = TestUtils.getTempDirectory(); + TestUtils.writeConfiguration(configuration, persistDir + File.separator + + ApplicationProperties.APPLICATION_PROPERTIES); + + String confLocation = System.getProperty("atlas.conf"); + URL url; + if (confLocation == null) { + url = BaseSecurityTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES); + } else { + url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL(); + } + PropertiesConfiguration configuredProperties = new PropertiesConfiguration(); + configuredProperties.load(url); + TestUtils.writeConfiguration(configuredProperties, persistDir + File.separator + + ApplicationProperties.APPLICATION_PROPERTIES); + ApplicationProperties.forceReload(); + return persistDir; + } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java b/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java index 8eb8094..07802fa 100755 --- a/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/security/NegativeSSLAndKerberosTest.java @@ -22,6 +22,7 @@ import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasException; import org.apache.atlas.web.TestUtils; +import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.alias.JavaKeyStoreProvider; @@ -95,7 +96,7 @@ public class NegativeSSLAndKerberosTest extends BaseSSLAndKerberosTest { System.setProperty("atlas.conf", persistDir); secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { @Override - public PropertiesConfiguration getConfiguration() { + public Configuration getConfiguration() { return configuration; } }; http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java b/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java index aad3f3b..480861e 100755 --- a/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/security/SSLTest.java @@ -18,10 +18,8 @@ package org.apache.atlas.web.security; -import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasException; -import org.apache.atlas.web.TestUtils; import org.apache.atlas.web.service.SecureEmbeddedServer; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.hadoop.conf.Configuration; @@ -30,6 +28,7 @@ import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.JavaKeyStoreProvider; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.webapp.WebAppContext; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -47,6 +46,7 @@ public class SSLTest extends BaseSSLAndKerberosTest { private Path jksPath; private String providerUrl; private TestSecureEmbeddedServer secureEmbeddedServer; + private String originalConf; class TestSecureEmbeddedServer extends SecureEmbeddedServer { @@ -59,8 +59,11 @@ public class SSLTest extends BaseSSLAndKerberosTest { } @Override - public org.apache.commons.configuration.Configuration getConfiguration() { - return super.getConfiguration(); + protected WebAppContext getWebAppContext(String path) { + WebAppContext application = new WebAppContext(path, "/"); + application.setDescriptor(System.getProperty("projectBaseDir") + "/webapp/src/test/webapp/WEB-INF/web.xml"); + application.setClassLoader(Thread.currentThread().getContextClassLoader()); + return application; } } @@ -69,13 +72,9 @@ public class SSLTest extends BaseSSLAndKerberosTest { jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks"); providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + jksPath.toUri(); - String persistDir = TestUtils.getTempDirectory(); - setupCredentials(); - final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl); - TestUtils.writeConfiguration(configuration, persistDir + File.separator + - ApplicationProperties.APPLICATION_PROPERTIES); + String persistDir = writeConfiguration(configuration); dgiCLient = new AtlasClient(DGI_URL) { @Override @@ -84,6 +83,8 @@ public class SSLTest extends BaseSSLAndKerberosTest { } }; + originalConf = System.getProperty("atlas.conf"); + System.setProperty("atlas.conf", persistDir); secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) { @Override public PropertiesConfiguration getConfiguration() { @@ -98,6 +99,10 @@ public class SSLTest extends BaseSSLAndKerberosTest { if (secureEmbeddedServer != null) { secureEmbeddedServer.getServer().stop(); } + + if (originalConf != null) { + System.setProperty("atlas.conf", originalConf); + } } protected void setupCredentials() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTest.java b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTest.java index 6b0a005..c356be6 100644 --- a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTest.java @@ -18,8 +18,11 @@ package org.apache.atlas.web.service; +import org.apache.atlas.ApplicationProperties; import org.apache.atlas.web.TestUtils; +import org.apache.atlas.web.security.BaseSecurityTest; import org.apache.commons.configuration.PropertiesConfiguration; +import org.eclipse.jetty.webapp.WebAppContext; import org.testng.Assert; import org.testng.annotations.Test; @@ -34,10 +37,16 @@ public class SecureEmbeddedServerTest extends SecureEmbeddedServerTestBase { // setup the configuration final PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); + configuration.setProperty("atlas.services.enabled", false); configuration.setProperty("atlas.notification.embedded", "false"); // setup the credential provider setupCredentials(); + String persistDir = BaseSecurityTest.writeConfiguration(configuration); + String originalConf = System.getProperty("atlas.conf"); + System.setProperty("atlas.conf", persistDir); + + ApplicationProperties.forceReload(); SecureEmbeddedServer secureEmbeddedServer = null; try { secureEmbeddedServer = new SecureEmbeddedServer(21443, TestUtils.getWarPath()) { @@ -45,6 +54,16 @@ public class SecureEmbeddedServerTest extends SecureEmbeddedServerTestBase { protected PropertiesConfiguration getConfiguration() { return configuration; } + + @Override + protected WebAppContext getWebAppContext(String path) { + WebAppContext application = new WebAppContext(path, "/"); + application.setDescriptor( + System.getProperty("projectBaseDir") + "/webapp/src/test/webapp/WEB-INF/web.xml"); + application.setClassLoader(Thread.currentThread().getContextClassLoader()); + return application; + } + }; secureEmbeddedServer.server.start(); @@ -59,7 +78,12 @@ public class SecureEmbeddedServerTest extends SecureEmbeddedServerTestBase { Assert.fail("War deploy failed", e); } finally { secureEmbeddedServer.server.stop(); + + if (originalConf == null) { + System.clearProperty("atlas.conf"); + } else { + System.setProperty("atlas.conf", originalConf); + } } } - } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/bca454e1/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java index 6a56c5d..b42fc0f 100755 --- a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java +++ b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java @@ -103,8 +103,11 @@ public class SecureEmbeddedServerTestBase { @Test public void testNoConfiguredCredentialProvider() throws Exception { - + String originalConf = null; try { + originalConf = System.getProperty("atlas.conf"); + System.clearProperty("atlas.conf"); + ApplicationProperties.forceReload(); secureEmbeddedServer = new SecureEmbeddedServer(securePort, TestUtils.getWarPath()); secureEmbeddedServer.server.start(); @@ -113,7 +116,15 @@ public class SecureEmbeddedServerTestBase { Assert.assertEquals(e.getMessage(), "No credential provider path configured for storage of certificate store passwords"); } finally { - secureEmbeddedServer.server.stop(); + if (secureEmbeddedServer != null) { + secureEmbeddedServer.server.stop(); + } + + if (originalConf == null) { + System.clearProperty("atlas.conf"); + } else { + System.setProperty("atlas.conf", originalConf); + } } }
