Skip to content

Commit

Permalink
Fix authorization and aws set-cookie (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhostVlad authored Nov 21, 2018
1 parent a13bd12 commit 12eac8b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 2,012 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"homepage": "https://github.com/reimagined/resolve/tree/master/packages/adapters/api-handler-adapters/resolve-api-handler-awslambda#readme",
"dependencies": {
"@babel/runtime": "^7.0.0",
"binary-case": "1.1.4",
"content-disposition": "0.5.2",
"cookie": "0.3.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import binaryCase from 'binary-case'
import contentDisposition from 'content-disposition'
import cookie from 'cookie'

Expand Down Expand Up @@ -87,6 +88,7 @@ const createResponse = () => {
const internalRes = {
status: 200,
headers: {},
cookies: [],
body: '',
closed: false
}
Expand Down Expand Up @@ -125,14 +127,7 @@ const createResponse = () => {
validateResponseOpened()
const serializedCookie = cookie.serialize(name, value, options)

let cookieHeader = internalRes.headers['Set-Cookie']
if (cookieHeader != null) {
cookieHeader = `${cookieHeader}, ${serializedCookie}`
} else {
cookieHeader = serializedCookie
}

internalRes.headers['Set-Cookie'] = cookieHeader
internalRes.cookies.push(serializedCookie)
})

defineResponseMethod('clearCookie', (name, options) => {
Expand All @@ -142,14 +137,7 @@ const createResponse = () => {
expire: COOKIE_CLEAR_DATE
})

let cookieHeader = internalRes.headers['Set-Cookie']
if (cookieHeader != null) {
cookieHeader = `${cookieHeader}, ${serializedCookie}`
} else {
cookieHeader = serializedCookie
}

internalRes.headers['Set-Cookie'] = cookieHeader
internalRes.cookies.push(serializedCookie)
})

defineResponseMethod('status', code => {
Expand Down Expand Up @@ -238,9 +226,15 @@ const wrapApiHandler = (handler, getCustomParameters) => async (

await handler(req, res)

const { status: statusCode, headers, body: bodyBuffer } = res[INTERNAL]
const { status: statusCode, headers, cookies, body: bodyBuffer } = res[
INTERNAL
]
const body = bodyBuffer.toString()

for (let idx = 0; idx < cookies.length; idx++) {
headers[binaryCase('Set-cookie', idx)] = cookies[idx]
}

result = { statusCode, headers, body }
} catch (error) {
const outError =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
Object {
"args": Array [
"null",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
],
"returnValue": "undefined",
},
Expand Down Expand Up @@ -69,7 +69,7 @@ Object {
Object {
"args": Array [
"null",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\",\\"Content-Disposition\\":\\"attachment; filename=\\\\\\"synthetic-filename.txt\\\\\\"\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Content-Disposition\\":\\"attachment; filename=\\\\\\"synthetic-filename.txt\\\\\\"\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
],
"returnValue": "undefined",
},
Expand Down Expand Up @@ -100,7 +100,7 @@ Object {
Object {
"args": Array [
"null",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
],
"returnValue": "undefined",
},
Expand Down Expand Up @@ -131,7 +131,7 @@ Object {
Object {
"args": Array [
"null",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
],
"returnValue": "undefined",
},
Expand Down Expand Up @@ -193,7 +193,7 @@ Object {
Object {
"args": Array [
"null",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
"{\\"statusCode\\":200,\\"headers\\":{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"},\\"body\\":\\"{\\\\\\"adapter\\\\\\":\\\\\\"awslambda\\\\\\",\\\\\\"method\\\\\\":\\\\\\"GET\\\\\\",\\\\\\"query\\\\\\":{\\\\\\"query-name-1\\\\\\":\\\\\\"query-value-1\\\\\\",\\\\\\"query-name-2\\\\\\":\\\\\\"query-value-2\\\\\\"},\\\\\\"path\\\\\\":\\\\\\"PATH_INFO\\\\\\",\\\\\\"headers\\\\\\":{\\\\\\"Header-Name-1\\\\\\":\\\\\\"header-value-1\\\\\\",\\\\\\"Header-Name-2\\\\\\":\\\\\\"header-value-2\\\\\\",\\\\\\"Cookie\\\\\\":\\\\\\"cookie-content\\\\\\",\\\\\\"Host\\\\\\":\\\\\\"host-content\\\\\\"},\\\\\\"cookies\\\\\\":{},\\\\\\"body\\\\\\":\\\\\\"BODY_CONTENT\\\\\\",\\\\\\"param\\\\\\":\\\\\\"value\\\\\\",\\\\\\"existingHeader\\\\\\":\\\\\\"Two-Header-Value\\\\\\"}\\"}",
],
"returnValue": "undefined",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"homepage": "https://github.com/reimagined/resolve/tree/master/packages/adapters/api-handler-adapters/resolve-api-handler-express#readme",
"dependencies": {
"@babel/runtime": "^7.0.0",
"binary-case": "1.1.4",
"content-disposition": "0.5.2",
"cookie": "0.3.1",
"raw-body": "2.3.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import binaryCase from 'binary-case'
import contentDisposition from 'content-disposition'
import cookie from 'cookie'
import getRawBody from 'raw-body'
Expand Down Expand Up @@ -93,6 +94,7 @@ const createResponse = () => {
const internalRes = {
status: 200,
headers: {},
cookies: [],
body: '',
closed: false
}
Expand Down Expand Up @@ -131,14 +133,7 @@ const createResponse = () => {
validateResponseOpened()
const serializedCookie = cookie.serialize(name, value, options)

let cookieHeader = internalRes.headers['Set-Cookie']
if (cookieHeader != null) {
cookieHeader = `${cookieHeader}, ${serializedCookie}`
} else {
cookieHeader = serializedCookie
}

internalRes.headers['Set-Cookie'] = cookieHeader
internalRes.cookies.push(serializedCookie)
})

defineResponseMethod('clearCookie', (name, options) => {
Expand All @@ -148,14 +143,7 @@ const createResponse = () => {
expire: COOKIE_CLEAR_DATE
})

let cookieHeader = internalRes.headers['Set-Cookie']
if (cookieHeader != null) {
cookieHeader = `${cookieHeader}, ${serializedCookie}`
} else {
cookieHeader = serializedCookie
}

internalRes.headers['Set-Cookie'] = cookieHeader
internalRes.cookies.push(serializedCookie)
})

defineResponseMethod('status', code => {
Expand Down Expand Up @@ -242,9 +230,13 @@ const wrapApiHandler = (handler, getCustomParameters) => async (

await handler(req, res)

const { status, headers, body } = res[INTERNAL]
const { status, headers, cookies, body } = res[INTERNAL]
expressRes.status(status)

for (let idx = 0; idx < cookies.length; idx++) {
headers[binaryCase('Set-cookie', idx)] = cookies[idx]
}

expressRes.set(headers)

expressRes.end(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Object {
"callsInfo": Array [
Object {
"args": Array [
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"}",
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"}",
],
"returnValue": "{}",
},
Expand Down Expand Up @@ -148,7 +148,7 @@ Object {
"callsInfo": Array [
Object {
"args": Array [
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\",\\"Content-Disposition\\":\\"attachment; filename=\\\\\\"synthetic-filename.txt\\\\\\"\\"}",
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Content-Disposition\\":\\"attachment; filename=\\\\\\"synthetic-filename.txt\\\\\\"\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"}",
],
"returnValue": "{}",
},
Expand Down Expand Up @@ -212,7 +212,7 @@ Object {
"callsInfo": Array [
Object {
"args": Array [
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"}",
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"}",
],
"returnValue": "{}",
},
Expand Down Expand Up @@ -276,7 +276,7 @@ Object {
"callsInfo": Array [
Object {
"args": Array [
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"}",
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"}",
],
"returnValue": "{}",
},
Expand Down Expand Up @@ -397,7 +397,7 @@ Object {
"callsInfo": Array [
Object {
"args": Array [
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-Cookie\\":\\"One-Cookie-Name=One-Cookie-Value, Two-Cookie-Name=Two-Cookie-Value, Two-Cookie-Name=\\"}",
"{\\"One-Header-Name\\":\\"One-Header-Value\\",\\"Two-Header-Name\\":\\"Two-Header-Value\\",\\"Set-cookie\\":\\"One-Cookie-Name=One-Cookie-Value\\",\\"set-cookie\\":\\"Two-Cookie-Name=Two-Cookie-Value\\",\\"SEt-cookie\\":\\"Two-Cookie-Name=\\"}",
],
"returnValue": "{}",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const apiHandlerConstructor = (
await sendAuthResponse(authResponse, res, authRequest.resolve.rootPath)
} catch (error) {
res.status(504)
res.end(String(error.stack))

const outError =
error != null && error.stack != null
? `${error.stack}`
: `Unknown error ${error}`

res.end(outError)
}
}

Expand Down
31 changes: 25 additions & 6 deletions packages/modules/resolve-module-auth/src/wrap_auth_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,33 @@ const wrapDefaultJwt = (executor, defaultJwtToken) => async ({
const wrapAuthRequest = req => {
const jwtToken = req.cookies[req.resolve.jwtCookie.name]

const authRequest = {
...req,
const authRequest = Object.create(req, {
resolve: {
...req.resolve,
executeCommand: wrapDefaultJwt(req.resolve.executeCommand, jwtToken),
executeQuery: wrapDefaultJwt(req.resolve.executeQuery, jwtToken)
value: Object.create(req.resolve, {
executeCommand: {
value: wrapDefaultJwt(req.resolve.executeCommand, jwtToken),
enumerable: true,
configurable: true,
writable: true
},
executeQuery: {
value: wrapDefaultJwt(req.resolve.executeQuery, jwtToken),
enumerable: true,
configurable: true,
writable: true
}
}),
enumerable: true,
configurable: true,
writable: true
},
body: {
value: null,
enumerable: true,
configurable: true,
writable: true
}
}
})

// TODO: use string-based body parsers (not stream-based like npm body-parser)
if (req.body != null && req.headers['content-type'] != null) {
Expand Down
Loading

0 comments on commit 12eac8b

Please sign in to comment.