22
33load ' test-helper'
44
5+ setup_file () {
6+ if ! helm_supports_credentials; then
7+ echo " # Skipping credential tests - Helm version < 3.14.0 does not support credential passing" >&2
8+ fi
9+ }
10+
511@test " should setup git credentials when HELM_PLUGIN_USERNAME and HELM_PLUGIN_PASSWORD are set" {
12+ if ! helm_supports_credentials; then
13+ skip " Helm version < 3.14.0 does not support credential passing"
14+ fi
15+
616 export HELM_PLUGIN_USERNAME=" testuser"
717 export HELM_PLUGIN_PASSWORD=" testpass"
8-
18+
919 # Call setup_git_credentials function in a subshell to check exports
1020 run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "GIT_USER=${GIT_USER}" && echo "GIT_PASSWORD=${GIT_PASSWORD}"'
1121 [ $status = 0 ]
12-
22+
1323 # Check that the output contains the expected values
1424 [[ " $output " == * " GIT_USER=testuser" * ]]
1525 [[ " $output " == * " GIT_PASSWORD=testpass" * ]]
16-
26+
1727 # Check that HELM_GIT_USE_CREDENTIALS is set to enable git_cmd wrapper
1828 run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "HELM_GIT_USE_CREDENTIALS=${HELM_GIT_USE_CREDENTIALS}"'
1929 [ $status = 0 ]
2030 [[ " $output " == * " HELM_GIT_USE_CREDENTIALS=1" * ]]
2131}
2232
2333@test " should not setup git credentials when HELM_PLUGIN_USERNAME is missing" {
34+ if ! helm_supports_credentials; then
35+ skip " Helm version < 3.14.0 does not support credential passing"
36+ fi
37+
2438 unset HELM_PLUGIN_USERNAME
2539 export HELM_PLUGIN_PASSWORD=" testpass"
26-
40+
2741 # Call setup_git_credentials function
2842 run setup_git_credentials
2943 [ $status = 0 ]
30-
44+
3145 # Check that environment variables are not set
3246 [ -z " ${GIT_USER:- } " ]
3347 [ -z " ${GIT_PASSWORD:- } " ]
3448}
3549
3650@test " should not setup git credentials when HELM_PLUGIN_PASSWORD is missing" {
51+ if ! helm_supports_credentials; then
52+ skip " Helm version < 3.14.0 does not support credential passing"
53+ fi
54+
3755 export HELM_PLUGIN_USERNAME=" testuser"
3856 unset HELM_PLUGIN_PASSWORD
39-
57+
4058 # Call setup_git_credentials function
4159 run setup_git_credentials
4260 [ $status = 0 ]
43-
61+
4462 # Check that environment variables are not set
4563 [ -z " ${GIT_USER:- } " ]
4664 [ -z " ${GIT_PASSWORD:- } " ]
4765}
4866
4967@test " should not setup git credentials when both are missing" {
68+ if ! helm_supports_credentials; then
69+ skip " Helm version < 3.14.0 does not support credential passing"
70+ fi
71+
5072 unset HELM_PLUGIN_USERNAME
5173 unset HELM_PLUGIN_PASSWORD
52-
74+
5375 # Call setup_git_credentials function
5476 run setup_git_credentials
5577 [ $status = 0 ]
56-
78+
5779 # Check that environment variables are not set
5880 [ -z " ${GIT_USER:- } " ]
5981 [ -z " ${GIT_PASSWORD:- } " ]
6082}
6183
6284@test " helm_git main should call setup_git_credentials with username and password" {
85+ if ! helm_supports_credentials; then
86+ skip " Helm version < 3.14.0 does not support credential passing"
87+ fi
88+
6389 export HELM_PLUGIN_USERNAME=" testuser"
6490 export HELM_PLUGIN_PASSWORD=" testpass"
65-
91+
6692 # Test that main function sets up credentials by checking git config
6793 run bash -c
' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && export HELM_GIT_DEBUG=1 && main "" "" "" "git+https://example.com/[email protected] ?ref=master" 2>&1 || true' 68-
94+
6995 # Check that the debug message about setting up credentials appears
7096 [[ " $output " == * " Setting up git credentials using Helm-provided username and password" * ]]
7197}
7298
7399@test " git credential helper should work with environment variables" {
100+ if ! helm_supports_credentials; then
101+ skip " Helm version < 3.14.0 does not support credential passing"
102+ fi
103+
74104 export HELM_PLUGIN_USERNAME=" testuser"
75105 export HELM_PLUGIN_PASSWORD=" testpass"
76106 export GIT_USER=" testuser"
77107 export GIT_PASSWORD=" testpass"
78-
108+
79109 # Test the credential helper directly
80110 run bash -c ' echo "username=${GIT_USER}"; echo "password=${GIT_PASSWORD}"'
81111 [ $status = 0 ]
@@ -84,36 +114,48 @@ load 'test-helper'
84114}
85115
86116@test " should handle credentials with special characters" {
117+ if ! helm_supports_credentials; then
118+ skip " Helm version < 3.14.0 does not support credential passing"
119+ fi
120+
87121 export HELM_PLUGIN_USERNAME=
" [email protected] " 88122 export HELM_PLUGIN_PASSWORD=" pass/with/special&chars"
89-
123+
90124 # Call setup_git_credentials function in a subshell to check exports
91125 run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "GIT_USER=${GIT_USER}" && echo "GIT_PASSWORD=${GIT_PASSWORD}"'
92126 [ $status = 0 ]
93-
127+
94128 # Check that the output contains the expected values with special characters
95129 [[
" $output " == * " [email protected] " * ]]
96130 [[ " $output " == * " GIT_PASSWORD=pass/with/special&chars" * ]]
97131}
98132
99133@test " git_cmd should use credentials when available" {
134+ if ! helm_supports_credentials; then
135+ skip " Helm version < 3.14.0 does not support credential passing"
136+ fi
137+
100138 export HELM_PLUGIN_USERNAME=" testuser"
101139 export HELM_PLUGIN_PASSWORD=" testpass"
102-
140+
103141 # Test git_cmd function
104142 run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && git_cmd config --list | grep -E "(user|credential)" || echo "No credential config found"'
105143 [ $status = 0 ]
106-
144+
107145 # Should succeed (exit code 0)
108146}
109147
110148@test " git_cmd should work normally when no credentials" {
149+ if ! helm_supports_credentials; then
150+ skip " Helm version < 3.14.0 does not support credential passing"
151+ fi
152+
111153 unset HELM_PLUGIN_USERNAME
112154 unset HELM_PLUGIN_PASSWORD
113155 unset HELM_GIT_USE_CREDENTIALS
114-
156+
115157 # Test git_cmd function without credentials
116158 run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && git_cmd --version'
117159 [ $status = 0 ]
118160 [[ " $output " == * " git version" * ]]
119- }
161+ }
0 commit comments