@@ -32,9 +32,23 @@ describe('cors', () => {
32
32
}
33
33
} , { ipfs, cors : { origin : [ origin ] } } )
34
34
35
+ expect ( res ) . to . have . property ( 'statusCode' , 200 )
35
36
expect ( res ) . to . have . nested . property ( 'headers.access-control-allow-origin' , origin )
36
37
} )
37
38
39
+ it ( 'allows request when referer is supplied in request' , async ( ) => {
40
+ const origin = 'http://localhost:8080'
41
+ const res = await http ( {
42
+ method : 'POST' ,
43
+ url : '/api/v0/id' ,
44
+ headers : {
45
+ referer : origin + '/index.html'
46
+ }
47
+ } , { ipfs, cors : { origin : [ origin ] } } )
48
+
49
+ expect ( res ) . to . have . property ( 'statusCode' , 200 )
50
+ } )
51
+
38
52
it ( 'does not allow credentials when omitted in config' , async ( ) => {
39
53
const origin = 'http://localhost:8080'
40
54
const res = await http ( {
@@ -149,5 +163,102 @@ describe('cors', () => {
149
163
150
164
expect ( res ) . to . have . property ( 'statusCode' , 404 )
151
165
} )
166
+
167
+ it ( 'rejects requests when cors origin list is empty and origin is sent' , async ( ) => {
168
+ const origin = 'http://localhost:8080'
169
+ const res = await http ( {
170
+ method : 'POST' ,
171
+ url : '/api/v0/id' ,
172
+ headers : {
173
+ origin
174
+ }
175
+ } , {
176
+ ipfs,
177
+ cors : { origin : [ ] }
178
+ } )
179
+
180
+ expect ( res ) . to . have . property ( 'statusCode' , 403 )
181
+ } )
182
+
183
+ it ( 'rejects requests when cors origin list is empty and referer is sent' , async ( ) => {
184
+ const referer = 'http://localhost:8080/index.html'
185
+ const res = await http ( {
186
+ method : 'POST' ,
187
+ url : '/api/v0/id' ,
188
+ headers : {
189
+ referer
190
+ }
191
+ } , {
192
+ ipfs,
193
+ cors : { origin : [ ] }
194
+ } )
195
+
196
+ expect ( res ) . to . have . property ( 'statusCode' , 403 )
197
+ } )
198
+
199
+ it ( 'rejects requests when cors origin list is empty and referer and origin are sent' , async ( ) => {
200
+ const referer = 'http://localhost:8080/index.html'
201
+ const res = await http ( {
202
+ method : 'POST' ,
203
+ url : '/api/v0/id' ,
204
+ headers : {
205
+ referer,
206
+ origin : 'http://localhost:8080'
207
+ }
208
+ } , {
209
+ ipfs,
210
+ cors : { origin : [ ] }
211
+ } )
212
+
213
+ expect ( res ) . to . have . property ( 'statusCode' , 403 )
214
+ } )
215
+
216
+ it ( 'rejects requests when cors origin list is empty and origin is sent as "null" (e.g. data urls and sandboxed iframes)' , async ( ) => {
217
+ const origin = 'null'
218
+ const res = await http ( {
219
+ method : 'POST' ,
220
+ url : '/api/v0/id' ,
221
+ headers : {
222
+ origin
223
+ }
224
+ } , {
225
+ ipfs,
226
+ cors : { origin : [ ] }
227
+ } )
228
+
229
+ expect ( res ) . to . have . property ( 'statusCode' , 403 )
230
+ } )
231
+
232
+ it ( 'rejects requests when cors origin list does not contain the correct origin and origin is sent' , async ( ) => {
233
+ const origin = 'http://localhost:8080'
234
+ const res = await http ( {
235
+ method : 'POST' ,
236
+ url : '/api/v0/id' ,
237
+ headers : {
238
+ origin
239
+ }
240
+ } , {
241
+ ipfs,
242
+ cors : { origin : [ 'http://example.com:8080' ] }
243
+ } )
244
+
245
+ expect ( res ) . to . have . property ( 'statusCode' , 403 )
246
+ } )
247
+
248
+ it ( 'rejects requests when cors origin list does not contain the correct origin and referer is sent' , async ( ) => {
249
+ const referer = 'http://localhost:8080/index.html'
250
+ const res = await http ( {
251
+ method : 'POST' ,
252
+ url : '/api/v0/id' ,
253
+ headers : {
254
+ referer
255
+ }
256
+ } , {
257
+ ipfs,
258
+ cors : { origin : [ 'http://example.com:8080' ] }
259
+ } )
260
+
261
+ expect ( res ) . to . have . property ( 'statusCode' , 403 )
262
+ } )
152
263
} )
153
264
} )
0 commit comments