-
-
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: add support for apiGateway.apiKeys (#1572)
- Loading branch information
1 parent
18d4e8a
commit 20f6e8b
Showing
7 changed files
with
134 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function getApiKeysValues(apiKeys) { | ||
return new Set( | ||
apiKeys | ||
.filter((apiKey) => typeof apiKey === 'object' && apiKey.value != null) | ||
.map(({ value }) => value), | ||
) | ||
} |
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
71 changes: 71 additions & 0 deletions
71
tests/options/apiGateway/apiKeys/apiGateway-apiKeys.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,71 @@ | ||
import assert from 'node:assert' | ||
import { dirname, resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, teardown } from '../../../_testHelpers/index.js' | ||
import { BASE_URL } from '../../../config.js' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
describe('apiGateway apiKeys tests', function desc() { | ||
beforeEach(() => | ||
setup({ | ||
servicePath: resolve(__dirname), | ||
}), | ||
) | ||
|
||
afterEach(() => teardown()) | ||
|
||
// | ||
;[ | ||
{ | ||
description: 'should ...', | ||
expected: { | ||
body: { | ||
message: 'Forbidden', | ||
}, | ||
statusCode: 403, | ||
}, | ||
path: '/dev/foo', | ||
}, | ||
|
||
{ | ||
description: 'should ...', | ||
expected: { | ||
body: { | ||
foo: 'bar', | ||
}, | ||
statusCode: 200, | ||
}, | ||
headers: { | ||
'x-api-key': 'fooValuefooValuefooValue', | ||
}, | ||
path: '/dev/foo', | ||
}, | ||
|
||
{ | ||
description: 'should ...', | ||
expected: { | ||
body: { | ||
foo: 'bar', | ||
}, | ||
statusCode: 200, | ||
}, | ||
headers: { | ||
'x-api-key': 'barValuebarValuebarValue', | ||
}, | ||
path: '/dev/foo', | ||
}, | ||
].forEach(({ description, expected, headers, path }) => { | ||
it(description, async () => { | ||
const url = new URL(path, BASE_URL) | ||
|
||
const response = await fetch(url, { | ||
headers, | ||
}) | ||
assert.equal(response.status, expected.statusCode) | ||
|
||
const json = await response.json() | ||
assert.deepEqual(json, expected.body) | ||
}) | ||
}) | ||
}) |
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,30 @@ | ||
service: apiGateway-apiKeys-tests | ||
|
||
configValidationMode: error | ||
deprecationNotificationMode: error | ||
|
||
plugins: | ||
- ../../../../src/index.js | ||
|
||
provider: | ||
apiGateway: | ||
apiKeys: | ||
# - fooKeyName TODO, TEST MISSING for generated apiKey | ||
- name: fooName | ||
value: fooValuefooValuefooValue | ||
- value: barValuebarValuebarValue | ||
memorySize: 128 | ||
name: aws | ||
region: us-east-1 | ||
runtime: nodejs16.x | ||
stage: dev | ||
versionFunctions: false | ||
|
||
functions: | ||
foo: | ||
events: | ||
- http: | ||
method: get | ||
path: /foo | ||
private: true | ||
handler: src/index.default |
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,10 @@ | ||
const { stringify } = JSON | ||
|
||
export default async function handler() { | ||
return { | ||
body: stringify({ | ||
foo: 'bar', | ||
}), | ||
statusCode: 200, | ||
} | ||
} |
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" | ||
} |