]>
Commit | Line | Data |
---|---|---|
861444f6 JK |
1 | #!/bin/sh |
2 | ||
6c556cb8 ZJS |
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 | ||
861444f6 JK |
32 | . ./test-lib.sh |
33 | . "$TEST_DIRECTORY"/lib-credential.sh | |
34 | ||
e41d68b7 JK |
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. | |
16e44810 | 45 | if test -z "$GIT_TEST_CREDENTIAL_HELPER"; then |
e41d68b7 JK |
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 | |
16e44810 | 53 | fi |
861444f6 | 54 | |
16e44810 ZJS |
55 | test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" || |
56 | eval "$GIT_TEST_CREDENTIAL_HELPER_SETUP" | |
861444f6 | 57 | |
16e44810 ZJS |
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" | |
861444f6 | 61 | |
16e44810 | 62 | helper_test "$GIT_TEST_CREDENTIAL_HELPER" |
0ce02e2f H |
63 | helper_test_password_expiry_utc "$GIT_TEST_CREDENTIAL_HELPER" |
64 | helper_test_oauth_refresh_token "$GIT_TEST_CREDENTIAL_HELPER" | |
861444f6 JK |
65 | |
66 | if test -z "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"; then | |
16e44810 | 67 | say "# skipping timeout tests (GIT_TEST_CREDENTIAL_HELPER_TIMEOUT not set)" |
861444f6 | 68 | else |
861444f6 | 69 | helper_test_timeout "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT" |
861444f6 JK |
70 | fi |
71 | ||
16e44810 ZJS |
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 | ||
e41d68b7 JK |
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 | ||
861444f6 | 84 | test_done |