1 # Shell library for testing credential handling including helpers. See t0302
2 # for an example of testing a specific helper.
4 # Try a set of credential helpers; the expected stdin,
5 # stdout and stderr should be provided on stdin,
12 credential_opts
="$credential_opts -c credential.helper='$arg'"
15 read_chunk
>expect-stdout
&&
16 read_chunk
>expect-stderr
&&
17 if ! eval "git $credential_opts credential $credential_cmd <stdin >stdout 2>stderr"; then
18 echo "git credential failed with code $?" &&
22 test_cmp expect-stdout stdout
&&
23 test_cmp expect-stderr stderr
35 # Clear any residual data from previous tests. We only
36 # need this when testing third-party helpers which read and
37 # write outside of our trash-directory sandbox.
39 # Don't bother checking for success here, as it is
40 # outside the scope of tests and represents a best effort to
41 # clean up after ourselves.
43 reject
$1 https example.com store-user
44 reject
$1 https example.com user1
45 reject
$1 https example.com user2
46 reject
$1 http path.tld user
47 reject
$1 https timeout.tld user
48 reject
$1 https sso.tld
56 ) | git
-c credential.helper
=$1 credential reject
62 test_expect_success
"helper ($HELPER) has no existing data" '
63 check fill $HELPER <<-\EOF
69 username=askpass-username
70 password=askpass-password
72 askpass: Username for '\''https://example.com'\'':
73 askpass: Password for '\''https://askpass-username@example.com'\'':
77 test_expect_success
"helper ($HELPER) stores password" '
78 check approve $HELPER <<-\EOF
86 test_expect_success
"helper ($HELPER) can retrieve password" '
87 check fill $HELPER <<-\EOF
99 test_expect_success
"helper ($HELPER) requires matching protocol" '
100 check fill $HELPER <<-\EOF
106 username=askpass-username
107 password=askpass-password
109 askpass: Username for '\''http://example.com'\'':
110 askpass: Password for '\''http://askpass-username@example.com'\'':
114 test_expect_success
"helper ($HELPER) requires matching host" '
115 check fill $HELPER <<-\EOF
121 username=askpass-username
122 password=askpass-password
124 askpass: Username for '\''https://other.tld'\'':
125 askpass: Password for '\''https://askpass-username@other.tld'\'':
129 test_expect_success
"helper ($HELPER) requires matching username" '
130 check fill $HELPER <<-\EOF
138 password=askpass-password
140 askpass: Password for '\''https://other@example.com'\'':
144 test_expect_success
"helper ($HELPER) requires matching path" '
145 test_config credential.usehttppath true &&
146 check approve $HELPER <<-\EOF &&
153 check fill $HELPER <<-\EOF
161 username=askpass-username
162 password=askpass-password
164 askpass: Username for '\''http://path.tld/bar.git'\'':
165 askpass: Password for '\''http://askpass-username@path.tld/bar.git'\'':
169 test_expect_success
"helper ($HELPER) can forget host" '
170 check reject $HELPER <<-\EOF &&
174 check fill $HELPER <<-\EOF
180 username=askpass-username
181 password=askpass-password
183 askpass: Username for '\''https://example.com'\'':
184 askpass: Password for '\''https://askpass-username@example.com'\'':
188 test_expect_success
"helper ($HELPER) can store multiple users" '
189 check approve $HELPER <<-\EOF &&
195 check approve $HELPER <<-\EOF &&
201 check fill $HELPER <<-\EOF &&
211 check fill $HELPER <<-\EOF
223 test_expect_success
"helper ($HELPER) can forget user" '
224 check reject $HELPER <<-\EOF &&
229 check fill $HELPER <<-\EOF
237 password=askpass-password
239 askpass: Password for '\''https://user1@example.com'\'':
243 test_expect_success
"helper ($HELPER) remembers other user" '
244 check fill $HELPER <<-\EOF
256 test_expect_success
"helper ($HELPER) can store empty username" '
257 check approve $HELPER <<-\EOF &&
263 check fill $HELPER <<-\EOF
275 helper_test_timeout
() {
278 test_expect_success
"helper ($HELPER) times out" '
279 check approve "$HELPER" <<-\EOF &&
286 check fill "$HELPER" <<-\EOF
292 username=askpass-username
293 password=askpass-password
295 askpass: Username for '\''https://timeout.tld'\'':
296 askpass: Password for '\''https://askpass-username@timeout.tld'\'':
301 write_script askpass
<<\EOF
303 what
=$
(echo $1 | cut
-d" " -f1 |
tr A-Z a-z |
tr -cd a-z
)
306 GIT_ASKPASS
="$PWD/askpass"