This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch graphql-ws-it-signatures
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 9af5a7546167997637c692e06404bf95376e96c0
Author: Serge Huber <[email protected]>
AuthorDate: Fri Sep 4 17:17:55 2026 +0200

    Keep Jetty client types out of GraphQLWebSocketIT method signatures
    
    JUnit resolves the types in a test class's method signatures when it scans 
the
    class, before the test setup has waited for the container to finish
    provisioning, so a class that runs early fails to load when a helper takes a
    websocket-client type as a parameter. Build the upgrade request inside the
    helpers instead.
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
---
 .../unomi/itests/graphql/GraphQLWebSocketIT.java   | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git 
a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java 
b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java
index b0160cb78..65a5e2479 100644
--- 
a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java
+++ 
b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLWebSocketIT.java
@@ -108,15 +108,13 @@ public class GraphQLWebSocketIT extends BaseGraphQLIT {
      */
     @Test
     public void testWebSocketUpgrade_withoutAuth_upgradesButCannotOperate() 
throws Exception {
-        assertStartIsRefusedBeforeAuthentication(new ClientUpgradeRequest());
+        assertStartIsRefusedBeforeAuthentication(null, null);
     }
 
     /** A public API key is not a subscription credential, on the handshake or 
anywhere else. */
     @Test
     public void testWebSocketUpgrade_withPublicApiKeyOnly_cannotOperate() 
throws Exception {
-        ClientUpgradeRequest request = new ClientUpgradeRequest();
-        request.setHeader("X-Unomi-Api-Key", testPublicKeyValue);
-        assertStartIsRefusedBeforeAuthentication(request);
+        assertStartIsRefusedBeforeAuthentication("X-Unomi-Api-Key", 
testPublicKeyValue);
     }
 
     /** connection_init carrying a valid credential is how a browser client 
authenticates. */
@@ -167,11 +165,20 @@ public class GraphQLWebSocketIT extends BaseGraphQLIT {
      * The core property of the unauthenticated-upgrade path: an operation 
sent before authenticating is
      * refused and the socket is closed. Without this, opening the handshake 
would be a regression.
      */
-    private void assertStartIsRefusedBeforeAuthentication(ClientUpgradeRequest 
request) throws Exception {
+    /**
+     * Jetty's websocket-client types are kept out of method signatures on 
purpose: JUnit resolves
+     * signature types when it scans the class, before {@code @Before} has 
waited for the container,
+     * and that bundle is not necessarily wired yet at that point.
+     */
+    private void assertStartIsRefusedBeforeAuthentication(String headerName, 
String headerValue) throws Exception {
         WebSocketClient client = new WebSocketClient();
         Socket socket = new Socket();
         try {
             client.start();
+            ClientUpgradeRequest request = new ClientUpgradeRequest();
+            if (headerName != null) {
+                request.setHeader(headerName, headerValue);
+            }
             Future<Session> onConnected = client.connect(socket, 
graphqlWebSocketUri(), request);
             RemoteEndpoint remote = onConnected.get(10, 
TimeUnit.SECONDS).getRemote();
 
@@ -198,16 +205,12 @@ public class GraphQLWebSocketIT extends BaseGraphQLIT {
 
     @Test
     public void testWebSocketUpgrade_withWrongJaasPassword_returns401() throws 
Exception {
-        ClientUpgradeRequest request = new ClientUpgradeRequest();
-        request.setHeader("Authorization", 
basicAuthHeader(BASIC_AUTH_USER_NAME, "definitely-not-the-password"));
-        assertWebSocketUpgradeRejected(request);
+        assertWebSocketUpgradeRejected(basicAuthHeader(BASIC_AUTH_USER_NAME, 
"definitely-not-the-password"));
     }
 
     @Test
     public void testWebSocketUpgrade_withMalformedBasic_returns401() throws 
Exception {
-        ClientUpgradeRequest request = new ClientUpgradeRequest();
-        request.setHeader("Authorization", "Basic !!!");
-        assertWebSocketUpgradeRejected(request);
+        assertWebSocketUpgradeRejected("Basic !!!");
     }
 
     @Test
@@ -270,12 +273,14 @@ public class GraphQLWebSocketIT extends BaseGraphQLIT {
         }
     }
 
-    private void assertWebSocketUpgradeRejected(ClientUpgradeRequest request) 
throws Exception {
+    private void assertWebSocketUpgradeRejected(String authorization) throws 
Exception {
         WebSocketClient client = new WebSocketClient();
         Socket socket = new Socket();
         try {
             client.start();
             URI echoUri = new URI("ws://localhost:" + getHttpPort() + 
"/graphql");
+            ClientUpgradeRequest request = new ClientUpgradeRequest();
+            request.setHeader("Authorization", authorization);
             Future<Session> onConnected = client.connect(socket, echoUri, 
request);
             try {
                 onConnected.get(10, TimeUnit.SECONDS);

Reply via email to