CI / test (push) Canceled after 0s
Close two token-leak paths in the git mirror and harden the supply chain per the OWASP audit (audit/2026-08-11/security-report.md). Runtime fixes: - mirror GitError masks the embedded oauth2:<token> in both the failing command line and git's stderr before raising; cli now catches GitError with a clean message instead of an uncaught traceback that printed the live token. - Scrub token-bearing remote URLs from the bare config at the end of each run so tokens aren't persisted in .git/config. - Default mirror workdir is per-user 0700 (/tmp/cb2gitea-<uid>), not a world-readable /tmp/cb2gitea. Supply chain: - Commit uv.lock; CI installs via uv sync --frozen (hash-verified). - Pin Gitea Actions to commit SHAs, not mutable @vN tags. - Pin the ruff rule set and exclude audit/ for reproducible linting. Adds tests/test_mirror.py for the redaction helpers.
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
"""Redaction helpers keep forge tokens out of error text and stored git config.
|
|
|
|
Pure-function checks (no network): ``_authed`` embeds the token in the URL,
|
|
``_redact`` masks it for logs/exceptions, and ``_bare`` strips it for the
|
|
on-disk remote config scrub.
|
|
"""
|
|
|
|
from codeberg_to_gitea_migrator.mirror import _authed, _bare, _redact
|
|
|
|
|
|
def test_redact_masks_token_keeps_url_shape():
|
|
url = _authed("https://codeberg.org/o/r.git", "s3cr3t")
|
|
assert "s3cr3t" not in _redact(url)
|
|
assert _redact(url) == "https://oauth2:***@codeberg.org/o/r.git"
|
|
|
|
|
|
def test_bare_strips_userinfo_entirely():
|
|
url = _authed("https://codeberg.org/o/r.git", "s3cr3t")
|
|
assert _bare(url) == "https://codeberg.org/o/r.git"
|
|
|
|
|
|
def test_handles_percent_encoded_token_chars():
|
|
# A token with a space and '@' is percent-encoded by _authed; both helpers
|
|
# must still match the encoded form up to the literal '@' delimiter.
|
|
url = _authed("https://codeberg.org/o/r.git", "a b@c")
|
|
assert "a%20b%40c" not in _redact(url)
|
|
assert _bare(url) == "https://codeberg.org/o/r.git"
|
|
|
|
|
|
def test_no_token_untouched():
|
|
assert _redact("https://codeberg.org/o/r.git") == "https://codeberg.org/o/r.git"
|
|
assert _bare("https://codeberg.org/o/r.git") == "https://codeberg.org/o/r.git"
|