Skip to content

Commit 3df6a24

Browse files
committed
#109 Add testcase for whitelisted errors
1 parent ee2ad0d commit 3df6a24

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

test/headers.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
const expect = require('chai').expect // Assertion library
44

55
// Init API instance
6-
const api = require('../index')({ version: 'v1.0' })
6+
7+
const api = require('../index')({
8+
version: 'v1.0',
9+
errorHeaderWhitelist: [
10+
'Access-Control-Allow-Origin',
11+
'Access-Control-Allow-Methods',
12+
]
13+
})
714

815
let event = {
916
httpMethod: 'get',
@@ -93,6 +100,13 @@ api.get('/removeHeader', function(req,res) {
93100
})
94101
})
95102

103+
api.get('/whitelistHeaders', function(req,res) {
104+
res.status(200).header('TestStrippedHeader', 'RemoveMe')
105+
res.status(200).header('access-control-allow-methods', ['GET, OPTIONS'])
106+
res.status(200).header('access-control-allow-origin', ['example.com'])
107+
throw new Error('TestError')
108+
})
109+
96110
api.get('/cors', function(req,res) {
97111
res.cors().json({})
98112
})
@@ -244,6 +258,20 @@ describe('Header Tests:', function() {
244258
})
245259
}) // end it
246260

261+
it('Pass whitelisted headers on error', async function() {
262+
let _event = Object.assign({},event,{ path: '/whitelistHeaders'})
263+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
264+
expect(result).to.deep.equal({
265+
multiValueHeaders: {
266+
'content-type': ['application/json'],
267+
'access-control-allow-methods': ['GET, OPTIONS'],
268+
'access-control-allow-origin': ['example.com'],
269+
}, statusCode: 500,
270+
body: '{"error":"TestError"}',
271+
isBase64Encoded: false
272+
})
273+
}) // end it
274+
247275
}) // end Standard tests
248276

249277
describe('CORS Tests:', function() {

0 commit comments

Comments
 (0)