Skip to content

Commit

Permalink
Merge pull request #980 from danilofuchs/fix/resource-path
Browse files Browse the repository at this point in the history
fix: resourcePath in authorizers should contain wildcards
  • Loading branch information
chardos committed Jun 4, 2020
2 parents b5b8f1f + efc4866 commit bf2a48d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
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

0 comments on commit bf2a48d

Please sign in to comment.