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

fix: resourcePath in authorizers should contain wildcards #980

Merged
merged 3 commits into from Jun 4, 2020
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
4 changes: 3 additions & 1 deletion src/events/http/createAuthScheme.js
Expand Up @@ -44,7 +44,7 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
const accountId = 'random-account-id'
const apiId = 'random-api-id'
const httpMethod = request.method.toUpperCase()
const resourcePath = request.path.replace(
const resourcePath = request.route.path.replace(
new RegExp(`^/${provider.stage}`),
'',
)
Expand All @@ -59,8 +59,10 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
requestId: 'random-request-id',
resourceId: 'random-resource-id',
resourcePath,
path: request.path,
stage: provider.stage,
},
resource: resourcePath,
}

// Create event Object for authFunction
Expand Down
Expand Up @@ -186,7 +186,7 @@ export default class LambdaProxyIntegrationEvent {
resourcePath: route.path,
stage: this.#stage,
},
resource: this.#path,
resource: route.path,
stageVariables: this.#stageVariables,
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/handler/handler.js
Expand Up @@ -202,3 +202,10 @@ exports.TestPathVariable = (event, context, callback) => {
body: stringify(event.path),
})
}

exports.TestResourceVariable = (event, context, callback) => {
callback(null, {
statusCode: 200,
body: stringify(event.resource),
})
}
7 changes: 7 additions & 0 deletions tests/integration/handler/handlerPayload.test.js
Expand Up @@ -301,6 +301,13 @@ describe('handler payload tests with prepend off', () => {
path: '/test-path-variable-handler',
status: 200,
},

{
description: 'event.resource should not contain wildcards',
expected: '/{id}/test-resource-variable-handler',
path: '/1/test-resource-variable-handler',
status: 200,
},
].forEach(({ description, expected, path, status }) => {
test(description, async () => {
const url = joinUrl(TEST_BASE_URL, path)
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/handler/serverless.yml
Expand Up @@ -155,3 +155,10 @@ functions:
method: get
path: test-path-variable-handler
handler: handler.TestPathVariable

TestResourceVariable:
events:
- http:
method: get
path: /{id}/test-resource-variable-handler
handler: handler.TestResourceVariable