"""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"