@@ -37,6 +37,35 @@ describe('RestServer (integration)', () => {
37
37
. expect ( 500 ) ;
38
38
} ) ;
39
39
40
+ it ( 'allows cors' , async ( ) => {
41
+ const server = await givenAServer ( { rest : { port : 0 } } ) ;
42
+ server . handler ( ( sequence , request , response ) => {
43
+ response . write ( 'Hello' ) ;
44
+ response . end ( ) ;
45
+ } ) ;
46
+
47
+ await createClientForHandler ( server . handleHttp )
48
+ . get ( '/' )
49
+ . expect ( 200 , 'Hello' )
50
+ . expect ( 'Access-Control-Allow-Origin' , '*' )
51
+ . expect ( 'Access-Control-Allow-Credentials' , 'true' ) ;
52
+ } ) ;
53
+
54
+ it ( 'allows cors preflight' , async ( ) => {
55
+ const server = await givenAServer ( { rest : { port : 0 } } ) ;
56
+ server . handler ( ( sequence , request , response ) => {
57
+ response . write ( 'Hello' ) ;
58
+ response . end ( ) ;
59
+ } ) ;
60
+
61
+ await createClientForHandler ( server . handleHttp )
62
+ . options ( '/' )
63
+ . expect ( 204 )
64
+ . expect ( 'Access-Control-Allow-Origin' , '*' )
65
+ . expect ( 'Access-Control-Allow-Credentials' , 'true' )
66
+ . expect ( 'Access-Control-Max-Age' , '86400' ) ;
67
+ } ) ;
68
+
40
69
it ( 'exposes "GET /openapi.json" endpoint' , async ( ) => {
41
70
const server = await givenAServer ( { rest : { port : 0 } } ) ;
42
71
const greetSpec = {
@@ -75,7 +104,6 @@ describe('RestServer (integration)', () => {
75
104
} ) ;
76
105
expect ( response . get ( 'Access-Control-Allow-Origin' ) ) . to . equal ( '*' ) ;
77
106
expect ( response . get ( 'Access-Control-Allow-Credentials' ) ) . to . equal ( 'true' ) ;
78
- expect ( response . get ( 'Access-Control-Allow-Max-Age' ) ) . to . equal ( '86400' ) ;
79
107
} ) ;
80
108
81
109
it ( 'exposes "GET /openapi.yaml" endpoint' , async ( ) => {
@@ -115,7 +143,6 @@ servers:
115
143
expect ( yaml . safeLoad ( response . text ) ) . to . eql ( expected ) ;
116
144
expect ( response . get ( 'Access-Control-Allow-Origin' ) ) . to . equal ( '*' ) ;
117
145
expect ( response . get ( 'Access-Control-Allow-Credentials' ) ) . to . equal ( 'true' ) ;
118
- expect ( response . get ( 'Access-Control-Allow-Max-Age' ) ) . to . equal ( '86400' ) ;
119
146
} ) ;
120
147
121
148
it ( 'exposes "GET /swagger-ui" endpoint' , async ( ) => {
@@ -145,7 +172,6 @@ servers:
145
172
expect ( response . get ( 'Location' ) ) . match ( url ) ;
146
173
expect ( response . get ( 'Access-Control-Allow-Origin' ) ) . to . equal ( '*' ) ;
147
174
expect ( response . get ( 'Access-Control-Allow-Credentials' ) ) . to . equal ( 'true' ) ;
148
- expect ( response . get ( 'Access-Control-Allow-Max-Age' ) ) . to . equal ( '86400' ) ;
149
175
} ) ;
150
176
151
177
it ( 'exposes "GET /swagger-ui" endpoint with apiExplorerUrl' , async ( ) => {
@@ -177,7 +203,6 @@ servers:
177
203
expect ( response . get ( 'Location' ) ) . match ( url ) ;
178
204
expect ( response . get ( 'Access-Control-Allow-Origin' ) ) . to . equal ( '*' ) ;
179
205
expect ( response . get ( 'Access-Control-Allow-Credentials' ) ) . to . equal ( 'true' ) ;
180
- expect ( response . get ( 'Access-Control-Allow-Max-Age' ) ) . to . equal ( '86400' ) ;
181
206
} ) ;
182
207
183
208
async function givenAServer ( options ?: ApplicationConfig ) {
0 commit comments