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
32 TEST_PASSES_SANITIZE_LEAK
=true
34 .
"$TEST_DIRECTORY"/lib-credential.sh
36 # If we're not given a specific external helper to run against,
37 # there isn't much to test. But we can still run through our
38 # battery of tests with a fake helper and check that the
39 # test themselves are self-consistent and clean up after
42 # We'll use the "store" helper, since we can easily inspect
43 # its state by looking at the on-disk file. But since it doesn't
44 # implement any caching or expiry logic, we'll cheat and override
45 # the "check" function to just report all results as OK.
46 if test -z "$GIT_TEST_CREDENTIAL_HELPER"; then
47 GIT_TEST_CREDENTIAL_HELPER
=store
48 GIT_TEST_CREDENTIAL_HELPER_TIMEOUT
=store
50 test "$1" = "approve" ||
return 0
51 git
-c credential.helper
=store credential approve
56 test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" ||
57 eval "$GIT_TEST_CREDENTIAL_HELPER_SETUP"
59 # clean before the test in case there is cruft left
60 # over from a previous run that would impact results
61 helper_test_clean
"$GIT_TEST_CREDENTIAL_HELPER"
63 helper_test
"$GIT_TEST_CREDENTIAL_HELPER"
64 helper_test_password_expiry_utc
"$GIT_TEST_CREDENTIAL_HELPER"
65 helper_test_oauth_refresh_token
"$GIT_TEST_CREDENTIAL_HELPER"
67 if test -z "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"; then
68 say
"# skipping timeout tests (GIT_TEST_CREDENTIAL_HELPER_TIMEOUT not set)"
70 helper_test_timeout
"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"
73 # clean afterwards so that we are good citizens
74 # and don't leave cruft in the helper's storage, which
75 # might be long-term system storage
76 helper_test_clean
"$GIT_TEST_CREDENTIAL_HELPER"
78 if test "$check_cleanup" = "t"
80 test_expect_success
'test cleanup removes everything' '
81 test_must_be_empty "$HOME/.git-credentials"