-
-
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.
feat: Support injection of custom authentication strategy (#1314)
- Loading branch information
1 parent
a5158a4
commit febfe77
Showing
7 changed files
with
158 additions
and
5 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
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
37 changes: 37 additions & 0 deletions
37
tests/integration/custom-authentication/authenticationCustomVariable.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,37 @@ | ||
import fetch from 'node-fetch' | ||
import { resolve } from 'path' | ||
import { joinUrl, setup, teardown } from '../_testHelpers/index.js' | ||
|
||
jest.setTimeout(30000) | ||
|
||
describe('custom authentication serverless-offline variable tests', () => { | ||
// init | ||
beforeAll(() => | ||
setup({ | ||
servicePath: resolve(__dirname), | ||
}), | ||
) | ||
|
||
// cleanup | ||
afterAll(() => teardown()) | ||
|
||
// | ||
;[ | ||
{ | ||
description: | ||
'should return custom payload from injected authentication provider', | ||
path: '/echo', | ||
status: 200, | ||
}, | ||
].forEach(({ description, path, status }) => { | ||
test(description, async () => { | ||
const url = joinUrl(TEST_BASE_URL, path) | ||
|
||
const response = await fetch(url) | ||
expect(response.status).toEqual(status) | ||
|
||
const json = await response.json() | ||
expect(json.event.requestContext.authorizer.expected).toEqual('it works') | ||
}) | ||
}) | ||
}) |
18 changes: 18 additions & 0 deletions
18
tests/integration/custom-authentication/authenticationProvider.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,18 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
module.exports = (endpoint, functionKey, method, path) => { | ||
return { | ||
name: 'strategy-name', | ||
scheme: 'scheme', | ||
|
||
getAuthenticateFunction: () => ({ | ||
async authenticate(request, h) { | ||
const context = { expected: 'it works' } | ||
return h.authenticated({ | ||
credentials: { | ||
context, | ||
}, | ||
}) | ||
}, | ||
}), | ||
} | ||
} |
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 @@ | ||
'use strict' | ||
|
||
const { stringify } = JSON | ||
|
||
exports.echo = async function echo(event, context) { | ||
const data = { event, context } | ||
return stringify(data) | ||
} |
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,24 @@ | ||
service: integration-tests | ||
|
||
custom: | ||
offline: | ||
customAuthenticationProvider: './authenticationProvider' | ||
|
||
plugins: | ||
- ../../../ | ||
|
||
provider: | ||
memorySize: 128 | ||
name: aws | ||
region: us-east-1 # default | ||
runtime: nodejs12.x | ||
stage: dev | ||
versionFunctions: false | ||
|
||
functions: | ||
echo: | ||
events: | ||
- httpApi: | ||
method: get | ||
path: echo | ||
handler: handler.echo |