Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Possibility to add authorization headers to the GraphQLTestSubscription #919

Closed as not planned
@maxkramer

Description

@maxkramer

Describe the bug
Hi all, I'm getting the following error when attempting to create a subscription to one of our endpoints, which is protected by OAuth2. The exception makes sense, however I'm unable to find a way to attach the token as a header to the connection that's being made.

I can see that headers can be added through the TestWebSocketClientConfigurator, but no way to add custom headers to it, neither switch it out for a different implementation. Is there something I'm missing on the session that would allow this?

Caused by: javax.websocket.DeploymentException: Failed to handle HTTP response code [401]. Unsupported Authentication scheme [Bearer] returned in response
	at app//org.apache.tomcat.websocket.WsWebSocketContainer.processAuthenticationChallenge(WsWebSocketContainer.java:524)
	at app//org.apache.tomcat.websocket.WsWebSocketContainer.connectToServerRecursive(WsWebSocketContainer.java:396)
	at app//org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:185)
	at app//com.graphql.spring.boot.test.GraphQLTestSubscription.initClient(GraphQLTestSubscription.java:532)
	at app//com.graphql.spring.boot.test.GraphQLTestSubscription.init(GraphQLTestSubscription.java:105)

To Reproduce
Steps to reproduce the behavior:

  1. Create an subscription resolver protected by isAuthorized()
  2. Attempt to fetch data from this endpoint in a test:
graphQLTestSubscription
            .init("some-subscription.graphql")
            .awaitAndGetAllResponses(Duration.ofSeconds(1))

Expected behavior
It should take into account @MockUser or ideally allow setting custom headers especially for authentication. GraphQLTestTemplate specifically has graphQLTestTemplate.withBearerAuth().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions