Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: checking generated api key #1589

Merged
merged 1 commit into from
Oct 1, 2022
Merged

Conversation

iansu
Copy link
Contributor

@iansu iansu commented Sep 30, 2022

Description

A recent change prevented the default generated API key from working: https://github.com/dherault/serverless-offline/pull/1585/files#diff-c2aeb87128097ca7cd2056b14fba597e31a08404b3bedd046fb550ca602147a3L925

Motivation and Context

Fix a bug that was recently introduced and shipped in v11

How Has This Been Tested?

I've tested this fix locally. This probably should have been covered by a unit test to prevent this from breaking originally. I can add some better tests if that's desired. I figure you probably want to ship a patch release with this fix soon though.

Screenshots (if appropriate):

N/A

@@ -906,9 +906,11 @@ export default class HttpServer {
const apiKey = createApiKey()

this.#apiKeysValues = getApiKeysValues(
this.#serverless.service.provider.apiGateway?.apiKeys ?? [apiKey],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work correctly. The result of this expression is that this.#apiKeysValues is an empty set which means the key that was just created will not work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right. the problem is that we are passing the result of the expression to getApiKeysValues, which expects an array of objects, while [apiKey] is just an array of a string.

)

this.#apiKeysValues.push(apiKey)
Copy link
Collaborator

@dnalborczyk dnalborczyk Oct 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getApiKeysValues is returning a Set, where push does not exist. we would need to use .add here. ideally we would only push when we have no values in the Set. and ideally we would only then call createApiKey.

@dnalborczyk dnalborczyk merged commit 5d9d769 into dherault:master Oct 1, 2022
@dnalborczyk
Copy link
Collaborator

thank you for your PR @iansu !

I figure you probably want to ship a patch release with this fix soon though.

I'll pull this in and fix this up so we can release it quickly.

This probably should have been covered by a unit test to prevent this from breaking originally. I can add some better tests if that's desired.

I wanted to add a test for this initially, but couldn't find the time. in the test we would need to read the generated key from stdout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants