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 464bfd95e RANGER-5397: IllegalArgumentException in RangerRESTClient
when no ran… (#732)
464bfd95e is described below
commit 464bfd95efa37984a0274bcdf7c0332330f4cc57
Author: Vyom Mani Tiwari <[email protected]>
AuthorDate: Wed Dec 31 13:35:22 2025 +0530
RANGER-5397: IllegalArgumentException in RangerRESTClient when no ran…
(#732)
* 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.
---
.../ranger/plugin/util/RangerRESTClient.java | 8 ++--
.../ranger/plugin/util/TestRangerRESTClient.java | 50 ++++++++++++++++++++++
2 files changed, 55 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..0e5d34e04
--- /dev/null
+++
b/agents-common/src/test/java/org/apache/ranger/plugin/util/TestRangerRESTClient.java
@@ -0,0 +1,50 @@
+/*
+ * 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.Assert;
+import org.junit.Test;
+
+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 =
Assert.assertThrows(IllegalArgumentException.class, plugin::init);
+ Assert.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();
+ Assert.assertNotNull("RangerBasePlugin should be initialized
successfully", plugin);
+ }
+}