-
-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support authorizer with no identity source specified (#1639)
- Loading branch information
1 parent
84e07f6
commit 43aaa2e
Showing
7 changed files
with
167 additions
and
29 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
54 changes: 54 additions & 0 deletions
54
tests/integration/no-identity-source-authorizer/no-identity-source-authorizer.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import assert from 'node:assert' | ||
import { dirname, resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { BASE_URL } from '../../config.js' | ||
import { setup, teardown } from '../../_testHelpers/index.js' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
describe('no identity source authorizer tests', function desc() { | ||
beforeEach(() => | ||
setup({ | ||
servicePath: resolve(__dirname), | ||
}), | ||
) | ||
|
||
afterEach(() => teardown()) | ||
|
||
// | ||
;[ | ||
{ | ||
description: 'should respond with 200', | ||
expected: { | ||
message: 'hello', | ||
}, | ||
options: { | ||
headers: { | ||
Authorization: 'Bearer 4674cc54-bd05-11e7-abc4-cec278b6b50a', | ||
}, | ||
}, | ||
path: '/dev/hello', | ||
status: 200, | ||
}, | ||
|
||
{ | ||
description: | ||
'should respond with 200 if request has no authorization header', | ||
expected: { | ||
message: 'hello', | ||
}, | ||
path: '/dev/hello', | ||
status: 200, | ||
}, | ||
].forEach(({ description, expected, options, path, status }) => { | ||
it(description, async () => { | ||
const url = new URL(path, BASE_URL) | ||
|
||
const response = await fetch(url, options) | ||
assert.equal(response.status, status) | ||
|
||
const json = await response.json() | ||
assert.deepEqual(json, expected) | ||
}) | ||
}) | ||
}) |
32 changes: 32 additions & 0 deletions
32
tests/integration/no-identity-source-authorizer/serverless.yml
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,32 @@ | ||
service: no-identity-source-authorizer | ||
|
||
configValidationMode: error | ||
deprecationNotificationMode: error | ||
|
||
plugins: | ||
- ../../../src/index.js | ||
|
||
provider: | ||
architecture: arm64 | ||
deploymentMethod: direct | ||
memorySize: 1024 | ||
name: aws | ||
region: us-east-1 | ||
runtime: nodejs18.x | ||
stage: dev | ||
versionFunctions: false | ||
|
||
functions: | ||
hello: | ||
events: | ||
- http: | ||
authorizer: | ||
name: authorizer | ||
resultTtlInSeconds: 0 | ||
type: request | ||
method: get | ||
path: hello | ||
handler: src/handler.hello | ||
|
||
authorizer: | ||
handler: src/authorizer.authorizer |
15 changes: 15 additions & 0 deletions
15
tests/integration/no-identity-source-authorizer/src/authorizer.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export async function authorizer(event) { | ||
return { | ||
policyDocument: { | ||
Statement: [ | ||
{ | ||
Action: 'execute-api:Invoke', | ||
Effect: 'Allow', | ||
Resource: event.methodArn, | ||
}, | ||
], | ||
Version: '2012-10-17', | ||
}, | ||
principalId: 'user', | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/integration/no-identity-source-authorizer/src/handler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { stringify } = JSON | ||
|
||
export async function hello() { | ||
return { | ||
body: stringify({ message: 'hello' }), | ||
statusCode: 200, | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/integration/no-identity-source-authorizer/src/package.json
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,3 @@ | ||
{ | ||
"type": "module" | ||
} |