]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0303-credential-external.sh
Merge branch 'mr/rerere-crash-fix'
[thirdparty/git.git] / t / t0303-credential-external.sh
1 #!/bin/sh
2
3 test_description='external credential helper tests
4
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,
7 you check it with:
8
9 make GIT_TEST_CREDENTIAL_HELPER=foo t0303-credential-external.sh
10
11 This assumes that your helper is capable of both storing and
12 retrieving credentials (some helpers may be read-only, and they will
13 fail these tests).
14
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"
18 results.
19
20 If your helper supports time-based expiration with a configurable
21 timeout, you can test that feature with:
22
23 make GIT_TEST_CREDENTIAL_HELPER=foo \
24 GIT_TEST_CREDENTIAL_HELPER_TIMEOUT="foo --timeout=1" \
25 t0303-credential-external.sh
26
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
29 commands.
30 '
31
32 . ./test-lib.sh
33 . "$TEST_DIRECTORY"/lib-credential.sh
34
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
39 # themselves.
40 #
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
48 check () {
49 test "$1" = "approve" || return 0
50 git -c credential.helper=store credential approve
51 }
52 check_cleanup=t
53 fi
54
55 test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" ||
56 eval "$GIT_TEST_CREDENTIAL_HELPER_SETUP"
57
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"
61
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"
65
66 if test -z "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"; then
67 say "# skipping timeout tests (GIT_TEST_CREDENTIAL_HELPER_TIMEOUT not set)"
68 else
69 helper_test_timeout "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"
70 fi
71
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"
76
77 if test "$check_cleanup" = "t"
78 then
79 test_expect_success 'test cleanup removes everything' '
80 test_must_be_empty "$HOME/.git-credentials"
81 '
82 fi
83
84 test_done