fmorg-git commented on code in PR #766:
URL: https://github.com/apache/ranger/pull/766#discussion_r2608436687


##########
plugin-ozone/src/test/java/org/apache/ranger/authorization/ozone/authorizer/TestRangerOzoneAuthorizer.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.ranger.authorization.ozone.authorizer;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.AssumeRoleRequest;
+import org.apache.hadoop.ozone.security.acl.AssumeRoleRequest.OzoneGrant;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
+import org.apache.hadoop.ozone.security.acl.RequestContext;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig;
+import org.apache.ranger.plugin.model.RangerInlinePolicy;
+import org.apache.ranger.plugin.policyengine.RangerPluginContext;
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+import org.apache.ranger.plugin.util.JsonUtilsV2;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class TestRangerOzoneAuthorizer {
+    static RangerOzoneAuthorizer ozoneAuthorizer;
+
+    private final String               hostname  = "localhost";
+    private final InetAddress          ipAddress = 
InetAddress.getLoopbackAddress();
+    private final UserGroupInformation user1     = 
UserGroupInformation.createRemoteUser("user1");
+    private final UserGroupInformation user2     = 
UserGroupInformation.createRemoteUser("user2");
+    private final String               role1     = "role1";
+
+    private final OzoneObj vol1  = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.VOLUME).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol1").build();
+    private final OzoneObj buck1 = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.BUCKET).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol1").setBucketName("buck1").build();
+    private final OzoneObj key1  = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.KEY).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol1").setBucketName("buck1").setKeyName("key1").build();
+    private final OzoneObj vol2  = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.VOLUME).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol2").build();
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        RangerPluginContext pluginContext = new RangerPluginContext(new 
RangerPluginConfig("ozone", null, "om", null, null, null));
+        RangerBasePlugin    plugin        = new 
RangerBasePlugin(pluginContext.getConfig());
+
+        plugin.init();
+
+        ozoneAuthorizer = new RangerOzoneAuthorizer(plugin);
+
+        assertNotNull(ozoneAuthorizer);
+    }
+
+    @Test
+    public void testAssumeRoleDeny() throws Exception {
+        // user1 should not be allowed to assume role1
+        AssumeRoleRequest request = new AssumeRoleRequest(hostname, ipAddress, 
user1, role1, null);
+
+        assertThrows(OMException.class, () -> 
ozoneAuthorizer.generateAssumeRoleSessionPolicy(request));
+    }
+
+    @Test
+    public void testAssumeRoleWithNoGrants() throws Exception {
+        // user2 should be allowed to assume role1
+        AssumeRoleRequest request = new AssumeRoleRequest(hostname, ipAddress, 
user2, role1, Collections.emptySet());
+

Review Comment:
   here for grants of `Collections.emptySet()`, I believe no permissions should 
be allowed in the session policy



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to