Copilot commented on code in PR #14532:
URL: https://github.com/apache/gravitino/pull/14532#discussion_r4450255296


##########
authorizations/authorization-ranger/src/test/java/org/apache/gravitino/authorization/ranger/TestRangerClientExtension.java:
##########
@@ -0,0 +1,220 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpServer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import org.apache.gravitino.authorization.ranger.reference.VXGroup;
+import org.apache.gravitino.authorization.ranger.reference.VXGroupList;
+import org.apache.gravitino.authorization.ranger.reference.VXUser;
+import org.apache.gravitino.authorization.ranger.reference.VXUserList;
+import org.apache.ranger.RangerServiceException;
+import org.apache.ranger.plugin.model.RangerPolicy;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Exercises {@link RangerClientExtension} over HTTP against a stub Ranger 
Admin. */
+public class TestRangerClientExtension {
+
+  private static final ObjectMapper MAPPER = new ObjectMapper();
+
+  private final List<String> requests = new CopyOnWriteArrayList<>();
+  private final Map<String, String> requestBodies = new ConcurrentHashMap<>();
+  private HttpServer server;
+  private RangerClientExtension client;
+
+  @BeforeEach
+  public void setUp() throws IOException {
+    server = HttpServer.create(new 
InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);

Review Comment:
   `InetAddress.getLoopbackAddress()` can return `::1` when IPv6 is preferred, 
but the client URL below always uses `127.0.0.1`. In that configuration the 
stub listens on IPv6 while every request targets IPv4, causing these tests to 
fail with connection errors. Bind explicitly to the IPv4 address used by the 
client, or construct the URL from the actual bound address.



##########
authorizations/authorization-ranger/src/test/java/org/apache/gravitino/authorization/ranger/integration/test/RangerITEnv.java:
##########
@@ -517,7 +517,7 @@ protected static void updateOrCreateRangerPolicy(
       Assertions.assertTrue(policies.size() <= 1);
       if (!policies.isEmpty()) {
         RangerPolicy policy = policies.get(0);
-        policy.getPolicyItems().addAll(policyItems);
+        policyItems.forEach(policy::addPolicyItem);

Review Comment:
   `RangerITEnv` uses the plain client from `RangerContainer`, so updating a 
fetched policy bypasses the timestamp workaround and sends Ranger 2.8's 
incompatible dates to Admin 2.4, causing HTTP 400. Route these updates through 
`RangerClientExtension` or omit both server-managed timestamps before sending. 
The same issue affects `RangerHiveIT.java:2201`.



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