Git fork
at reftables-rust 84 lines 2.8 kB view raw
1#!/bin/sh 2 3test_description='external credential helper tests 4 5This is a tool for authors of external helper tools to sanity-check 6their helpers. If you have written the "git-credential-foo" helper, 7you check it with: 8 9 make GIT_TEST_CREDENTIAL_HELPER=foo t0303-credential-external.sh 10 11This assumes that your helper is capable of both storing and 12retrieving credentials (some helpers may be read-only, and they will 13fail these tests). 14 15Please note that the individual tests do not verify all of the 16preconditions themselves, but rather build on each other. A failing 17test means that tests later in the sequence can return false "OK" 18results. 19 20If your helper supports time-based expiration with a configurable 21timeout, 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 27If your helper requires additional setup before the tests are started, 28you can set GIT_TEST_CREDENTIAL_HELPER_SETUP to a sequence of shell 29commands. 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. 45if 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 53fi 54 55test -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 60helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" 61 62helper_test "$GIT_TEST_CREDENTIAL_HELPER" 63helper_test_password_expiry_utc "$GIT_TEST_CREDENTIAL_HELPER" 64helper_test_oauth_refresh_token "$GIT_TEST_CREDENTIAL_HELPER" 65 66if test -z "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"; then 67 say "# skipping timeout tests (GIT_TEST_CREDENTIAL_HELPER_TIMEOUT not set)" 68else 69 helper_test_timeout "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT" 70fi 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 75helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" 76 77if test "$check_cleanup" = "t" 78then 79 test_expect_success 'test cleanup removes everything' ' 80 test_must_be_empty "$HOME/.git-credentials" 81 ' 82fi 83 84test_done