This is an automated email from the ASF dual-hosted git repository.

pradeep pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new d21032d12 RANGER-5397: IllegalArgumentException in RangerRESTClient 
when no ranger.plugin.<service>.policy.rest.url is configured (#779)
d21032d12 is described below

commit d21032d1241b8890c5fa53455781261fa9178b04
Author: Vyom Mani Tiwari <[email protected]>
AuthorDate: Wed Dec 31 16:11:00 2025 +0530

    RANGER-5397: IllegalArgumentException in RangerRESTClient when no 
ranger.plugin.<service>.policy.rest.url is configured (#779)
    
    * RANGER-5397: IllegalArgumentException in RangerRESTClient when no 
ranger.plugin.<service>.policy.rest.url is configured
    
    * fixed checkstyle issues.
    
    * change the code to throw IAE if url is not set.
    
    * migrated test to junit 5
---
 .../ranger/plugin/util/RangerRESTClient.java       |  8 ++--
 .../ranger/plugin/util/TestRangerRESTClient.java   | 53 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 3 deletions(-)

diff --git 
a/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
 
b/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
index 447ddd90b..da1e0eee9 100644
--- 
a/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
+++ 
b/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
@@ -110,9 +110,11 @@ public RangerRESTClient(String url, String 
sslConfigFileName, Configuration conf
         mUrl               = url;
         mSslConfigFileName = sslConfigFileName;
         configuredURLs     = StringUtil.getURLs(mUrl);
-
-        setLastKnownActiveUrlIndex((new 
Random()).nextInt(getConfiguredURLs().size()));
-
+        if (StringUtil.isEmpty(url)) {
+            throw new IllegalArgumentException("Ranger URL is null or empty. 
Likely caused by incorrect configuration");
+        } else {
+            setLastKnownActiveUrlIndex((new 
Random()).nextInt(getConfiguredURLs().size()));
+        }
         init(config);
     }
 
diff --git 
a/agents-common/src/test/java/org/apache/ranger/plugin/util/TestRangerRESTClient.java
 
b/agents-common/src/test/java/org/apache/ranger/plugin/util/TestRangerRESTClient.java
new file mode 100644
index 000000000..9d837a2c4
--- /dev/null
+++ 
b/agents-common/src/test/java/org/apache/ranger/plugin/util/TestRangerRESTClient.java
@@ -0,0 +1,53 @@
+/*
+ * 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.plugin.util;
+
+import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig;
+import org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions;
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class TestRangerRESTClient {
+    private static final String SERVICE_TYPE = "hive";
+    private static final String SERVICE_NAME = "test-service";
+    private static final String APP_ID = "test-app";
+    private static final String ERR_MESSAGE = "Ranger URL is null or empty.";
+
+    @Test
+    public void testPluginInit_WithNoUrl_ThrowsException() {
+        RangerBasePlugin plugin = new RangerBasePlugin(SERVICE_TYPE, 
SERVICE_NAME, APP_ID);
+        IllegalArgumentException exception = 
assertThrows(IllegalArgumentException.class, plugin::init);
+        assertTrue(exception.getMessage().contains(ERR_MESSAGE));
+    }
+
+    @Test
+    public void testPluginInit_WithValidUrl_Succeeds() {
+        RangerPolicyEngineOptions peOptions = new RangerPolicyEngineOptions();
+        RangerPluginConfig pluginConfig = new RangerPluginConfig(SERVICE_TYPE, 
SERVICE_NAME, APP_ID, "cl1", "on-perm", peOptions);
+        pluginConfig.set("ranger.plugin.hive.policy.rest.url", 
"http://dummy:1234";);
+        RangerBasePlugin plugin = new RangerBasePlugin(pluginConfig);
+        plugin.init();
+        assertNotNull(plugin, "RangerBasePlugin should be initialized 
successfully");
+    }
+}

Reply via email to