-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[k6] Add authentication variables in headers and cookies #19060
[k6] Add authentication variables in headers and cookies #19060
Conversation
thanks for the PR cc @mostafa |
global_api_key_cookie: | ||
type: apiKey | ||
name: global_api_key_cookie | ||
in: cookie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please copy this file to modules/openapi-generator/src/test/resources/3_0/k6/petstore-with-fake-endpoints-models-for-testing.yaml
and revert the change in this file which is used by many other generators for testing?
please also update https://github.com/OpenAPITools/openapi-generator/blob/master/bin/configs/k6.yaml#L3 with the new path to the test spec used by k6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I've modified this PR according to your comment, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. looks good
if there's no further feedback from @mostafa, i will merge it early next week
have a nice weekend
This reverts commit b8cff86.
…te k6 path as its example yaml file.
if (globalAuthMethod.isKeyInHeader) { | ||
httpParams.add(new Parameter(globalAuthMethod.keyParamName, getTemplateString(toVarName(globalAuthMethod.keyParamName)))); | ||
extraParameters.add(new Parameter(toVarName(globalAuthMethod.keyParamName), globalAuthMethod.keyParamName.toUpperCase(Locale.ROOT))); | ||
} | ||
if (globalAuthMethod.isKeyInCookie) { | ||
cookieParams.add(new Parameter(globalAuthMethod.keyParamName, getTemplateString(toVarName(globalAuthMethod.keyParamName)))); | ||
extraParameters.add(new Parameter(toVarName(globalAuthMethod.keyParamName), globalAuthMethod.keyParamName.toUpperCase(Locale.ROOT))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willie5588912 Is it either/or? Or can it be both? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be in both. In some cases, we may need authentication token both in headers and cookies, and this depends on the requirement from the server side.
As the implementation here, it gives the flexibility for authentication token in headers and cookies since they are independent from each other and both ok if provided or not provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mostafa thanks for reviewing. I saw the thumb up so I'll merge it to get the ball rolling.
It seems that the authentication statement is not handled in k6, so here I add a patch for parsing global authentication statement (only API Keys and Cookie Authentication). The parsed variables will be added to all the k6 test functions in either headers or cookies based on its statement.
Take
petstore-with-fake-endpoints-models-for-testing.yaml
as an example, which is used by k6:With the authentication statement specified above, the generated code would be as follows:
If the global authentication is not specified, the
headers
works same as before, and thecookies
gets disappeared (seemscookies
not handled in k6 mustache originally, so without cookie authentication, the content is empty. Therefore, I made thecookies
disappear if it is empty.)While, I'm not sure if it is correct to add all the automatically generated samples into a commit, since there are lots of files.
Please help check this PR, thanks for your help!
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)