git » chasquid » commit 1208ea1

test: Fix generate_cert cache age logic

author Alberto Bertogli
2024-03-09 10:39:17 UTC
committer Alberto Bertogli
2024-03-09 13:04:25 UTC
parent 3be7cd5160d28405bbcb1ac5d28b61caf0f91236

test: Fix generate_cert cache age logic

The generate_cert cache has a bug because it uses the directory's age,
which won't necessarily change, and it was always re-generating
certificates after 10m.

This patch fixes the bug by checking the age of the private key file
instead of the directory.

test/util/lib.sh +2 -3

diff --git a/test/util/lib.sh b/test/util/lib.sh
index 5ed52bc..c373dd4 100644
--- a/test/util/lib.sh
+++ b/test/util/lib.sh
@@ -195,11 +195,10 @@ function generate_certs_for() {
 	# Generating certs is takes time and slows the tests down, so we keep
 	# a little cache that is common to all tests.
 	CACHEDIR="${TBASE}/../.generate_certs_cache"
-	mkdir -p "${CACHEDIR}"
+	mkdir -p "${CACHEDIR}/$1/"
 	touch -d "10 minutes ago" "${CACHEDIR}/.reference"
-	if [ "${CACHEDIR}/$1/" -ot "${CACHEDIR}/.reference" ]; then
+	if [ "${CACHEDIR}/$1/privkey.pem" -ot "${CACHEDIR}/.reference" ]; then
 		# Cache miss (either was not there, or was too old).
-		mkdir -p "${CACHEDIR}/$1/"
 		(
 			cd "${CACHEDIR}/$1/" || exit 1
 			generate_cert -ca -validfor=1h -host="$1"