This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch
backport/graphql-websocket-auth-3.0.x
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to
refs/heads/backport/graphql-websocket-auth-3.0.x by this push:
new b9b38b132 Keep Jetty client types out of GraphQLWebSocketIT method
signatures
b9b38b132 is described below
commit b9b38b132944c2294a833cdcb060d093f3e567d4
Author: Serge Huber <[email protected]>
AuthorDate: Fri Sep 4 12:38:18 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, which happens at probe start, before the test's setup has waited for
the
container to finish provisioning. A helper that took a websocket-client
type as
a parameter therefore made every test in the class fail to load whenever the
class ran early, as it does when selected on its own. Build the upgrade
request
inside the helper instead, so the client bundle is only needed once the
tests
actually run.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
---
.../unomi/itests/graphql/GraphQLWebSocketIT.java | 27 +++++++++++++---------
1 file changed, 16 insertions(+), 11 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 4a88b765d..18c4e9c6c 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
@@ -185,36 +185,41 @@ 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, 401);
+ assertWebSocketUpgradeRejected(basicAuthHeader(BASIC_AUTH_USER_NAME,
"definitely-not-the-password"), null, 401);
}
@Test
public void testWebSocketUpgrade_withMalformedBasic_returns401() throws
Exception {
- ClientUpgradeRequest request = new ClientUpgradeRequest();
- request.setHeader("Authorization", "Basic !!!");
- assertWebSocketUpgradeRejected(request, 401);
+ assertWebSocketUpgradeRejected("Basic !!!", null, 401);
}
/** A WebSocket handshake bypasses CORS, so a foreign origin is refused
before anything else. */
@Test
public void testWebSocketUpgrade_fromForeignOrigin_returns403() throws
Exception {
- ClientUpgradeRequest request = new ClientUpgradeRequest();
- request.setHeader("Origin", "http://attacker.example");
- request.setHeader("Authorization",
basicAuthHeader(BASIC_AUTH_USER_NAME, BASIC_AUTH_PASSWORD));
- assertWebSocketUpgradeRejected(request, 403);
+ assertWebSocketUpgradeRejected(basicAuthHeader(BASIC_AUTH_USER_NAME,
BASIC_AUTH_PASSWORD), "http://attacker.example", 403);
}
private URI graphqlWebSocketUri() throws Exception {
return new URI("ws://localhost:" + getHttpPort() + "/graphql");
}
- private void assertWebSocketUpgradeRejected(ClientUpgradeRequest request,
int expectedStatus) 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 assertWebSocketUpgradeRejected(String authorization, String
origin, int expectedStatus) throws Exception {
WebSocketClient client = new WebSocketClient();
Socket socket = new Socket();
try {
client.start();
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ if (authorization != null) {
+ request.setHeader("Authorization", authorization);
+ }
+ if (origin != null) {
+ request.setHeader("Origin", origin);
+ }
Future<Session> onConnected = client.connect(socket,
graphqlWebSocketUri(), request);
try {
onConnected.get(10, TimeUnit.SECONDS);