-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly identify scopes for paths containing arguments (#57)
- Loading branch information
Showing
12 changed files
with
312 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ cdk.context.json | |
|
||
!src/lambda/route1.js | ||
!src/lambda/route2.js | ||
!src/lambda/route3.js | ||
!src/lambda/route4.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Route { | ||
constructor(event) { | ||
this.event = event; | ||
} | ||
|
||
async handle() { | ||
console.log("Route 3 processing event."); | ||
|
||
return { | ||
statusCode: 200, | ||
headers: {}, | ||
body: "route 3", | ||
}; | ||
} | ||
} | ||
|
||
module.exports.route = async (event) => { | ||
const route = new Route(event); | ||
return await route.handle(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Route { | ||
constructor(event) { | ||
this.event = event; | ||
} | ||
|
||
async handle() { | ||
console.log("Route 4 processing event."); | ||
|
||
return { | ||
statusCode: 200, | ||
headers: {}, | ||
body: "route 4", | ||
}; | ||
} | ||
} | ||
|
||
module.exports.route = async (event) => { | ||
const route = new Route(event); | ||
return await route.handle(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
import { PersonaClient } from "talis-node"; | ||
declare type ParsedArn = { | ||
method: string; | ||
resourcePath: string; | ||
apiOptions: { | ||
region: string; | ||
restApiId: string; | ||
stage: string; | ||
}; | ||
awsAccountId: string; | ||
}; | ||
export declare class PersonaAuthorizer { | ||
event: any; | ||
context: any; | ||
personaClient: PersonaClient | undefined; | ||
constructor(event: any, context: any); | ||
handle(): Promise<any>; | ||
validateToken(validationOpts: any): Promise<Record<string, any>>; | ||
/** | ||
* Break down an API gateway method ARN into it's constituent parts. | ||
* Method ARNs take the following format: | ||
* | ||
* arn:aws:execute-api:<Region id>:<Account id>:<API id>/<Stage>/<Method>/<Resource path> | ||
* | ||
* e.g: | ||
* | ||
* arn:aws:execute-api:eu-west-1:123:abc/development/GET/2/works | ||
* | ||
* @param methodArn {string} The method ARN provided by the event handed to a Lambda function | ||
* @returns {{ | ||
* method: string, | ||
* resourcePath: string, | ||
* apiOptions: { | ||
* region: string, | ||
* restApiId: string, | ||
* stage: string | ||
* }, | ||
* awsAccountId: string | ||
* }} | ||
*/ | ||
parseMethodArn(methodArn: string): ParsedArn; | ||
getScope(parsedMethodArn: ParsedArn): any; | ||
getPersonaClient(): PersonaClient; | ||
pathMatch(pathDefinition: string, path: string): boolean; | ||
} | ||
export {}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { PersonaAuthorizer } from "../../../../src/lambda/api/authorizer"; | ||
|
||
describe("authorizer", () => { | ||
describe("pathMatch", () => { | ||
const pathMatchTests = [ | ||
{ | ||
title: "matches simple paths", | ||
pathDefinition: "/1/route1", | ||
path: "/1/route1", | ||
expectedResult: true, | ||
}, | ||
{ | ||
title: "does not match different simple paths", | ||
pathDefinition: "/1/route1", | ||
path: "/1/route2", | ||
expectedResult: false, | ||
}, | ||
{ | ||
title: "matches long paths", | ||
pathDefinition: "/1/a/b/route1", | ||
path: "/1/a/b/route1", | ||
expectedResult: true, | ||
}, | ||
{ | ||
title: "matches paths terminated by argument", | ||
pathDefinition: "/1/route1/{id}", | ||
path: "/1/route1/test_id", | ||
expectedResult: true, | ||
}, | ||
{ | ||
title: "does not matche paths when argument incorrect syntax", | ||
pathDefinition: "/1/route1/:id", | ||
path: "/1/route1/test_id", | ||
expectedResult: false, | ||
}, | ||
{ | ||
title: "matches paths containing an argument", | ||
pathDefinition: "/1/a/{id}/route1", | ||
path: "/1/a/test_id/route1", | ||
expectedResult: true, | ||
}, | ||
{ | ||
title: "does not match when number of segments don't match", | ||
pathDefinition: "/a/b/route1", | ||
path: "/a/b/c/route1", | ||
expectedResult: false, | ||
}, | ||
]; | ||
pathMatchTests.forEach((testSpec) => { | ||
test(`${testSpec.title}`, async () => { | ||
const authorizer = new PersonaAuthorizer(null, null); | ||
expect( | ||
authorizer.pathMatch(testSpec.pathDefinition, testSpec.path) | ||
).toBe(testSpec.expectedResult); | ||
}); | ||
}); | ||
}); | ||
}); |