[repo] Hygiene: batched hook (300 files 1.7 s), narrower build/ and JWK rules, more key forms, bash-4 check
This commit is contained in:
@@ -111,6 +111,9 @@ expect reject "PuTTY private key content" putty.txt
|
||||
printf 'not really a key\n' > me.ppk
|
||||
expect reject "*.ppk file name" me.ppk
|
||||
|
||||
printf '# created: 2026\nage-secret-key-%s\n' 1qyz8xrfk3w6j9p2m4n5l7kxqzj5s8tvh3r2w6y9 > lower.txt
|
||||
expect reject "age secret key in lower case" lower.txt
|
||||
|
||||
printf '# created: 2026\nAGE-SECRET-KEY-%s\n' 1QYZ8XRFK3W6J9P2M4N5L7KXQZJ5S8TVH3R2W6Y9 > identity.txt
|
||||
expect reject "age secret key" identity.txt
|
||||
|
||||
@@ -120,9 +123,33 @@ expect reject "JWK private key" key.json
|
||||
printf '{"k%s":"EC","crv":"P-256","x":"f83O","y":"x_FE"}\n' ty > pub.json
|
||||
expect accept "JWK public key" pub.json
|
||||
|
||||
printf '{\n "k%s"\n : "RSA",\n "n": "0vx7",\n "e": "AQAB",\n "d"\n :\n "X4cT"\n}\n' ty > rsa.json
|
||||
expect reject "JWK private key across lines, newline before the colon" rsa.json
|
||||
|
||||
printf '{"keys":[{"k%s":"OKP","crv":"Ed25519","x":"11qY","d":"nWGx"}]}\n' ty > jwks.json
|
||||
expect reject "OKP private key inside a JWKS" jwks.json
|
||||
|
||||
printf '{"jwk":{"k%s":"EC","x":"f83O","y":"x_FE"},"meta":{"d":"2026-11-07"}}\n' ty > mixed.json
|
||||
expect accept "JWK public key with an unrelated \"d\" in another object" mixed.json
|
||||
|
||||
printf '{"k%s":"oct","k":"GawgguFy","d":"not a private-key parameter"}\n' ty > oct.json
|
||||
expect accept "\"d\" with kty oct is not an RSA/EC/OKP private key" oct.json
|
||||
|
||||
printf '[Interface]\nPrivate%s = %s\nAddress = 10.0.0.2/32\n' Key yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk= > wg0.conf
|
||||
expect reject "WireGuard private key" wg0.conf
|
||||
|
||||
printf 'wireguard:\n interface:\n private_%s: yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=\n' key > wg.yaml
|
||||
expect reject "WireGuard private_key in YAML" wg.yaml
|
||||
|
||||
printf 'peers:\n - private_%s: "yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk="\n' key > wg2.yml
|
||||
expect reject "WireGuard private_key in a YAML list, quoted" wg2.yml
|
||||
|
||||
printf 'private_%s_file: /run/secrets/wg\n' key > wg3.yaml
|
||||
expect accept "WireGuard private_key_file path (no key)" wg3.yaml
|
||||
|
||||
printf '*.txt binary\n' > .gitattributes && cp "$SRC/pem" attr.txt && git add .gitattributes
|
||||
expect reject "PEM key in a file .gitattributes marks binary" attr.txt
|
||||
|
||||
printf 'not really a key\n' > server.key
|
||||
expect reject "*.key file name" server.key
|
||||
|
||||
@@ -163,7 +190,23 @@ mkdir -p apps/web/dist && printf 'x\n' > apps/web/dist/index.html
|
||||
expect reject "file under dist/" apps/web/dist/index.html
|
||||
|
||||
mkdir -p apps/web/build && printf 'x\n' > apps/web/build/index.html
|
||||
expect reject "file under build/" apps/web/build/index.html
|
||||
expect reject "file under apps/<app>/build/" apps/web/build/index.html
|
||||
|
||||
mkdir -p build && printf 'x\n' > build/out.js
|
||||
expect reject "file under build/ at the root" build/out.js
|
||||
|
||||
mkdir -p crates/x/src/build && printf 'pub mod x;\n' > crates/x/src/build/mod.rs
|
||||
expect accept "source module named build (crates/x/src/build/mod.rs)" crates/x/src/build/mod.rs
|
||||
|
||||
mkdir -p apps/web/src/build && printf 'x\n' > apps/web/src/build/x.ts
|
||||
expect accept "apps/web/src/build/ is not output" apps/web/src/build/x.ts
|
||||
|
||||
mkdir -p packages/ui/build && printf '{}\n' > packages/ui/package.json && printf 'x\n' > packages/ui/build/ui.js
|
||||
git add packages/ui/package.json
|
||||
expect reject "build/ next to a package.json" packages/ui/build/ui.js
|
||||
|
||||
mkdir -p docs/build && printf 'x\n' > docs/build/notes.md
|
||||
expect accept "build/ with no package.json beside it" docs/build/notes.md
|
||||
|
||||
mkdir -p apps/web/.svelte-kit && printf 'x\n' > apps/web/.svelte-kit/env.js
|
||||
expect reject "file under .svelte-kit/" apps/web/.svelte-kit/env.js
|
||||
@@ -177,5 +220,33 @@ expect_staged reject "PEM key in a file named with a newline" "$(printf 'new\nli
|
||||
printf 'fine\n' > "$SRC/fine"
|
||||
expect_staged accept "harmless file named with a double quote" 'say"hi".txt' "$SRC/fine"
|
||||
|
||||
# Bash 3 or a POSIX sh: the hook refuses with a clear message. Only testable where sh is
|
||||
# not bash (dash on Debian); Git Bash's sh is bash.
|
||||
if [ -z "$(sh -c 'echo "${BASH_VERSION:-}"')" ]; then
|
||||
printf 'x\n' > shtest.txt && git add shtest.txt
|
||||
if sh "$HOOKS/pre-commit" 2>"$WORK/.err"; then
|
||||
fail=$((fail + 1)); echo "FAIL the hook ran under a shell that is not bash 4"
|
||||
elif grep -q 'needs bash 4' "$WORK/.err"; then
|
||||
pass=$((pass + 1)); echo "ok reject run by sh (not bash): clear message"
|
||||
else
|
||||
fail=$((fail + 1)); echo "FAIL no clear message under sh:"; cat "$WORK/.err"
|
||||
fi
|
||||
git reset -q --hard HEAD; git clean -q -fdx -e .err
|
||||
else
|
||||
echo "skip sh is bash here; the bash-4 check is exercised where sh is dash"
|
||||
fi
|
||||
|
||||
# Speed: 300 ordinary files in one commit.
|
||||
mkdir -p many
|
||||
for n in $(seq 1 300); do printf 'line %d\n' "$n" > "many/f$n.txt"; done
|
||||
git add many
|
||||
start=$(date +%s%N)
|
||||
commit_and_check accept "300 ordinary files in one commit"
|
||||
ms=$(( ($(date +%s%N) - start) / 1000000 ))
|
||||
printf ' (300 files: %d ms)\n' "$ms"
|
||||
if [ "$ms" -gt 10000 ]; then
|
||||
fail=$((fail + 1)); echo "FAIL 300 files took over 10 s"
|
||||
fi
|
||||
|
||||
printf '\nhook: %d passed, %d failed\n' "$pass" "$fail"
|
||||
[ "$fail" -eq 0 ]
|
||||
|
||||
Reference in New Issue
Block a user