Skip to content

Commit

Permalink
test: test for access-control-request-headers scenario (fastify#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
alemagio committed Aug 1, 2020
1 parent 6a64e8d commit 8e43498
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ test('Should shortcircuits preflight requests', t => {
})
})

test('Should add access-control-allow-headers to response if preflight req has access-control-request-headers', t => {
t.plan(4)

const fastify = Fastify()
fastify.register(cors)

fastify.options('/', (req, reply) => {
t.fail('we should not be here')
})

fastify.inject({
method: 'OPTIONS',
url: '/',
headers: { 'access-control-request-headers': 'x-requested-with' }
}, (err, res) => {
t.error(err)
delete res.headers.date
t.strictEqual(res.statusCode, 204)
t.strictEqual(res.payload, '')
t.match(res.headers, {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
'access-control-allow-headers': 'x-requested-with',
vary: 'Origin, Access-Control-Request-Headers',
'content-length': '0'
})
})
})

test('Should shortcircuits preflight requests with custom status code', t => {
t.plan(4)

Expand Down

0 comments on commit 8e43498

Please sign in to comment.