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


##########
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:
   Fixed — wrapped the servlet/filter inspection block in try/finally so 
server.stop() always runs, even on assertion failure.



##########
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:
   Fixed — wrapped the servlet/filter inspection block in try/finally so 
server.stop() always runs, even on assertion failure.



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