t0303: check that helper_test_clean removes all credentials
commite41d68b75c7e9beb1bc92ad5519c30a215c9d9d1
authorJeff King <peff@peff.net>
Sat, 17 Feb 2024 04:58:14 +0000 (16 23:58 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Feb 2024 23:01:41 +0000 (19 15:01 -0800)
tree23c6f3b6d41a8a1c3e35faaa0a6428c3479375e1
parent30b1e8b920d9e5a151ad4bdbd1b6612d6f00794f
t0303: check that helper_test_clean removes all credentials

Our lib-credential.sh library comes with a "clean" function that removes
all of the credentials used in its tests (to avoid leaving cruft in
system credential storage). But it's easy to add a test that uses a new
credential but forget to add it to the clean function.  E.g., the case
fixed by 83e6eb7d7a (t/lib-credential: clean additional credential,
2024-02-15).

We should be able to catch this automatically, but it's a little tricky.

We can't just compare the contents of the helper's storage before and
after the test run, because there isn't a way to ask a helper to dump
all of its storage. And in most cases we don't have direct access to the
underlying storage (since the whole point of the helper is to abstract
that away). We can work around that by using our own "store" helper,
since we can directly inspect its state by looking at its on-disk file.

But there's a catch: the "store" helper doesn't support features like
caching or expiration, so using it naively fails tests (and skipping
those tests would give us incomplete coverage). Implementing all of
those features would be non-trivial. But we can hack around that by
overriding the "check" function used by the tests to turn most requests
into noop success (except for "approve" requests, which actually store
things).

And then at the end we can check that running the "clean" function takes
us back to an empty state.

Note that because we've skipped any tests that erase credentials
(because of our noop check function), the state we see at cleanup time
may be larger than it would be normally. That's OK. The point of the
clean function is to clean up any cruft we _might_ have left in place,
so we're just being doubly thorough.

The way this is bolted onto t0303 feels a little messy. But it's really
the best place to do it, because then we know that it is running the
exact sequence of tests that we'd use for testing a real external
helper. In a normal run of "make test" it currently does nothing (the
idea is that you run it manually after pointing it at some helper
program). But now with this patch, "make test" will sanity-check the
script itself.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0303-credential-external.sh