import logging from monky_deployd.redact import MASK, Redactor def test_redacts_token_shapes_and_registered_values(): r = Redactor() r.add("pg-s3cret-value") text = "tok hvs.CAESIJabcdefghijklmnopqrstuvwxyz0123456789 jwt eyJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJhZ2VudCJ9.c2lnbmF0dXJlLXNpZw pw=pg-s3cret-value ok" out = r.scrub(text) assert "hvs." not in out and "eyJ" not in out and "pg-s3cret-value" not in out assert out.count(MASK) == 3 assert r.scrub("Authorization: Bearer abc.def") == f"Authorization: Bearer {MASK}" def test_filter_rewrites_records_in_place(): r = Redactor() r.add("SUPERSECRET") rec = logging.LogRecord("x", logging.INFO, "f", 1, "value=%s", ("SUPERSECRET",), None) assert r.filter(rec) is True assert rec.getMessage() == f"value={MASK}" def test_short_values_are_not_registered(): r = Redactor() r.add("ab") assert r.scrub("ab is fine") == "ab is fine"