Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also support --disableCookieValidation when we createResourceRoutes. #975

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/events/http/HttpServer.js
Expand Up @@ -901,8 +901,20 @@ export default class HttpServer {
}

const hapiMethod = method === 'ANY' ? '*' : method

const state = this.#options.disableCookieValidation
? {
failAction: 'ignore',
parse: false,
}
: {
failAction: 'error',
parse: true,
}

const hapiOptions = {
cors: this.#options.corsConfig,
state,
}

// skip HEAD routes as hapi will fail with 'Method name not allowed: HEAD ...'
Expand Down
61 changes: 61 additions & 0 deletions tests/old-unit/offline.test.js
Expand Up @@ -1012,5 +1012,66 @@ describe('Offline', () => {

expect(result.queryString).toHaveProperty('bar', 'baz')
})

describe('disable cookie validation', () => {
test('should return bad request by default if invalid cookies are passed by the request', async () => {
const offline = await new OfflineBuilder(serviceBuilder, {
resourceRoutes: true,
})
.addFunctionConfig('cookie', {
events: [
{
http: {
method: 'GET',
path: 'cookie',
},
},
],
handler: 'tests/old-unit/fixtures/handler.cookie',
})
.toObject()

const res = await offline.inject({
headers: {
Cookie:
'a.strange.cookie.with.newline.at.the.end=yummie123utuiwi-32432fe3-f3e2e32\n',
},
method: 'GET',
url: '/dev/cookie',
})

expect(res.statusCode).toEqual(400)
})

test('should return 200 if the "disableCookieValidation"-flag is set', async () => {
const offline = await new OfflineBuilder(serviceBuilder, {
resourceRoutes: true,
disableCookieValidation: true,
})
.addFunctionConfig('cookie', {
events: [
{
http: {
method: 'GET',
path: 'cookie',
},
},
],
handler: 'tests/old-unit/fixtures/handler.cookie',
})
.toObject()

const res = await offline.inject({
headers: {
Cookie:
'a.strange.cookie.with.newline.at.the.end=yummie123utuiwi-32432fe3-f3e2e32\n',
},
method: 'GET',
url: '/dev/cookie',
})

expect(res.statusCode).toEqual(200)
})
})
})
})