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

Commit 0c3be87

Browse files
committed
feat: fix unit tests
1 parent b1b2aba commit 0c3be87

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebsocketAutoConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ public GraphQLWebsocketServlet graphQLWebsocketServlet(
6363
}
6464
keepAliveListener().ifPresent(listeners::add);
6565
return new GraphQLWebsocketServlet(
66-
graphQLInvoker,
67-
invocationInputFactory,
68-
graphQLObjectMapper,
69-
listeners);
66+
graphQLInvoker, invocationInputFactory, graphQLObjectMapper, listeners);
7067
}
7168

7269
private Optional<SubscriptionConnectionListener> keepAliveListener() {
@@ -96,7 +93,10 @@ public WsCsrfTokenRepository wsCsrfTokenRepository() {
9693
public ServerEndpointRegistration serverEndpointRegistration(
9794
GraphQLWebsocketServlet servlet, WsCsrfFilter csrfFilter) {
9895
return new GraphQLWsServerEndpointRegistration(
99-
websocketProperties.getPath(), servlet, csrfFilter);
96+
websocketProperties.getPath(),
97+
servlet,
98+
csrfFilter,
99+
websocketProperties.getAllowedOrigins());
100100
}
101101

102102
@Bean

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWsServerEndpointRegistration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ public class GraphQLWsServerEndpointRegistration extends ServerEndpointRegistrat
1818
private static final String ALL = "*";
1919
private final GraphQLWebsocketServlet servlet;
2020
private final WsCsrfFilter csrfFilter;
21+
private final List<String> allowedOrigins;
2122

2223
public GraphQLWsServerEndpointRegistration(
23-
String path, GraphQLWebsocketServlet servlet, WsCsrfFilter csrfFilter, List<String> allowedOrigins) {
24+
String path,
25+
GraphQLWebsocketServlet servlet,
26+
WsCsrfFilter csrfFilter,
27+
List<String> allowedOrigins) {
2428
super(path, servlet);
2529
this.servlet = servlet;
2630
if (allowedOrigins == null || allowedOrigins.isEmpty()) {

graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWsServerEndpointRegistrationTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,36 @@ class GraphQLWsServerEndpointRegistrationTest {
1616
private static final String PATH = "/subscriptions";
1717

1818
@Mock private GraphQLWebsocketServlet servlet;
19+
@Mock private WsCsrfFilter csrfFilter;
1920

2021
@ParameterizedTest
21-
@CsvSource(value = {"https://trusted.com", "NULL", "' '"}, nullValues = {"NULL"})
22+
@CsvSource(
23+
value = {"https://trusted.com", "NULL", "' '"},
24+
nullValues = {"NULL"})
2225
void givenDefaultAllowedOrigins_whenCheckOrigin_thenReturnTrue(String origin) {
2326
var registration = createRegistration();
2427
var allowed = registration.checkOrigin("null".equals(origin) ? null : origin);
2528
assertThat(allowed).isTrue();
2629
}
2730

2831
private GraphQLWsServerEndpointRegistration createRegistration(String... allowedOrigins) {
29-
return new GraphQLWsServerEndpointRegistration(PATH, servlet, List.of(allowedOrigins));
32+
return new GraphQLWsServerEndpointRegistration(
33+
PATH, servlet, csrfFilter, List.of(allowedOrigins));
3034
}
3135

3236
@ParameterizedTest(name = "{index} => allowedOrigin=''{0}'', originToCheck=''{1}''")
33-
@CsvSource(delimiterString = "|", textBlock = """
37+
@CsvSource(
38+
delimiterString = "|",
39+
textBlock =
40+
"""
3441
* | https://trusted.com
3542
https://trusted.com | https://trusted.com
3643
https://trusted.com/ | https://trusted.com
3744
https://trusted.com/ | https://trusted.com/
3845
https://trusted.com | https://trusted.com/
3946
""")
40-
void givenAllowedOrigins_whenCheckOrigin_thenReturnTrue(String allowedOrigin, String originToCheck) {
47+
void givenAllowedOrigins_whenCheckOrigin_thenReturnTrue(
48+
String allowedOrigin, String originToCheck) {
4149
var registration = createRegistration(allowedOrigin);
4250
var allowed = registration.checkOrigin(originToCheck);
4351
assertThat(allowed).isTrue();

graphql-spring-boot-test/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818
*/
1919
dependencies {
20+
compileOnly 'jakarta.servlet:jakarta.servlet-api:6.0.0'
21+
compileOnly 'jakarta.websocket:jakarta.websocket-api:2.1.0'
22+
compileOnly 'jakarta.websocket:jakarta.websocket-client-api:2.1.0'
2023
implementation "org.springframework:spring-web"
2124
implementation "org.springframework.boot:spring-boot-starter-test"
2225
implementation "com.fasterxml.jackson.core:jackson-databind"
@@ -27,4 +30,5 @@ dependencies {
2730
testImplementation "org.springframework.boot:spring-boot-starter-websocket"
2831
testImplementation project(":graphql-spring-boot-starter")
2932
testImplementation "io.reactivex.rxjava2:rxjava:2.2.21"
33+
3034
}

0 commit comments

Comments
 (0)