-
Notifications
You must be signed in to change notification settings - Fork 3
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: Use yt01 token generator environment for k6 tests running on yt01 #1391
Conversation
📝 WalkthroughWalkthroughThe changes introduce a new constant Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Quality Gate passedIssues Measures |
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
tests/k6/common/config.js (1)
44-44
: Enhance comment clarity for token generator environment selection.The implementation correctly handles the token generator environment selection. However, the comment could be more descriptive about the purpose and implications of this configuration.
Consider updating the comment to be more explicit:
-export const tokenGeneratorEnv = __ENV.API_ENVIRONMENT == "yt01" ? "yt01" : "tt02"; // yt01 is the only environment that has a separate token generator environment +export const tokenGeneratorEnv = __ENV.API_ENVIRONMENT == "yt01" ? "yt01" : "tt02"; // Use yt01's dedicated token generator for yt01 environment, default to tt02 for all other environmentstests/k6/common/token.js (1)
60-61
: Add validation for tokenGeneratorEnv valueConsider adding validation to ensure tokenGeneratorEnv contains a valid value before using it in URL construction. This would prevent potential issues with invalid environments.
+ const validEnvironments = ['tt02', 'yt01']; + if (!validEnvironments.includes(tokenGeneratorEnv)) { + throw new Error(`Invalid token generator environment: ${tokenGeneratorEnv}`); + }Also applies to: 66-67
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
tests/k6/common/config.js
(1 hunks)tests/k6/common/token.js
(2 hunks)
🔇 Additional comments (3)
tests/k6/common/config.js (1)
44-44
: Verify token generator environment usage across the codebase.
Let's ensure this change is consistently applied across all token-related functionality.
✅ Verification successful
Let me check the actual implementation and usage of this token generator environment configuration.
Token generator environment configuration is correctly implemented
The verification shows that:
token.js
correctly uses the importedtokenGeneratorEnv
constant fromconfig.js
in both token generation functions (getServiceOwnerTokenFromGenerator
andgetEnduserTokenFromGenerator
).- The shell script
generate_tokens.sh
handles environment mapping separately for its specific use case (batch token generation) and doesn't need to use thetokenGeneratorEnv
constant as it's not part of the k6 test execution context. - No other files in the codebase require similar environment-specific token generator logic as the token generation is centralized in these two files.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any other files that might need to use tokenGeneratorEnv
# and verify the usage in token.js
# Check for any files containing token generator URLs or environment references
echo "Checking for files with token generator references:"
rg -l "token.*generator|maskinporten|idporten" tests/
# Check for specific environment strings that might need to use tokenGeneratorEnv
echo -e "\nChecking for hardcoded environment references:"
rg -l "tt02|yt01" tests/
# Look for potential token-related configuration
echo -e "\nChecking for other token-related configuration:"
rg -l "getToken|fetchToken|token.*config" tests/
Length of output: 897
Script:
#!/bin/bash
# Check the implementation in token.js
echo "Content of token.js:"
cat tests/k6/common/token.js
# Check the usage in generate_tokens.sh
echo -e "\nContent of generate_tokens.sh:"
cat tests/k6/tests/scripts/generate_tokens.sh
# Check for any direct usage of tt02/yt01 in these files
echo -e "\nChecking for direct environment references in token-related files:"
rg "tt02|yt01" tests/k6/common/token.js tests/k6/tests/scripts/generate_tokens.sh
Length of output: 6944
tests/k6/common/token.js (2)
4-4
: LGTM: Clean import addition
The import of tokenGeneratorEnv
is well-placed and follows proper naming conventions.
60-61
:
Security: Consider using HTTPS for token generator endpoint
While the changes to use dynamic environment configuration are good, the token generator endpoint is using HTTP. This could expose sensitive information during token generation.
Let's verify if HTTPS is supported:
Consider updating the URL to use HTTPS:
- const url = `http://altinn-testtools-token-generator.azurewebsites.net/api/GetEnterpriseToken?env=${tokenGeneratorEnv}&scopes=${encodeURIComponent(fullTokenOptions.scopes)}&org=${fullTokenOptions.orgName}&orgNo=${fullTokenOptions.orgNo}&ttl=${tokenTtl}`;
+ const url = `https://altinn-testtools-token-generator.azurewebsites.net/api/GetEnterpriseToken?env=${tokenGeneratorEnv}&scopes=${encodeURIComponent(fullTokenOptions.scopes)}&org=${fullTokenOptions.orgName}&orgNo=${fullTokenOptions.orgNo}&ttl=${tokenTtl}`;
🤖 I have created a release *beep* *boop* --- ## [1.28.2](v1.28.1...v1.28.2) (2024-11-05) ### Bug Fixes * Use yt01 token generator environment for k6 tests running on yt01 ([#1391](#1391)) ([393176c](393176c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Description
This updates the token generator to use the yt01 token generator when running against the yt01.
Related Issue(s)
Verification
Summary by CodeRabbit
New Features
Bug Fixes
Documentation