Option C oc_diagnostics
Loading...
Searching...
No Matches
test_redaction Namespace Reference

Functions

 _prod_on ()
 test_git_url_credentials_stripped ()
 test_github_pat_prefix_redacted_in_bare_text ()
 test_openai_and_slack_prefixes_redacted ()
 test_kv_password_scrubbed_without_configured_pattern ()
 test_kv_api_key_variants_all_redacted ()
 test_redact_secrets_toggle_bypasses_builtins ()
 test_dev_mode_still_skips_all_redaction ()

Variables

 _REPO_ROOT = Path(__file__).resolve().parents[1]

Detailed Description

Purpose
-------
OI-506 / FS-506 — regression coverage for the built-in secret/URL/token
scrubbers added to ``_apply_redaction``. These run unconditionally when
``REDACT_SECRETS`` is True (the default) inside production mode.

The three built-in regexes:

1. ``_GIT_URL_RE``       — strips ``user:token@`` from http(s) URLs.
2. ``_TOKEN_PREFIXES_RE`` — redacts common opaque-prefix tokens
   (GitHub PATs, Slack bot tokens, OpenAI keys, JWTs).
3. ``_KV_SECRET_RE``     — redacts ``secret=value`` / ``secret: value``
   style pairs for a fixed allowlist of key names.

The tests restore ``PROD_MODE`` and ``REDACT_SECRETS`` in ``finally`` so
they never leak state into neighbouring tests.

Diagnostics
-----------
Domain: TEST
Levels:
    L2 — test lifecycle

Contracts
---------
- Built-ins must scrub even when ``REDACTION_PATTERNS`` is empty.
- The ``REDACT_SECRETS=False`` toggle must bypass all three built-ins.
- Dev mode (``PROD_MODE=False``) must never redact.

Function Documentation

◆ _prod_on()

test_redaction._prod_on ( )
protected
Flip PROD_MODE on and return the restore callable.

Definition at line 49 of file test_redaction.py.

Here is the caller graph for this function:

◆ test_dev_mode_still_skips_all_redaction()

test_redaction.test_dev_mode_still_skips_all_redaction ( )
OI-506: PROD_MODE=False short-circuits the full redaction stack.

Definition at line 153 of file test_redaction.py.

◆ test_git_url_credentials_stripped()

test_redaction.test_git_url_credentials_stripped ( )
OI-506: ``https://user:token@host/path`` → ``https://***@host/path``.

Definition at line 63 of file test_redaction.py.

Here is the call graph for this function:

◆ test_github_pat_prefix_redacted_in_bare_text()

test_redaction.test_github_pat_prefix_redacted_in_bare_text ( )
OI-506: ``ghp_…`` tokens outside URL context are still redacted.

Definition at line 77 of file test_redaction.py.

Here is the call graph for this function:

◆ test_kv_api_key_variants_all_redacted()

test_redaction.test_kv_api_key_variants_all_redacted ( )
OI-506: ``api_key``, ``api-key``, and ``apikey`` all match the KV regex.

Definition at line 117 of file test_redaction.py.

Here is the call graph for this function:

◆ test_kv_password_scrubbed_without_configured_pattern()

test_redaction.test_kv_password_scrubbed_without_configured_pattern ( )
OI-506: ``password=…`` is redacted even with no REDACTION_PATTERNS.

Definition at line 103 of file test_redaction.py.

Here is the call graph for this function:

◆ test_openai_and_slack_prefixes_redacted()

test_redaction.test_openai_and_slack_prefixes_redacted ( )
OI-506: ``sk-…`` and ``xoxb-…`` tokens match the prefix regex.

Definition at line 90 of file test_redaction.py.

Here is the call graph for this function:

◆ test_redact_secrets_toggle_bypasses_builtins()

test_redaction.test_redact_secrets_toggle_bypasses_builtins ( )
OI-506: with REDACT_SECRETS=False the three built-ins are inert.

Definition at line 132 of file test_redaction.py.

Variable Documentation

◆ _REPO_ROOT

test_redaction._REPO_ROOT = Path(__file__).resolve().parents[1]
protected

Definition at line 42 of file test_redaction.py.