Skip to content

Commit 0f93883

Browse files
climba03003mcollina
authored andcommitted
test: ensure no regression
1 parent 6448dc9 commit 0f93883

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/preflight.test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,76 @@ test('Can override preflight response with preflightContinue', t => {
360360
})
361361
})
362362
})
363+
364+
test('Should support ongoing prefix ', t => {
365+
t.plan(12)
366+
367+
const fastify = Fastify()
368+
369+
fastify.register(async (instance) => {
370+
instance.register(cors)
371+
}, { prefix: '/prefix' })
372+
373+
// support prefixed route
374+
fastify.inject({
375+
method: 'OPTIONS',
376+
url: '/prefix',
377+
headers: {
378+
'access-control-request-method': 'GET',
379+
origin: 'example.com'
380+
}
381+
}, (err, res) => {
382+
t.error(err)
383+
delete res.headers.date
384+
t.equal(res.statusCode, 204)
385+
t.equal(res.payload, '')
386+
t.match(res.headers, {
387+
'access-control-allow-origin': '*',
388+
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
389+
vary: 'Origin, Access-Control-Request-Headers',
390+
'content-length': '0'
391+
})
392+
})
393+
394+
// support prefixed route without / continue
395+
fastify.inject({
396+
method: 'OPTIONS',
397+
url: '/prefixfoo',
398+
headers: {
399+
'access-control-request-method': 'GET',
400+
origin: 'example.com'
401+
}
402+
}, (err, res) => {
403+
t.error(err)
404+
delete res.headers.date
405+
t.equal(res.statusCode, 204)
406+
t.equal(res.payload, '')
407+
t.match(res.headers, {
408+
'access-control-allow-origin': '*',
409+
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
410+
vary: 'Origin, Access-Control-Request-Headers',
411+
'content-length': '0'
412+
})
413+
})
414+
415+
// support prefixed route with / continue
416+
fastify.inject({
417+
method: 'OPTIONS',
418+
url: '/prefix/foo',
419+
headers: {
420+
'access-control-request-method': 'GET',
421+
origin: 'example.com'
422+
}
423+
}, (err, res) => {
424+
t.error(err)
425+
delete res.headers.date
426+
t.equal(res.statusCode, 204)
427+
t.equal(res.payload, '')
428+
t.match(res.headers, {
429+
'access-control-allow-origin': '*',
430+
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
431+
vary: 'Origin, Access-Control-Request-Headers',
432+
'content-length': '0'
433+
})
434+
})
435+
})

0 commit comments

Comments
 (0)