Skip to content

Commit 060f753

Browse files
committed
fix(#516): add check origin tests
1 parent a938d66 commit 060f753

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package graphql.kickstart.servlet
2+
3+
import spock.lang.Specification
4+
5+
class GraphQLWebsocketServletSpec extends Specification {
6+
7+
def "checkOrigin without any allowed origins allows given origin"() {
8+
given: "a websocket servlet with no allowed origins"
9+
def servlet = new GraphQLWebsocketServlet(GraphQLConfiguration.with(TestUtils.createGraphQlSchema()).build())
10+
11+
when: "we check origin http://localhost:8080"
12+
def allowed = servlet.checkOrigin("http://localhost:8080")
13+
14+
then:
15+
allowed
16+
}
17+
18+
def "checkOrigin without any allowed origins allows when no origin given"() {
19+
given: "a websocket servlet with no allowed origins"
20+
def servlet = new GraphQLWebsocketServlet(GraphQLConfiguration.with(TestUtils.createGraphQlSchema()).build())
21+
22+
when: "we check origin null"
23+
def allowed = servlet.checkOrigin(null)
24+
25+
then:
26+
allowed
27+
}
28+
29+
def "checkOrigin without any allowed origins allows when origin is empty"() {
30+
given: "a websocket servlet with no allowed origins"
31+
def servlet = new GraphQLWebsocketServlet(GraphQLConfiguration.with(TestUtils.createGraphQlSchema()).build())
32+
33+
when: "we check origin null"
34+
def allowed = servlet.checkOrigin(" ")
35+
36+
then:
37+
allowed
38+
}
39+
40+
def "checkOrigin with allow all origins allows given origin"() {
41+
given: "a websocket servlet with allow all origins"
42+
def servlet = new GraphQLWebsocketServlet(GraphQLConfiguration.with(TestUtils.createGraphQlSchema()).allowedOrigins(List.of("*")).build())
43+
44+
when: "we check origin http://localhost:8080"
45+
def allowed = servlet.checkOrigin("http://localhost:8080")
46+
47+
then:
48+
allowed
49+
}
50+
51+
def "checkOrigin with specific allowed origins allows given origin"() {
52+
given: "a websocket servlet with allow all origins"
53+
def servlet = new GraphQLWebsocketServlet(GraphQLConfiguration.with(TestUtils.createGraphQlSchema()).allowedOrigins(List.of("http://localhost:8080")).build())
54+
55+
when: "we check origin http://localhost:8080"
56+
def allowed = servlet.checkOrigin("http://localhost:8080")
57+
58+
then:
59+
allowed
60+
}
61+
62+
def "checkOrigin with specific allowed origins allows given origin with trailing slash"() {
63+
given: "a websocket servlet with allow all origins"
64+
def servlet = new GraphQLWebsocketServlet(GraphQLConfiguration.with(TestUtils.createGraphQlSchema()).allowedOrigins(List.of("http://localhost:8080")).build())
65+
66+
when: "we check origin http://localhost:8080/"
67+
def allowed = servlet.checkOrigin("http://localhost:8080/")
68+
69+
then:
70+
allowed
71+
}
72+
73+
def "checkOrigin with specific allowed origins with trailing slash allows given origin without trailing slash"() {
74+
given: "a websocket servlet with allow all origins"
75+
def servlet = new GraphQLWebsocketServlet(GraphQLConfiguration.with(TestUtils.createGraphQlSchema()).allowedOrigins(List.of("http://localhost:8080/")).build())
76+
77+
when: "we check origin http://localhost:8080"
78+
def allowed = servlet.checkOrigin("http://localhost:8080")
79+
80+
then:
81+
allowed
82+
}
83+
}

0 commit comments

Comments
 (0)