smengcl commented on code in PR #10872:
URL: https://github.com/apache/ozone/pull/10872#discussion_r3756677096


##########
hadoop-ozone/multitenancy-ranger/src/test/java/org/apache/hadoop/ozone/om/multitenant/TestRangerClientMultiTenantAccessControllerMockClient.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.hadoop.ozone.om.multitenant;
+
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_KERBEROS_KEYTAB_FILE_KEY;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_KERBEROS_PRINCIPAL_KEY;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_RANGER_HTTPS_ADDRESS_KEY;
+import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_RANGER_SERVICE;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.sun.jersey.api.client.ClientResponse;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import org.apache.hadoop.hdds.conf.InMemoryConfigurationForTesting;
+import org.apache.hadoop.hdds.conf.MutableConfigurationSource;
+import org.apache.hadoop.ozone.om.multitenant.MultiTenantAccessController.Acl;
+import 
org.apache.hadoop.ozone.om.multitenant.MultiTenantAccessController.Policy;
+import org.apache.hadoop.ozone.om.multitenant.MultiTenantAccessController.Role;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
+import org.apache.hadoop.security.authentication.util.KerberosName;
+import org.apache.ranger.RangerClient;
+import org.apache.ranger.RangerServiceException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit tests for {@link RangerClientMultiTenantAccessController} that use a
+ * mock {@link RangerClient} instead of a live Ranger endpoint.
+ */
+class TestRangerClientMultiTenantAccessControllerMockClient {
+
+  private RangerClient rangerClient;
+  private RangerClientMultiTenantAccessController accessController;
+
+  @BeforeEach
+  public void setUpMocks() throws Exception {
+    rangerClient = mock(RangerClient.class);
+    
+    MutableConfigurationSource conf = new InMemoryConfigurationForTesting();
+    conf.set(OZONE_RANGER_HTTPS_ADDRESS_KEY, "https://localhost:6182/";);
+    conf.set(OZONE_RANGER_SERVICE, "cm_ozone");
+    conf.set(OZONE_OM_KERBEROS_PRINCIPAL_KEY, "om/[email protected]");
+    conf.set(OZONE_OM_KERBEROS_KEYTAB_FILE_KEY, "/path/to/ozone.keytab");
+
+    // Initialize Kerberos name rules before creating the controller
+    KerberosName.setRules(conf.get("hadoop.security.auth_to_local", 
"DEFAULT"));

Review Comment:
   These six tests now run, but they fail in `setUpMocks()` before the mock is 
installed. `DEFAULT` does not map the configured `EXAMPLE.COM` principal when 
the host uses a different default realm. The targeted JDK 21 run reports `Tests 
run: 6, Errors: 6`.
   
   Could you set an explicit mapping for `EXAMPLE.COM`? This change made all 
six tests pass locally:
   
   ```diff
   -    KerberosName.setRules(conf.get("hadoop.security.auth_to_local", 
"DEFAULT"));
   +    KerberosName.setRules(
   +        "RULE:[2:$1@$0](.*@EXAMPLE.COM)s/@.*//\n" +
   +            "DEFAULT");
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to