ramu11 commented on code in PR #9509:
URL: https://github.com/apache/camel-quarkus/pull/9509#discussion_r4704331963


##########
integration-tests/mcp-server/src/test/java/org/apache/camel/quarkus/component/mcp/server/it/McpServerOAuthTest.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.camel.quarkus.component.mcp.server.it;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import io.quarkiverse.mcp.server.TextContent;
+import io.quarkiverse.mcp.server.ToolResponse;
+import io.quarkiverse.mcp.server.test.McpAssured;
+import io.quarkiverse.mcp.server.test.McpAssured.McpStreamableTestClient;
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Exercises a real Keycloak/OIDC identity through MCP and into a Camel tool 
route. */
+@QuarkusTest
+@QuarkusTestResource(value = McpServerKeycloakTestResource.class, 
restrictToAnnotatedClass = true)
+class McpServerOAuthTest {
+
+    private static final String INITIALIZE_REQUEST = 
"{\"jsonrpc\":\"2.0\",\"id\":1,"
+            + 
"\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-06-18\","
+            + 
"\"capabilities\":{},\"clientInfo\":{\"name\":\"camel-quarkus-keycloak-test\",\"version\":\"1\"}}}";
+
+    @Test
+    void anonymousMcpRequestIsRejected() {
+        postInitialize(null, 401, false);
+    }
+
+    @Test
+    void invalidBearerTokenIsRejected() {
+        postInitialize("not-a-valid-keycloak-token", 401, false);
+    }
+
+    @Test
+    void protectedResourceMetadataIsPublished() {
+        String issuer = keycloakIssuer();
+        String metadata = 
RestAssured.get("/.well-known/oauth-protected-resource")
+                .then()
+                .statusCode(200)
+                .extract()
+                .asString();
+        
assertThat(metadata).contains("authorization_servers").contains(issuer);
+    }
+
+    // This exercises quarkus-mcp-server's loopback DNS-rebinding check, not a 
general Origin allow-list.
+    @Test
+    void untrustedOriginIsRejectedEvenWithValidBearerToken() {
+        postInitialize(accessToken(), 403, true);

Review Comment:
   Addressed in commit `ed222bd3d881889857afc2ce375d7e46f326bfa7`.
   
   Removed the Quarkus CORS configuration from both:
   - `integration-tests/mcp-server/src/main/resources/application.properties`
   - `integration-tests/mcp-server/src/test/resources/application.properties`
   
   I also strengthened `postInitialize()` in `McpServerOAuthTest` to assert 
that the untrusted-origin response contains `Invalid origin`, in addition to 
asserting HTTP 403.
   
   This ensures the test verifies that quarkus-mcp-server's loopback 
DNS-rebinding protection rejects the request, rather than passing because of 
the Quarkus CORS filter.
   
   The MCP integration-test build passes with this change.



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