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 6A0A7200C10 for ; Fri, 3 Feb 2017 10:00:27 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 688AB160B68; Fri, 3 Feb 2017 09:00:27 +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 1AED7160B48 for ; Fri, 3 Feb 2017 10:00:24 +0100 (CET) Received: (qmail 16068 invoked by uid 500); 3 Feb 2017 09:00:24 -0000 Mailing-List: contact commits-help@hawq.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hawq.incubator.apache.org Delivered-To: mailing list commits@hawq.incubator.apache.org Received: (qmail 16059 invoked by uid 99); 3 Feb 2017 09:00:24 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Feb 2017 09:00:24 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B2DC018231E for ; Fri, 3 Feb 2017 09:00:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id b7hw78C45Tv8 for ; Fri, 3 Feb 2017 09:00:10 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 0C98B60D2E for ; Fri, 3 Feb 2017 09:00:04 +0000 (UTC) Received: (qmail 12238 invoked by uid 99); 3 Feb 2017 09:00:04 -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; Fri, 03 Feb 2017 09:00:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EB28DDF9AB; Fri, 3 Feb 2017 09:00:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: espino@apache.org To: commits@hawq.incubator.apache.org Date: Fri, 03 Feb 2017 09:00:33 -0000 Message-Id: <95ad9cf4556b426fba27930bb6bebaf5@git.apache.org> In-Reply-To: <40325a477040484aa0872e11ff2aa29a@git.apache.org> References: <40325a477040484aa0872e11ff2aa29a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [31/50] [abbrv] incubator-hawq git commit: HAWQ-1203. Ranger Plugin Service Implementation. (with contributions by Lav Jain and Leslie Chang) (close #1092) archived-at: Fri, 03 Feb 2017 09:00:27 -0000 http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSchemasTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSchemasTest.java b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSchemasTest.java new file mode 100644 index 0000000..94372aa --- /dev/null +++ b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSchemasTest.java @@ -0,0 +1,126 @@ +/* + * 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 schema governing permissions and limitations + * under the License. + */ + +package org.apache.hawq.ranger.integration.admin; + +import com.google.common.collect.Sets; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; +import java.util.Set; +import java.util.Map; +import java.util.HashMap; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ListSchemasTest extends LookupTestBase { + + private static final Set DEFAULT_SCHEMAS = Sets.newHashSet("public"); + private static final Set EAST_SCHEMAS = Sets.newHashSet("common", "japan", "public"); + private static final Set WEST_SCHEMAS = Sets.newHashSet("common", "france", "jamaica", "public"); + private static final Set ALL_SCHEMAS = Sets.newHashSet("common", "japan", "france", "jamaica", "public"); + + private Map> resources; + + @Before + public void setUp() { + resources = new HashMap<>(); + } + + @Test + public void testListSchema_NoResources() throws Exception { + resources.put("database", Arrays.asList("noschema_db")); + List result = service.lookupResource(getContext("schema", "*", resources)); + assertEquals(DEFAULT_SCHEMAS.size(), result.size()); + assertEquals(DEFAULT_SCHEMAS, Sets.newHashSet(result)); + } + + @Test + public void testListSchemas_SingleDb_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east")); + List result = service.lookupResource(getContext("schema", "*", resources)); + assertEquals(EAST_SCHEMAS.size(), result.size()); + assertEquals(EAST_SCHEMAS, Sets.newHashSet(result)); + } + + @Test + public void testListSchemas_TwoDb_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + List result = service.lookupResource(getContext("schema", "*", resources)); + assertEquals(ALL_SCHEMAS.size(), result.size()); + assertEquals(ALL_SCHEMAS, Sets.newHashSet(result)); + } + + @Test + public void testListSchemas_AllDb_AllFilter() throws Exception { + resources.put("database", Arrays.asList("*")); + List result = service.lookupResource(getContext("schema", "*", resources)); + assertEquals(ALL_SCHEMAS.size(), result.size()); + assertEquals(ALL_SCHEMAS, Sets.newHashSet(result)); + } + + @Test + public void testListSchemas_SingleDb_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east")); + List result = service.lookupResource(getContext("schema", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSchemas_TwoDb_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + List result = service.lookupResource(getContext("schema", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSchemas_AllDb_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("*")); + List result = service.lookupResource(getContext("schema", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSchemas_SingleDb_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east")); + List result = service.lookupResource(getContext("schema", "ja", resources)); + assertEquals(1, result.size()); + assertEquals("japan", result.get(0)); + } + + @Test + public void testListSchemas_TwoDb_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + List result = service.lookupResource(getContext("schema", "ja", resources)); + assertEquals(2, result.size()); + assertEquals(Sets.newHashSet("japan", "jamaica"), Sets.newHashSet(result)); + } + + @Test + public void testListSchemas_AllDb_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("*")); + List result = service.lookupResource(getContext("schema", "ja", resources)); + assertEquals(2, result.size()); + assertEquals(Sets.newHashSet("japan", "jamaica"), Sets.newHashSet(result)); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSequencesTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSequencesTest.java b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSequencesTest.java new file mode 100644 index 0000000..0c601c2 --- /dev/null +++ b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListSequencesTest.java @@ -0,0 +1,250 @@ +/* + * 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 schema governing permissions and limitations + * under the License. + */ + +package org.apache.hawq.ranger.integration.admin; + +import com.google.common.collect.Sets; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ListSequencesTest extends LookupTestBase { + + private Map> resources; + + @Before + public void setUp() { + resources = new HashMap<>(); + } + + @Test + public void testListSequences_NoSchemaDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("noschema_db")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_SingleDb_SingleSchema_AllFilter_NoSequences() throws Exception { + resources.put("database", Arrays.asList("west")); + resources.put("schema", Arrays.asList("jamaica")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_SingleDb_SingleSchema_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water", "sake"))); + } + + @Test + public void testListSequences_SingleDb_TwoSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("common", "japan")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water", "sprite", "sake"))); + } + + @Test + public void testListSequences_SingleDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water", "sprite", "sake"))); + } + + @Test + public void testListSequences_TwoDb_CommonSchema_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("common")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water", "sprite"))); + } + + @Test + public void testListSequences_TwoDb_SingleSchema_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water", "sake"))); + } + + @Test + public void testListSequences_TwoDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertEquals(4, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water", "sprite", "sake", "scotch"))); + } + + @Test + public void testListSequences_AllDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("*")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "*", resources)); + assertEquals(4, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water", "sprite", "sake", "scotch"))); + } + + @Test + public void testListSequences_SingleDb_SingleSchema_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("sequence", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_SingleDb_TwoSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("common", "japan")); + List result = service.lookupResource(getContext("sequence", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_SingleDb_AllSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_TwoDbs_CommonSchema_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("common")); + List result = service.lookupResource(getContext("sequence", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_TwoDbs_SingleSchema_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("sequence", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_TwoDbs_AllSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_AllDbs_AllSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("*")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListSequences_SingleDb_SingleSchema_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("sequence", "s", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sake"))); + } + + @Test + public void testListSequences_SingleDb_TwoSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("common", "japan")); + List result = service.lookupResource(getContext("sequence", "s", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sprite", "sake"))); + } + + @Test + public void testListSequences_SingleDb_AllSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "s", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sprite", "sake"))); + } + + @Test + public void testListSequences_SingleDb_AllSchemas_FilteredPresent2() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "w", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water"))); + } + + @Test + public void testListSequences_TwoDbs_CommonSchema_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("common")); + List result = service.lookupResource(getContext("sequence", "w", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("water"))); + } + + @Test + public void testListSequences_TwoDbs_SingleSchema_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("sequence", "s", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sake"))); + } + + @Test + public void testListSequences_TwoDbs_AllSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "s", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sprite", "sake", "scotch"))); + } + + @Test + public void testListSequences_AllDbs_AllSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("*")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("sequence", "s", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sprite", "sake", "scotch"))); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablesTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablesTest.java b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablesTest.java new file mode 100644 index 0000000..1360cac --- /dev/null +++ b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablesTest.java @@ -0,0 +1,250 @@ +/* + * 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 schema governing permissions and limitations + * under the License. + */ + +package org.apache.hawq.ranger.integration.admin; + +import com.google.common.collect.Sets; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ListTablesTest extends LookupTestBase { + + private Map> resources; + + @Before + public void setUp() { + resources = new HashMap<>(); + } + + @Test + public void testListTables_NoSchemaDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("noschema_db")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_SingleDb_SingleSchema_AllFilter_NoTables() throws Exception { + resources.put("database", Arrays.asList("west")); + resources.put("schema", Arrays.asList("jamaica")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_SingleDb_SingleSchema_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice", "sushi"))); + } + + @Test + public void testListTables_SingleDb_TwoSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("common", "japan")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice", "soup", "sushi"))); + } + + @Test + public void testListTables_SingleDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice", "soup", "sushi"))); + } + + @Test + public void testListTables_TwoDb_CommonSchema_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("common")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice", "soup"))); + } + + @Test + public void testListTables_TwoDb_SingleSchema_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice", "sushi"))); + } + + @Test + public void testListTables_TwoDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertEquals(4, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice", "soup", "sushi", "stew"))); + } + + @Test + public void testListTables_AllDb_AllSchemas_AllFilter() throws Exception { + resources.put("database", Arrays.asList("*")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "*", resources)); + assertEquals(4, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice", "soup", "sushi", "stew"))); + } + + @Test + public void testListTables_SingleDb_SingleSchema_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("table", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_SingleDb_TwoSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("common", "japan")); + List result = service.lookupResource(getContext("table", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_SingleDb_AllSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_TwoDbs_CommonSchema_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("common")); + List result = service.lookupResource(getContext("table", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_TwoDbs_SingleSchema_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("table", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_TwoDbs_AllSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_AllDbs_AllSchemas_FilteredAbsent() throws Exception { + resources.put("database", Arrays.asList("*")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "z", resources)); + assertTrue(result.isEmpty()); + } + + @Test + public void testListTables_SingleDb_SingleSchema_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("table", "s", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sushi"))); + } + + @Test + public void testListTables_SingleDb_TwoSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("common", "japan")); + List result = service.lookupResource(getContext("table", "s", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("soup", "sushi"))); + } + + @Test + public void testListTables_SingleDb_AllSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "s", resources)); + assertEquals(2, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("soup", "sushi"))); + } + + @Test + public void testListTables_SingleDb_AllSchemas_FilteredPresent2() throws Exception { + resources.put("database", Arrays.asList("east")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "r", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice"))); + } + + @Test + public void testListTables_TwoDbs_CommonSchema_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("common")); + List result = service.lookupResource(getContext("table", "r", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("rice"))); + } + + @Test + public void testListTables_TwoDbs_SingleSchema_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("japan")); + List result = service.lookupResource(getContext("table", "s", resources)); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("sushi"))); + } + + @Test + public void testListTables_TwoDbs_AllSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("east", "west")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "s", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("soup", "sushi", "stew"))); + } + + @Test + public void testListTables_AllDbs_AllSchemas_FilteredPresent() throws Exception { + resources.put("database", Arrays.asList("*")); + resources.put("schema", Arrays.asList("*")); + List result = service.lookupResource(getContext("table", "s", resources)); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("soup", "sushi", "stew"))); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablespacesTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablespacesTest.java b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablespacesTest.java new file mode 100644 index 0000000..65048db --- /dev/null +++ b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/ListTablespacesTest.java @@ -0,0 +1,55 @@ +/* + * 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.hawq.ranger.integration.admin; + +import com.google.common.collect.Sets; +import org.junit.Test; + +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ListTablespacesTest extends LookupTestBase { + + private static final Set TABLESPACES = Sets.newHashSet("pg_default", "pg_global", "dfs_default"); + + @Test + public void testListTablespace_All() throws Exception { + List result = service.lookupResource(getContext("tablespace", "*")); + assertEquals(3, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet(TABLESPACES))); + } + + @Test + public void testListTablespace_FilteredPresent() throws Exception { + List result = service.lookupResource(getContext("tablespace", "pg_d")); + assertEquals(1, result.size()); + assertTrue(Sets.newHashSet(result).equals(Sets.newHashSet("pg_default"))); + } + + @Test + public void testListTablespace_FilteredAbsent() throws Exception { + List result = service.lookupResource(getContext("tablespace", "z")); + assertTrue(result.isEmpty()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/LookupTestBase.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/LookupTestBase.java b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/LookupTestBase.java new file mode 100644 index 0000000..25265f3 --- /dev/null +++ b/ranger-plugin/integration/admin/src/test/java/org/apache/hawq/ranger/integration/admin/LookupTestBase.java @@ -0,0 +1,65 @@ +/* + * 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.hawq.ranger.integration.admin; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hawq.ranger.service.RangerServiceHawq; +import org.apache.ranger.plugin.service.ResourceLookupContext; +import org.junit.Before; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class LookupTestBase { + + protected static final Log LOG = LogFactory.getLog(LookupTestBase.class); + protected RangerServiceHawq service; + + @Before + public void setup() { + Map configs = new HashMap<>(); + configs = new HashMap<>(); + configs.put("username", "gpadmin"); + configs.put("password", "dQSF8ViAE4/I38xmFwJfCg=="); + configs.put("hostname", "localhost"); + configs.put("port", "5432"); + configs.put("jdbc.driverClassName", "org.postgresql.Driver"); + + service = new RangerServiceHawq(); + service.setServiceName("hawq"); + service.setServiceType("hawq"); + service.setConfigs(configs); + } + + protected ResourceLookupContext getContext(String resourceName, String userInput) { + ResourceLookupContext context = new ResourceLookupContext(); + context.setResourceName(resourceName); + context.setUserInput(userInput); + return context; + } + + protected ResourceLookupContext getContext(String resourceName, String userInput, Map> resources) { + ResourceLookupContext context = getContext(resourceName, userInput); + context.setResources(resources); + return context; + } +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/admin/src/test/resources/admin-tests-ddl.sql ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/admin/src/test/resources/admin-tests-ddl.sql b/ranger-plugin/integration/admin/src/test/resources/admin-tests-ddl.sql new file mode 100644 index 0000000..d9e7fcc --- /dev/null +++ b/ranger-plugin/integration/admin/src/test/resources/admin-tests-ddl.sql @@ -0,0 +1,61 @@ +-- 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. + +-- EAST Database and its objects +DROP DATABASE IF EXISTS east; +CREATE DATABASE east; +\c east; +CREATE SCHEMA common; +CREATE TABLE common.rice (id integer); +CREATE TABLE common.soup (id integer); +CREATE SEQUENCE common.water; +CREATE SEQUENCE common.sprite; +CREATE FUNCTION common.eat(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE FUNCTION common.sleep(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE SCHEMA japan; +CREATE TABLE japan.rice (id integer); +CREATE TABLE japan.sushi (id integer); +CREATE SEQUENCE japan.water; +CREATE SEQUENCE japan.sake; +CREATE FUNCTION japan.eat(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE FUNCTION japan.stand(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE LANGUAGE langdbeast HANDLER plpgsql_call_handler; + +-- WEST Database and its objects +DROP DATABASE IF EXISTS west; +CREATE DATABASE west; +\c west; +CREATE SCHEMA common; +CREATE TABLE common.rice (id integer); +CREATE TABLE common.soup (id integer); +CREATE SEQUENCE common.water; +CREATE SEQUENCE common.sprite; +CREATE FUNCTION common.eat(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE FUNCTION common.sleep(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE SCHEMA france; +CREATE TABLE france.rice (id integer); +CREATE TABLE france.stew (id integer); +CREATE SEQUENCE france.water; +CREATE SEQUENCE france.scotch; +CREATE FUNCTION france.eat(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE FUNCTION france.smile(integer) RETURNS integer AS 'select $1;' LANGUAGE SQL; +CREATE LANGUAGE langdbwest HANDLER plpgsql_call_handler; +CREATE SCHEMA jamaica; + +-- Database without an explicit schema +DROP DATABASE IF EXISTS noschema_db; +CREATE DATABASE noschema_db; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/admin/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/admin/src/test/resources/log4j.properties b/ranger-plugin/integration/admin/src/test/resources/log4j.properties new file mode 100644 index 0000000..903f0b6 --- /dev/null +++ b/ranger-plugin/integration/admin/src/test/resources/log4j.properties @@ -0,0 +1,34 @@ +# 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. + +##-- To prevent junits from cluttering the build run by default all test runs send output to null appender +log4j.appender.devnull=org.apache.log4j.varia.NullAppender +#hawq.ranger.root.logger=FATAL,devnull + +##-- uncomment the following line during during development/debugging so see debug messages during test run to be emitted to console +hawq.ranger.root.logger=DEBUG,console +log4j.rootLogger=${hawq.ranger.root.logger} + +# Logging Threshold +log4j.threshold=ALL + +# +# console +# Add "console" to rootlogger above if you want to use this +# +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.err +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c{2}: %m%n http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/pom.xml ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/pom.xml b/ranger-plugin/integration/pom.xml new file mode 100644 index 0000000..b6aac80 --- /dev/null +++ b/ranger-plugin/integration/pom.xml @@ -0,0 +1,67 @@ + + + + + 4.0.0 + org.apache.hawq + ranger-plugin-integration + pom + HAWQ Ranger Plugin - Integration Tests + HAWQ Ranger Plugin - Integration Tests + + + org.apache.hawq + ranger-plugin + 2.1.0.0 + .. + + + + admin + service + + + + 1.9 + + + + + + src/test/resources + + **/* + + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + + + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/pom.xml ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/pom.xml b/ranger-plugin/integration/service/pom.xml new file mode 100644 index 0000000..34ade8d --- /dev/null +++ b/ranger-plugin/integration/service/pom.xml @@ -0,0 +1,68 @@ + + + + + 4.0.0 + org.apache.hawq + ranger-plugin-integration-service + jar + HAWQ Ranger Plugin - Integration Tests + HAWQ Ranger Plugin - Integration Tests + + + org.apache.hawq + ranger-plugin-integration + 2.1.0.0 + .. + + + + + log4j + log4j + + + postgresql + postgresql + + + org.apache.commons + commons-io + 1.3.2 + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.13 + + + + + junit + junit + + + + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/DatabaseTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/DatabaseTest.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/DatabaseTest.java new file mode 100644 index 0000000..451a289 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/DatabaseTest.java @@ -0,0 +1,67 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class DatabaseTest extends ServiceBaseTest { + + private static final List PRIVILEGES = Arrays.asList("connect", "temp"); + + public void beforeTest() + throws IOException { + createPolicy("test-database.json"); + resources.put("database", "sirotan"); + } + + @Test + public void testDatabases_UserMaria_SirotanDb_Allowed() + throws IOException { + assertTrue(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testDatabases_UserMaria_DoesNotExistDb_Denied() + throws IOException { + resources.put("database", "doesnotexist"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testDatabases_UserBob_SirotanDb_Denied() + throws IOException { + assertFalse(hasAccess("bob", resources, PRIVILEGES)); + } + + @Test + public void testDatabases_UserMaria_SirotanDb_Denied() + throws IOException { + deletePolicy(); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/FunctionTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/FunctionTest.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/FunctionTest.java new file mode 100644 index 0000000..1253c38 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/FunctionTest.java @@ -0,0 +1,91 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class FunctionTest extends ServiceBaseTest { + + private static final List PRIVILEGES = Arrays.asList("execute"); + + public void beforeTest() + throws IOException { + createPolicy("test-function.json"); + resources.put("database", "sirotan"); + resources.put("schema", "siroschema"); + resources.put("function", "atan"); + } + + @Test + public void testFunctions_UserMaria_SirotanDb_AtanFunction_Allowed() + throws IOException { + assertTrue(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testFunctions_UserMaria_OtherDb_AtanFunction_Denied() + throws IOException { + resources.put("database", "other"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testFunctions_UserMaria_SirotanDb_DoesNotExistFunction_Denied() + throws IOException { + resources.put("function", "doesnotexist"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testFunctions_UserBob_SirotanDb_AtanFunction_Denied() + throws IOException { + assertFalse(hasAccess("bob", resources, PRIVILEGES)); + } + + @Test + public void testFunctions_UserMaria_SirotanDb_AtanFunction_Denied() + throws IOException { + deletePolicy(); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testFunctions_UserMaria_DoesNotExistDb_AtanFunction_Denied() + throws IOException { + resources.put("database", "doesnotexist"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testFunctions_UserMaria_SirotanDb_AtanFunction_Policy2_Allowed() + throws IOException { + deletePolicy(); + createPolicy("test-function-2.json"); + assertTrue(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/LanguageTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/LanguageTest.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/LanguageTest.java new file mode 100644 index 0000000..6eedb08 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/LanguageTest.java @@ -0,0 +1,83 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LanguageTest extends ServiceBaseTest { + + private static final List PRIVILEGES = Arrays.asList("usage"); + + public void beforeTest() + throws IOException { + createPolicy("test-language.json"); + resources.put("database", "sirotan"); + resources.put("language", "sql"); + } + + @Test + public void testLanguages_UserMaria_SirotanDb_SqlLanguage_Allowed() + throws IOException { + assertTrue(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testLanguages_UserMaria_SirotanDb_DoesNotExistLanguage_Denied() + throws IOException { + resources.put("language", "doesnotexist"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testLanguages_UserBob_SirotanDb_SqlLanguage_Denied() + throws IOException { + assertFalse(hasAccess("bob", resources, PRIVILEGES)); + } + + @Test + public void testLanguages_UserMaria_SirotanDb_SqlLanguage_Denied() + throws IOException { + deletePolicy(); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testLanguages_UserMaria_DoesNotExistDb_SqlLanguage_Denied() + throws IOException { + resources.put("database", "doesnotexist"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testLanguages_UserMaria_SirotanDb_SqlLanguage_Policy2_Allowed() + throws IOException { + deletePolicy(); + createPolicy("test-language-2.json"); + assertTrue(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ProtocolTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ProtocolTest.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ProtocolTest.java new file mode 100644 index 0000000..f0e5c99 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ProtocolTest.java @@ -0,0 +1,67 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ProtocolTest extends ServiceBaseTest { + + private static final List PRIVILEGES = Arrays.asList("select", "insert"); + + public void beforeTest() + throws IOException { + createPolicy("test-protocol.json"); + resources.put("protocol", "pxf"); + } + + @Test + public void testProtocols_UserMaria_PxfProtocol_Allowed() + throws IOException { + assertTrue(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testProtocols_UserMaria_DoesNotExistProtocol_Denied() + throws IOException { + resources.put("protocol", "doesnotexist"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testProtocols_UserBob_PxfProtocol_Denied() + throws IOException { + assertFalse(hasAccess("bob", resources, PRIVILEGES)); + } + + @Test + public void testProtocols_UserMaria_PxfProtocol_Denied() + throws IOException { + deletePolicy(); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSRequest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSRequest.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSRequest.java new file mode 100644 index 0000000..7e7787a --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSRequest.java @@ -0,0 +1,60 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.codehaus.jackson.map.ObjectMapper; + +import java.io.IOException; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class RPSRequest { + + String user; + Map resources; + List privileges; + + public RPSRequest(String user, + Map resources, + List privileges) { + this.user = user; + this.resources = resources; + this.privileges = privileges; + } + + public String getJsonString() + throws IOException { + + Map request = new HashMap<>(); + request.put("requestId", 9); + request.put("user", user); + request.put("clientIp", "123.0.0.21"); + request.put("context", "CREATE DATABASE sirotan;"); + Map accessHash = new HashMap<>(); + accessHash.put("resource", resources); + accessHash.put("privileges", privileges); + request.put("access", Arrays.asList(accessHash)); + return new ObjectMapper().writeValueAsString(request); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSResponse.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSResponse.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSResponse.java new file mode 100644 index 0000000..2ed1046 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/RPSResponse.java @@ -0,0 +1,42 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.codehaus.jackson.annotate.JsonProperty; + +import java.util.List; +import java.util.Map; + +public class RPSResponse { + + @JsonProperty + public int requestId; + + @JsonProperty + public List> access; + + public List> getAccess() { + return access; + } + + public boolean hasAccess() { + return (boolean) access.get(0).get("allowed"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ServiceBaseTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ServiceBaseTest.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ServiceBaseTest.java new file mode 100644 index 0000000..8608584 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/ServiceBaseTest.java @@ -0,0 +1,116 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestName; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class ServiceBaseTest { + + protected final Log log = LogFactory.getLog(this.getClass()); + + @Rule + public final TestName testName = new TestName(); + protected final String policyName = getClass().getSimpleName(); + protected Map resources = new HashMap<>(); + + public static String RANGER_PLUGIN_SERVICE_HOST = "localhost"; + public static String RANGER_PLUGIN_SERVICE_PORT = "8432"; + public static String RANGER_PLUGIN_SERVICE_URL = + "http://" + RANGER_PLUGIN_SERVICE_HOST + ":" + RANGER_PLUGIN_SERVICE_PORT + "/rps"; + public static String RANGER_ADMIN_HOST = "localhost"; + public static String RANGER_ADMIN_PORT = "6080"; + public static String RANGER_URL = + "http://" + RANGER_ADMIN_HOST + ":" + RANGER_ADMIN_PORT + "/service/public/v2/api"; + public static String RANGER_TEST_USER = "maria_dev"; + public static int POLICY_REFRESH_INTERVAL = 6000; + + @Before + public void setUp() + throws IOException { + log.info("======================================================================================"); + log.info("Running test " + testName.getMethodName()); + log.info("======================================================================================"); + beforeTest(); + } + + @After + public void tearDown() + throws IOException { + deletePolicy(); + } + + protected void createPolicy(String jsonFile) + throws IOException { + + log.info("Creating policy " + policyName); + HttpPost httpPost = new HttpPost(RANGER_URL + "/policy"); + httpPost.setEntity(new StringEntity(Utils.getPayload(jsonFile))); + Utils.processHttpRequest(httpPost); + waitForPolicyRefresh(); + } + + protected void deletePolicy() + throws IOException { + + log.info("Deleting policy " + policyName); + String requestUrl = RANGER_URL + "/policy?servicename=hawq&policyname=" + policyName; + Utils.processHttpRequest(new HttpDelete(requestUrl)); + waitForPolicyRefresh(); + } + + protected boolean hasAccess(String user, + Map resources, + List privileges) + throws IOException { + + log.info("Checking access for user " + user); + RPSRequest request = new RPSRequest(user, resources, privileges); + HttpPost httpPost = new HttpPost(RANGER_PLUGIN_SERVICE_URL); + httpPost.setEntity(new StringEntity(request.getJsonString())); + String result = Utils.processHttpRequest(httpPost); + RPSResponse rpsResponse = Utils.getResponse(result); + return rpsResponse.hasAccess(); + } + + private void waitForPolicyRefresh() { + + try { + Thread.sleep(POLICY_REFRESH_INTERVAL); + } + catch (InterruptedException e) { + log.error(e); + } + } + + public abstract void beforeTest() throws IOException; +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/TablespaceTest.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/TablespaceTest.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/TablespaceTest.java new file mode 100644 index 0000000..cfc41cb --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/TablespaceTest.java @@ -0,0 +1,67 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.junit.Test; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class TablespaceTest extends ServiceBaseTest { + + private static final List PRIVILEGES = Arrays.asList("create"); + + public void beforeTest() + throws IOException { + createPolicy("test-tablespace.json"); + resources.put("tablespace", "pg_global"); + } + + @Test + public void testTablespaces_UserMaria_PgGlobalTablespace_Allowed() + throws IOException { + assertTrue(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testTablespaces_UserMaria_DoesNotExistTablespace_Denied() + throws IOException { + resources.put("tablespace", "doesnotexist"); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + + @Test + public void testTablespaces_UserBob_PgGlobalTablespace_Denied() + throws IOException { + assertFalse(hasAccess("bob", resources, PRIVILEGES)); + } + + @Test + public void testTablespaces_UserMaria_PgGlobalTablespace_Denied() + throws IOException { + deletePolicy(); + assertFalse(hasAccess(RANGER_TEST_USER, resources, PRIVILEGES)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/Utils.java ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/Utils.java b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/Utils.java new file mode 100644 index 0000000..971e513 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/java/org/apache/hawq/ranger/integration/service/tests/Utils.java @@ -0,0 +1,76 @@ +/* + * 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.hawq.ranger.integration.service.tests; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.impl.client.HttpClientBuilder; +import org.codehaus.jackson.map.ObjectMapper; + +import java.io.IOException; + +public class Utils { + + protected static final Log log = LogFactory.getLog(Utils.class); + + public static String getPayload(String jsonFile) + throws IOException { + return IOUtils.toString(Utils.class.getClassLoader().getResourceAsStream(jsonFile)); + } + + public static String getEncoding() { + return Base64.encodeBase64String("admin:admin".getBytes()); + } + + public static String processHttpRequest(HttpRequestBase request) + throws IOException { + + if (log.isDebugEnabled()) { + log.debug("Request URI = " + request.getURI().toString()); + } + request.setHeader("Authorization", "Basic " + getEncoding()); + request.setHeader("Content-Type", "application/json"); + HttpClient httpClient = HttpClientBuilder.create().build(); + HttpResponse response = httpClient.execute(request); + int responseCode = response.getStatusLine().getStatusCode(); + log.info("Response Code = " + responseCode); + HttpEntity entity = response.getEntity(); + if (entity != null) { + String result = IOUtils.toString(entity.getContent()); + if (log.isDebugEnabled()) { + log.debug(result); + } + return result; + } + return null; + } + + public static RPSResponse getResponse(String result) + throws IOException { + return new ObjectMapper().readValue(result, RPSResponse.class); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/log4j.properties b/ranger-plugin/integration/service/src/test/resources/log4j.properties new file mode 100644 index 0000000..8578fd2 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/log4j.properties @@ -0,0 +1,35 @@ +# 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. + +##-- To prevent junits from cluttering the build run by default all test runs send output to null appender +log4j.appender.devnull=org.apache.log4j.varia.NullAppender +#hawq.ranger.root.logger=FATAL,devnull + +##-- uncomment the following line during during development/debugging so see debug messages during test run to be emitted to console +hawq.ranger.root.logger=DEBUG,console +log4j.rootLogger=${hawq.ranger.root.logger} +log4j.logger.org.apache.http=WARN + +# Logging Threshold +log4j.threshold=ALL + +# +# console +# Add "console" to rootlogger above if you want to use this +# +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.err +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c{2}: %m%n http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/test-database.json ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/test-database.json b/ranger-plugin/integration/service/src/test/resources/test-database.json new file mode 100644 index 0000000..ffa3bfe --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/test-database.json @@ -0,0 +1,46 @@ +{ + "isEnabled": true, + "service": "hawq", + "name": "DatabaseTest", + "policyType": 0, + "description": "Test policy for database resource", + "isAuditEnabled": true, + "resources": { + "schema": { + "values": ["*"], + "isExcludes": false, + "isRecursive": false + }, + "database": { + "values": ["sirotan"], + "isExcludes": false, + "isRecursive": false + }, + "function": { + "values": ["*"], + "isExcludes": false, + "isRecursive": false + } + }, + "policyItems": [{ + "accesses": [{ + "type": "create", + "isAllowed": true + }, { + "type": "connect", + "isAllowed": true + }, { + "type": "temp", + "isAllowed": true + }], + "users": ["maria_dev"], + "groups": [], + "conditions": [], + "delegateAdmin": true + }], + "denyPolicyItems": [], + "allowExceptions": [], + "denyExceptions": [], + "dataMaskPolicyItems": [], + "rowFilterPolicyItems": [] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/test-function-2.json ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/test-function-2.json b/ranger-plugin/integration/service/src/test/resources/test-function-2.json new file mode 100644 index 0000000..5ae7f0b --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/test-function-2.json @@ -0,0 +1,40 @@ +{ + "isEnabled": true, + "service": "hawq", + "name": "FunctionTest", + "policyType": 0, + "description": "Test policy for function resource", + "isAuditEnabled": true, + "resources": { + "schema": { + "values": ["*"], + "isExcludes": false, + "isRecursive": false + }, + "database": { + "values": ["*"], + "isExcludes": false, + "isRecursive": false + }, + "function": { + "values": ["atan"], + "isExcludes": false, + "isRecursive": false + } + }, + "policyItems": [{ + "accesses": [{ + "type": "execute", + "isAllowed": true + }], + "users": ["maria_dev"], + "groups": [], + "conditions": [], + "delegateAdmin": true + }], + "denyPolicyItems": [], + "allowExceptions": [], + "denyExceptions": [], + "dataMaskPolicyItems": [], + "rowFilterPolicyItems": [] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/test-function.json ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/test-function.json b/ranger-plugin/integration/service/src/test/resources/test-function.json new file mode 100644 index 0000000..74d5d83 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/test-function.json @@ -0,0 +1,40 @@ +{ + "isEnabled": true, + "service": "hawq", + "name": "FunctionTest", + "policyType": 0, + "description": "Test policy for function resource", + "isAuditEnabled": true, + "resources": { + "schema": { + "values": ["siroschema"], + "isExcludes": false, + "isRecursive": false + }, + "database": { + "values": ["sirotan"], + "isExcludes": false, + "isRecursive": false + }, + "function": { + "values": ["atan"], + "isExcludes": false, + "isRecursive": false + } + }, + "policyItems": [{ + "accesses": [{ + "type": "execute", + "isAllowed": true + }], + "users": ["maria_dev"], + "groups": [], + "conditions": [], + "delegateAdmin": true + }], + "denyPolicyItems": [], + "allowExceptions": [], + "denyExceptions": [], + "dataMaskPolicyItems": [], + "rowFilterPolicyItems": [] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/test-language-2.json ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/test-language-2.json b/ranger-plugin/integration/service/src/test/resources/test-language-2.json new file mode 100644 index 0000000..93a41fe --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/test-language-2.json @@ -0,0 +1,35 @@ +{ + "isEnabled": true, + "service": "hawq", + "name": "LanguageTest", + "policyType": 0, + "description": "Test policy for language resource", + "isAuditEnabled": true, + "resources": { + "language": { + "values": ["sql"], + "isExcludes": false, + "isRecursive": false + }, + "database": { + "values": ["*"], + "isExcludes": false, + "isRecursive": false + } + }, + "policyItems": [{ + "accesses": [{ + "type": "usage", + "isAllowed": true + }], + "users": ["maria_dev"], + "groups": [], + "conditions": [], + "delegateAdmin": true + }], + "denyPolicyItems": [], + "allowExceptions": [], + "denyExceptions": [], + "dataMaskPolicyItems": [], + "rowFilterPolicyItems": [] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/test-language.json ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/test-language.json b/ranger-plugin/integration/service/src/test/resources/test-language.json new file mode 100644 index 0000000..cba2f43 --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/test-language.json @@ -0,0 +1,35 @@ +{ + "isEnabled": true, + "service": "hawq", + "name": "LanguageTest", + "policyType": 0, + "description": "Test policy for language resource", + "isAuditEnabled": true, + "resources": { + "language": { + "values": ["sql"], + "isExcludes": false, + "isRecursive": false + }, + "database": { + "values": ["sirotan"], + "isExcludes": false, + "isRecursive": false + } + }, + "policyItems": [{ + "accesses": [{ + "type": "usage", + "isAllowed": true + }], + "users": ["maria_dev"], + "groups": [], + "conditions": [], + "delegateAdmin": true + }], + "denyPolicyItems": [], + "allowExceptions": [], + "denyExceptions": [], + "dataMaskPolicyItems": [], + "rowFilterPolicyItems": [] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/test-protocol.json ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/test-protocol.json b/ranger-plugin/integration/service/src/test/resources/test-protocol.json new file mode 100644 index 0000000..d59caed --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/test-protocol.json @@ -0,0 +1,33 @@ +{ + "isEnabled": true, + "service": "hawq", + "name": "ProtocolTest", + "policyType": 0, + "description": "Test policy for protocol resource", + "isAuditEnabled": true, + "resources": { + "protocol": { + "values": ["pxf"], + "isExcludes": false, + "isRecursive": false + } + }, + "policyItems": [{ + "accesses": [{ + "type": "select", + "isAllowed": true + }, { + "type": "insert", + "isAllowed": true + }], + "users": ["maria_dev"], + "groups": [], + "conditions": [], + "delegateAdmin": true + }], + "denyPolicyItems": [], + "allowExceptions": [], + "denyExceptions": [], + "dataMaskPolicyItems": [], + "rowFilterPolicyItems": [] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7f36b35b/ranger-plugin/integration/service/src/test/resources/test-tablespace.json ---------------------------------------------------------------------- diff --git a/ranger-plugin/integration/service/src/test/resources/test-tablespace.json b/ranger-plugin/integration/service/src/test/resources/test-tablespace.json new file mode 100644 index 0000000..a45ecea --- /dev/null +++ b/ranger-plugin/integration/service/src/test/resources/test-tablespace.json @@ -0,0 +1,30 @@ +{ + "isEnabled": true, + "service": "hawq", + "name": "TablespaceTest", + "policyType": 0, + "description": "Test policy for tablespace resource", + "isAuditEnabled": true, + "resources": { + "tablespace": { + "values": ["pg_global"], + "isExcludes": false, + "isRecursive": false + } + }, + "policyItems": [{ + "accesses": [{ + "type": "create", + "isAllowed": true + }], + "users": ["maria_dev"], + "groups": [], + "conditions": [], + "delegateAdmin": true + }], + "denyPolicyItems": [], + "allowExceptions": [], + "denyExceptions": [], + "dataMaskPolicyItems": [], + "rowFilterPolicyItems": [] +} \ No newline at end of file