-
Notifications
You must be signed in to change notification settings - Fork 53
feat: Support helm --username and --password #347
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
Open
Copilot
wants to merge
16
commits into
master
Choose a base branch
from
copilot/fix-255
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e91610d
Changes before error encountered
Copilot 18e49fd
Add Helm version requirements for credential support
Copilot b532cc5
Simplify helm_supports_credentials() function as suggested
Copilot 6da3691
Fix shellcheck issues in credential helper and version checking
Copilot 6475dc1
Update helm-git-plugin.sh
aslafy-z 20da719
Update helm-git-plugin.sh
aslafy-z d24edb1
Update README.md
aslafy-z f77b9e3
Scope credential variables to git_cmd function only
Copilot f462147
Unset HELM_PLUGIN_* credentials after storing them locally
Copilot 259f78d
Remove export of HELM_GIT_USERNAME and HELM_GIT_PASSWORD variables
Copilot e2b5343
Initialize credential variables at global scope for clarity
Copilot ca31709
Update helm-git-plugin.sh
aslafy-z 542fdfd
Update helm-git-plugin.sh
aslafy-z f983511
Update tests for simplified credential implementation
Copilot be2947b
Fix test name to accurately reflect username-only credential behavior
Copilot 355af28
Update helm-git-plugin.sh
aslafy-z File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,167 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load 'test-helper' | ||
|
|
||
| setup_file() { | ||
| if ! helm_supports_credentials; then | ||
| echo "# Skipping credential tests - Helm version < 3.14.0 does not support credential passing" >&2 | ||
| fi | ||
| } | ||
|
|
||
| @test "should setup git credentials when HELM_PLUGIN_USERNAME and HELM_PLUGIN_PASSWORD are set" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| export HELM_PLUGIN_USERNAME="testuser" | ||
| export HELM_PLUGIN_PASSWORD="testpass" | ||
|
|
||
| # Source the plugin and check that credentials are stored | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && echo "git_username=${git_username}" && echo "git_password=${git_password}"' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"git_username=testuser"* ]] | ||
| [[ "$output" == *"git_password=testpass"* ]] | ||
|
|
||
| # Check that the original HELM_PLUGIN_* variables are unset for security | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && echo "HELM_PLUGIN_USERNAME=${HELM_PLUGIN_USERNAME:-unset}" && echo "HELM_PLUGIN_PASSWORD=${HELM_PLUGIN_PASSWORD:-unset}"' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"HELM_PLUGIN_USERNAME=unset"* ]] | ||
| [[ "$output" == *"HELM_PLUGIN_PASSWORD=unset"* ]] | ||
|
|
||
| # Check that the internal git_* variables are NOT exported to child processes | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && bash -c "echo git_username=\${git_username:-unset}; echo git_password=\${git_password:-unset}"' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"git_username=unset"* ]] | ||
| [[ "$output" == *"git_password=unset"* ]] | ||
| } | ||
|
|
||
| @test "should not setup git credentials when HELM_PLUGIN_USERNAME is missing" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| unset HELM_PLUGIN_USERNAME | ||
| export HELM_PLUGIN_PASSWORD="testpass" | ||
|
|
||
| # Source the plugin and verify git_username is empty | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && echo "git_username=${git_username:-empty}"' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"git_username=empty"* ]] | ||
| } | ||
|
|
||
| @test "should not setup git credentials when HELM_PLUGIN_PASSWORD is missing" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| export HELM_PLUGIN_USERNAME="testuser" | ||
| unset HELM_PLUGIN_PASSWORD | ||
|
|
||
| # Source the plugin and verify credentials are set (username without password is allowed) | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && echo "git_username=${git_username}" && echo "git_password=${git_password:-empty}"' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"git_username=testuser"* ]] | ||
| [[ "$output" == *"git_password=empty"* ]] | ||
| } | ||
|
|
||
| @test "should not setup git credentials when both are missing" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| unset HELM_PLUGIN_USERNAME | ||
| unset HELM_PLUGIN_PASSWORD | ||
|
|
||
| # Source the plugin and verify both are empty | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && echo "git_username=${git_username:-empty}" && echo "git_password=${git_password:-empty}"' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"git_username=empty"* ]] | ||
| [[ "$output" == *"git_password=empty"* ]] | ||
| } | ||
|
|
||
| @test "helm_git main should use credentials with username and password" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| export HELM_PLUGIN_USERNAME="testuser" | ||
| export HELM_PLUGIN_PASSWORD="testpass" | ||
| export HELM_GIT_TRACE=1 | ||
|
|
||
| # Test that git_cmd uses credentials by checking trace output | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && git_cmd --version 2>&1' | ||
|
|
||
| # Check that the trace message about using credentials appears | ||
| [[ "$output" == *"Git credential helper configured with username: testuser"* ]] | ||
| [[ "$output" == *"git version"* ]] | ||
| } | ||
|
|
||
| @test "git credential helper should work with environment variables" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| export HELM_PLUGIN_USERNAME="testuser" | ||
| export HELM_PLUGIN_PASSWORD="testpass" | ||
|
|
||
| # Test the credential helper by simulating what git_cmd does | ||
| run bash -c 'GIT_USERNAME="testuser" GIT_PASSWORD="testpass" bash <<EOF | ||
| echo "username=\${GIT_USERNAME}" | ||
| echo "password=\${GIT_PASSWORD}" | ||
| EOF' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"username=testuser"* ]] | ||
| [[ "$output" == *"password=testpass"* ]] | ||
| } | ||
|
|
||
| @test "should handle credentials with special characters" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| export HELM_PLUGIN_USERNAME="[email protected]" | ||
| export HELM_PLUGIN_PASSWORD="pass/with/special&chars" | ||
|
|
||
| # Source the plugin and verify credentials with special characters are stored | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && echo "git_username=${git_username}" && echo "git_password=${git_password}"' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"[email protected]"* ]] | ||
| [[ "$output" == *"git_password=pass/with/special&chars"* ]] | ||
|
|
||
| # Test that the credential helper can handle special characters | ||
| run bash -c 'GIT_USERNAME="[email protected]" GIT_PASSWORD="pass/with/special&chars" bash <<EOF | ||
| echo "username=\${GIT_USERNAME}" | ||
| echo "password=\${GIT_PASSWORD}" | ||
| EOF' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"[email protected]"* ]] | ||
| [[ "$output" == *"password=pass/with/special&chars"* ]] | ||
| } | ||
|
|
||
| @test "git_cmd should use credentials when available" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| export HELM_PLUGIN_USERNAME="testuser" | ||
| export HELM_PLUGIN_PASSWORD="testpass" | ||
|
|
||
| # Test git_cmd function with credentials | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && git_cmd --version' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"git version"* ]] | ||
| } | ||
|
|
||
| @test "git_cmd should work normally when no credentials" { | ||
| if ! helm_supports_credentials; then | ||
| skip "Helm version < 3.14.0 does not support credential passing" | ||
| fi | ||
|
|
||
| unset HELM_PLUGIN_USERNAME | ||
| unset HELM_PLUGIN_PASSWORD | ||
|
|
||
| # Test git_cmd function without credentials | ||
| run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && git_cmd --version' | ||
| [ $status = 0 ] | ||
| [[ "$output" == *"git version"* ]] | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This test case is wrongly named @copilot
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.
Fixed. Renamed test from "should not setup git credentials when HELM_PLUGIN_PASSWORD is missing" to "should setup git credentials with username only (empty password allowed)" which accurately describes the test behavior - username is captured and used even when password is missing.
Changes in commit be2947b.