Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AC454200CE3 for ; Sun, 13 Aug 2017 09:09:05 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AA8E0164728; Sun, 13 Aug 2017 07:09:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C8C8C164725 for ; Sun, 13 Aug 2017 09:09:04 +0200 (CEST) Received: (qmail 11203 invoked by uid 500); 13 Aug 2017 07:09:04 -0000 Mailing-List: contact commits-help@atlas.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@atlas.apache.org Delivered-To: mailing list commits@atlas.apache.org Received: (qmail 11194 invoked by uid 99); 13 Aug 2017 07:09:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Aug 2017 07:09:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CFF9AE0262; Sun, 13 Aug 2017 07:09:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: madhan@apache.org To: commits@atlas.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: atlas git commit: ATLAS-2038 : Integration Tests for AtlasAuthentication and Authorization Filter Date: Sun, 13 Aug 2017 07:09:03 +0000 (UTC) archived-at: Sun, 13 Aug 2017 07:09:05 -0000 Repository: atlas Updated Branches: refs/heads/0.8-incubating 0cb3d35c4 -> fe69c849e ATLAS-2038 : Integration Tests for AtlasAuthentication and Authorization Filter Signed-off-by: Madhan Neethiraj (cherry picked from commit cd49be50a2fc351f50165f6bd0573db561612699) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/fe69c849 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/fe69c849 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/fe69c849 Branch: refs/heads/0.8-incubating Commit: fe69c849e42a5814657bf51e8d5e4e1d4381a266 Parents: 0cb3d35 Author: nixonrodrigues Authored: Fri Aug 11 21:50:54 2017 +0530 Committer: Madhan Neethiraj Committed: Sun Aug 13 00:08:55 2017 -0700 ---------------------------------------------------------------------- .../AtlasAuthenticationSimpleFilterIT.java | 97 ++++++++++++++++++++ .../AtlasAuthenticationSimpleFilterTest.java | 89 ------------------ 2 files changed, 97 insertions(+), 89 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/fe69c849/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..25414fd --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterIT.java @@ -0,0 +1,97 @@ +/* + * 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.testng.Assert; +import org.testng.annotations.Test; +import sun.misc.BASE64Encoder; +import javax.ws.rs.core.Response; +import java.net.HttpURLConnection; +import java.net.URL; + +import static org.testng.Assert.assertEquals; + +/** + * + */ +public class AtlasAuthenticationSimpleFilterIT extends BaseSecurityTest { + private BASE64Encoder enc = new sun.misc.BASE64Encoder(); + + + @Test(enabled = true) + public void testSimpleLoginForValidUser() throws Exception { + URL url = new URL("http://localhost:31000/api/atlas/admin/session"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + String userpassword = "admin:admin"; // right password + String encodedAuthorization = enc.encode(userpassword.getBytes()); + connection.setRequestProperty("Authorization", "Basic " + + encodedAuthorization); + connection.connect(); + + assertEquals(connection.getResponseCode(), Response.Status.OK.getStatusCode()); + } + + + @Test(enabled = true) + public void testAccessforUnauthenticatedResource() throws Exception { + + URL url = new URL("http://localhost:31000/api/atlas/admin/status"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + assertEquals(connection.getResponseCode(), Response.Status.OK.getStatusCode()); + + } + + + @Test(enabled = true) + public void testSimpleLoginAndAuthorizationWithValidCrendentialsAndInvalidAccessToResource() + throws Exception { + try { + URL url = new URL("http://localhost:31000/api/atlas/v1/taxonomies"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + String userpassword = "rangertagsync:rangertagsync"; //right password with no policy for taxonomies api + String encodedAuthorization = enc.encode(userpassword.getBytes()); + connection.setRequestProperty("Authorization", "Basic " + + encodedAuthorization); + connection.connect(); + assertEquals(connection.getResponseCode(), 403); + + } catch (Exception e) { + Assert.fail("Failed with exception " + e.getMessage()); + } + } + + + @Test(enabled = true) + public void testSimpleLoginWithInvalidCrendentials() throws Exception { + + URL url = new URL("http://localhost:31000/api/atlas/admin/session"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + String userpassword = "admin:admin1"; //wrong password + String encodedAuthorization = enc.encode(userpassword.getBytes()); + connection.setRequestProperty("Authorization", "Basic " + + encodedAuthorization); + connection.connect(); + assertEquals(connection.getResponseCode(), 401); + } + +} http://git-wip-us.apache.org/repos/asf/atlas/blob/fe69c849/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterTest.java b/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterTest.java deleted file mode 100644 index 389eefe..0000000 --- a/webapp/src/test/java/org/apache/atlas/web/filters/AtlasAuthenticationSimpleFilterTest.java +++ /dev/null @@ -1,89 +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.RequestContext; -import org.apache.atlas.web.security.BaseSecurityTest; -import org.apache.atlas.web.service.EmbeddedServer; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.eclipse.jetty.server.Server; -import org.testng.annotations.Test; - -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; - -import static org.testng.Assert.assertEquals; - -/** - * - */ -public class AtlasAuthenticationSimpleFilterTest 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(); - assertEquals(connection.getResponseCode(), Response.Status.BAD_REQUEST.getStatusCode()); - - url = new URL("http://localhost:23001/?user.name=testuser"); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - - assertEquals(connection.getResponseCode(), Response.Status.OK.getStatusCode()); - assertEquals(RequestContext.get().getUser(), TESTUSER); - } finally { - server.getServer().stop(); - if (originalConf != null) { - System.setProperty("atlas.conf", originalConf); - } else { - System.clearProperty("atlas.conf"); - } - } - } - - protected String generateSimpleLoginConfiguration() throws Exception { - PropertiesConfiguration config = new PropertiesConfiguration(); - config.setProperty("atlas.http.authentication.enabled", "true"); - config.setProperty("atlas.http.authentication.type", "simple"); - return writeConfiguration(config); - } -}