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


##########
iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/TestRESTService.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.iceberg;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Collections;
+import java.util.Set;
+import org.apache.gravitino.iceberg.common.IcebergConfig;
+import org.apache.gravitino.listener.EventBus;
+import org.apache.gravitino.server.web.HttpAuditFilter;
+import org.apache.gravitino.server.web.JettyServer;
+import org.apache.gravitino.server.web.JettyServerConfig;
+import org.apache.gravitino.server.web.JettyServerTestUtils;
+import org.apache.gravitino.server.web.RequestContextFilter;
+import org.eclipse.jetty.servlet.ServletHandler;
+import org.junit.jupiter.api.Test;
+
+public class TestRESTService {
+
+  /**
+   * RESTService.initServer() previously registered /metrics and 
/prometheus/metrics (added by
+   * JettyServer#initialize() itself, outside ICEBERG_SPEC) with no audit 
coverage at all, and
+   * nothing in the build caught it. Rather than parse source text, this 
exercises the extracted
+   * RESTService#registerMetricsPathFilters against a plain JettyServer and 
inspects the real
+   * ServletHandler filter mappings it produces, so a broken 
JettyServer.METRICS_PATH_SPECS list or
+   * a filter that merely appears in a comment cannot pass. See GH-12760.
+   */
+  @Test
+  public void testMetricsPathsHaveAuditFilterCoverage() throws Exception {
+    JettyServer server = new JettyServer();
+    JettyServerConfig jettyServerConfig = JettyServerConfig.fromConfig(new 
IcebergConfig());
+    server.initialize(jettyServerConfig, "test-iceberg-rest", false);
+    EventBus eventBus = new EventBus(Collections.emptyList());
+
+    RESTService.registerMetricsPathFilters(server, eventBus);
+
+    ServletHandler servletHandler =
+        
JettyServerTestUtils.getServletContextHandler(server).getServletHandler();
+    Set<String> auditedPathSpecs =
+        JettyServerTestUtils.filterPathSpecsFor(servletHandler, 
HttpAuditFilter.class);
+    Set<String> requestContextPathSpecs =
+        JettyServerTestUtils.filterPathSpecsFor(servletHandler, 
RequestContextFilter.class);
+
+    for (String pathSpec : JettyServer.METRICS_PATH_SPECS) {
+      assertTrue(
+          auditedPathSpecs.contains(pathSpec),
+          "'" + pathSpec + "' must be covered by HttpAuditFilter, see 
GH-12760");
+      assertTrue(
+          requestContextPathSpecs.contains(pathSpec),
+          "'"
+              + pathSpec
+              + "' must be covered by RequestContextFilter for query-parameter 
"
+              + "capture, see GH-12760");
+    }
+
+    server.stop();
+  }

Review Comment:
   `server.stop()` is only called at the end of the test; if an assertion fails 
earlier, the JettyServer instance won’t be stopped, which can leak resources 
and make subsequent tests flaky. Wrap the servlet/filter inspection block in a 
try/finally so `server.stop()` always runs.



##########
lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/TestLanceRESTService.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.lance;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Collections;
+import java.util.Set;
+import org.apache.gravitino.lance.common.config.LanceConfig;
+import org.apache.gravitino.listener.EventBus;
+import org.apache.gravitino.server.web.HttpAuditFilter;
+import org.apache.gravitino.server.web.JettyServer;
+import org.apache.gravitino.server.web.JettyServerConfig;
+import org.apache.gravitino.server.web.JettyServerTestUtils;
+import org.apache.gravitino.server.web.RequestContextFilter;
+import org.eclipse.jetty.servlet.ServletHandler;
+import org.junit.jupiter.api.Test;
+
+public class TestLanceRESTService {
+
+  /**
+   * LanceRESTService.serviceInit() previously registered /metrics and 
/prometheus/metrics (added by
+   * JettyServer#initialize() itself, outside LANCE_SPEC) with no audit 
coverage at all, and nothing
+   * in the build caught it. Rather than parse source text, this exercises the 
extracted
+   * LanceRESTService#registerMetricsPathFilters against a plain JettyServer 
and inspects the real
+   * ServletHandler filter mappings it produces, so a broken 
JettyServer.METRICS_PATH_SPECS list or
+   * a filter that merely appears in a comment cannot pass. See GH-12760.
+   */
+  @Test
+  public void testMetricsPathsHaveAuditFilterCoverage() throws Exception {
+    JettyServer server = new JettyServer();
+    JettyServerConfig jettyServerConfig = JettyServerConfig.fromConfig(new 
LanceConfig());
+    server.initialize(jettyServerConfig, "test-lance-rest", false);
+    EventBus eventBus = new EventBus(Collections.emptyList());
+
+    LanceRESTService.registerMetricsPathFilters(server, eventBus);
+
+    ServletHandler servletHandler =
+        
JettyServerTestUtils.getServletContextHandler(server).getServletHandler();
+    Set<String> auditedPathSpecs =
+        JettyServerTestUtils.filterPathSpecsFor(servletHandler, 
HttpAuditFilter.class);
+    Set<String> requestContextPathSpecs =
+        JettyServerTestUtils.filterPathSpecsFor(servletHandler, 
RequestContextFilter.class);
+
+    for (String pathSpec : JettyServer.METRICS_PATH_SPECS) {
+      assertTrue(
+          auditedPathSpecs.contains(pathSpec),
+          "'" + pathSpec + "' must be covered by HttpAuditFilter, see 
GH-12760");
+      assertTrue(
+          requestContextPathSpecs.contains(pathSpec),
+          "'"
+              + pathSpec
+              + "' must be covered by RequestContextFilter for query-parameter 
"
+              + "capture, see GH-12760");
+    }
+
+    server.stop();
+  }

Review Comment:
   `server.stop()` is only called at the end of the test; if an assertion fails 
earlier, the JettyServer instance won’t be stopped, which can leak resources 
and make subsequent tests flaky. Wrap the servlet/filter inspection block in a 
try/finally so `server.stop()` always runs.



##########
server/src/test/java/org/apache/gravitino/server/TestGravitinoServer.java:
##########
@@ -57,6 +68,36 @@
 @TestInstance(Lifecycle.PER_CLASS)
 public class TestGravitinoServer {
 
+  // Static-asset and forwarding paths shared by both exemption sets below, 
each for the same
+  // reason in both: WebUIFilter's static assets and HealthAliasServlet's 
forwarded probes need
+  // no direct filter binding of their own on this path. See GH-12760.
+  private static final Set<String> STATIC_AND_FORWARDING_PATHS =
+      ImmutableSet.of(
+          "/", // DefaultServlet / WebUIFilter: serves static UI assets, no 
server-side logic.
+          "/ui/*", // WebUIFilter: serves static UI assets, no server-side 
logic.
+          "/health/*", // HealthAliasServlet forwards into /api/health*, 
already covered via the
+          "/health.html" // FORWARD dispatcher type; binding again here would 
double-log probes.
+          );

Review Comment:
   The inline comment for `"/health/*"` is left dangling ("already covered via 
the") and the explanation continues on the next line attached to 
`"/health.html"`, which makes the reason for the exemption hard to read. Make 
each entry’s comment self-contained.



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