You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2026/09/18 12:14:24 UTC

(unomi) branch graphql-ws-it-signatures created (now 9af5a7546)

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

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


      at 9af5a7546 Keep Jetty client types out of GraphQLWebSocketIT method signatures

This branch includes the following new commits:

     new 9af5a7546 Keep Jetty client types out of GraphQLWebSocketIT method signatures

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(unomi) 01/01: Keep Jetty client types out of GraphQLWebSocketIT method signatures

Posted by sh...@apache.org.
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 <sh...@apache.org>
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 <no...@anthropic.com>
---
 .../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);