3 test_description
='external credential helper tests
5 This is a tool for authors of external helper tools to sanity-check
6 their helpers. If you have written the "git-credential-foo" helper,
9 make GIT_TEST_CREDENTIAL_HELPER=foo t0303-credential-external.sh
11 This assumes that your helper is capable of both storing and
12 retrieving credentials (some helpers may be read-only, and they will
15 Please note that the individual tests do not verify all of the
16 preconditions themselves, but rather build on each other. A failing
17 test means that tests later in the sequence can return false "OK"
20 If your helper supports time-based expiration with a configurable
21 timeout, you can test that feature with:
23 make GIT_TEST_CREDENTIAL_HELPER=foo \
24 GIT_TEST_CREDENTIAL_HELPER_TIMEOUT="foo --timeout=1" \
25 t0303-credential-external.sh
27 If your helper requires additional setup before the tests are started,
28 you can set GIT_TEST_CREDENTIAL_HELPER_SETUP to a sequence of shell
33 .
"$TEST_DIRECTORY"/lib-credential.sh
35 # If we're not given a specific external helper to run against,
36 # there isn't much to test. But we can still run through our
37 # battery of tests with a fake helper and check that the
38 # test themselves are self-consistent and clean up after
41 # We'll use the "store" helper, since we can easily inspect
42 # its state by looking at the on-disk file. But since it doesn't
43 # implement any caching or expiry logic, we'll cheat and override
44 # the "check" function to just report all results as OK.
45 if test -z "$GIT_TEST_CREDENTIAL_HELPER"; then
46 GIT_TEST_CREDENTIAL_HELPER
=store
47 GIT_TEST_CREDENTIAL_HELPER_TIMEOUT
=store
49 test "$1" = "approve" ||
return 0
50 git
-c credential.helper
=store credential approve
55 test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" ||
56 eval "$GIT_TEST_CREDENTIAL_HELPER_SETUP"
58 # clean before the test in case there is cruft left
59 # over from a previous run that would impact results
60 helper_test_clean
"$GIT_TEST_CREDENTIAL_HELPER"
62 helper_test
"$GIT_TEST_CREDENTIAL_HELPER"
63 helper_test_password_expiry_utc
"$GIT_TEST_CREDENTIAL_HELPER"
64 helper_test_oauth_refresh_token
"$GIT_TEST_CREDENTIAL_HELPER"
66 if test -z "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"; then
67 say
"# skipping timeout tests (GIT_TEST_CREDENTIAL_HELPER_TIMEOUT not set)"
69 helper_test_timeout
"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"
72 # clean afterwards so that we are good citizens
73 # and don't leave cruft in the helper's storage, which
74 # might be long-term system storage
75 helper_test_clean
"$GIT_TEST_CREDENTIAL_HELPER"
77 if test "$check_cleanup" = "t"
79 test_expect_success
'test cleanup removes everything' '
80 test_must_be_empty "$HOME/.git-credentials"