|
Option C oc_diagnostics
|
Functions | |
| test_safe_env_path_accepts_normal_value (monkeypatch) | |
| test_safe_env_path_rejects_nul_byte (monkeypatch) | |
| test_safe_env_path_rejects_over_length (monkeypatch) | |
| test_safe_env_path_empty_returns_empty (monkeypatch) | |
| test_oversized_config_falls_back_to_defaults (monkeypatch) | |
| test_normal_sized_config_still_loads (monkeypatch, tmp_path) | |
Variables | |
| _REPO_ROOT = Path(__file__).resolve().parents[1] | |
Purpose
-------
OI-515 — verify ``OC_DIAGNOSTICS_*`` env-var containment rules.
``_safe_env_path`` rejects empty, NUL-bearing, and over-length paths so
an operator-supplied (or attacker-supplied) env var cannot push pathological
values into the config loader or log directory resolver.
``_load_debug_config`` additionally refuses to read a config file larger
than ``_MAX_CONFIG_BYTES`` (10 MiB) and falls back to the in-module
defaults, so a pathological config can't blow memory at import time.
Diagnostics
-----------
Domain: TEST
Levels:
L2 — test lifecycle
Contracts
---------
- ``_safe_env_path`` must never return a value containing ``\\0``.
- The config loader must not raise when the file exceeds the cap; it
must fall back to defaults and mark ``config_source`` accordingly.
| test_env_containment.test_normal_sized_config_still_loads | ( | monkeypatch, | |
| tmp_path ) |
OI-515: a reasonably-sized config still loads normally.
Definition at line 101 of file test_env_containment.py.
| test_env_containment.test_oversized_config_falls_back_to_defaults | ( | monkeypatch | ) |
OI-515: a >10 MiB config file is skipped; defaults are returned.
Definition at line 85 of file test_env_containment.py.
| test_env_containment.test_safe_env_path_accepts_normal_value | ( | monkeypatch | ) |
OI-515: typical paths round-trip unchanged through _safe_env_path.
Definition at line 46 of file test_env_containment.py.
| test_env_containment.test_safe_env_path_empty_returns_empty | ( | monkeypatch | ) |
OI-515: missing or whitespace-only env var returns ``''``.
Definition at line 77 of file test_env_containment.py.
| test_env_containment.test_safe_env_path_rejects_nul_byte | ( | monkeypatch | ) |
OI-515: NUL bytes are refused and the env var is treated as unset. ``os.environ`` itself refuses to store ``\\x00`` on most platforms, so we patch ``os.environ.get`` directly to simulate the hostile input.
Definition at line 52 of file test_env_containment.py.
| test_env_containment.test_safe_env_path_rejects_over_length | ( | monkeypatch | ) |
OI-515: values over _MAX_ENV_PATH_LEN chars are refused.
Definition at line 68 of file test_env_containment.py.
|
protected |
Definition at line 39 of file test_env_containment.py.