Files
felhom.eu/scripts/test_git_credential_sec.py
T
admin b79f9e1673
gates / gates (push) Successful in 3m41s
git-credential-sec: the token goes to https://gitea.dooplex.hu only (R-925)
The helper answered any server git asked about. It now reads protocol and host and answers one server.
Test: scripts/test_git_credential_sec.py (7 cases; red-proofed, 4 fail against the old helper).

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-11-11 15:22:51 +01:00

38 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Pins scripts/git-credential-sec.sh: the token goes to https://gitea.dooplex.hu and to no other server."""
import os, subprocess, sys
HELPER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "git-credential-sec.sh")
VALUE = "dummy-value-not-a-secret"
def ask(proto, host, token=VALUE, verb="get"):
env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin")}
if token is not None:
env["GITEA_GIT_TOKEN"] = token
p = subprocess.run(["sh", HELPER, verb], input=f"protocol={proto}\nhost={host}\n\n", text=True,
capture_output=True, env=env, timeout=10)
return p.stdout, p.stderr
CASES = [ # (name, proto, host, token, verb, gives the value?)
("the right server gets the value", "https", "gitea.dooplex.hu", VALUE, "get", True),
("another host gets nothing", "https", "evil.example", VALUE, "get", False),
("a look-alike host gets nothing", "https", "gitea.dooplex.hu.evil.example", VALUE, "get", False),
("the right host on a port gets nothing", "https", "gitea.dooplex.hu:8443", VALUE, "get", False),
("plain http gets nothing", "http", "gitea.dooplex.hu", VALUE, "get", False),
("no token in the environment gives nothing", "https", "gitea.dooplex.hu", None, "get", False),
("store is not answered", "https", "gitea.dooplex.hu", VALUE, "store", False),
]
bad = 0
for name, proto, host, token, verb, want in CASES:
out, err = ask(proto, host, token, verb)
got = VALUE in out
leak = VALUE in err
ok = got == want and not leak and (want or verb != "get" or "quit=true" in out)
print(("ok " if ok else "FAIL ") + name)
bad += 0 if ok else 1
print(f"git-credential-sec: {len(CASES) - bad} of {len(CASES)} passed")
sys.exit(1 if bad else 0)