test(vector): address PR #873 round-1 review

- Extract `_app_enabled` to a module-level helper so the gate predicate is
  unit-tested directly instead of via an inline copy that could drift.
- Move `import logging` to module scope in test_scanner_app_gating.py.
- Harden `get_enabled_apps` OCS-envelope parsing (`X or {}` / `or []`) so a
  present-but-null `ocs`/`data` coerces to empty instead of raising on
  `None.get`; add parametrized malformed-envelope tests.
- Use https:// in the test request URL (SonarCloud S5332 hotspot).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-07 20:04:00 +02:00
co-authored by Claude Opus 4.8
parent 2e609cbea7
commit b11d1b17a3
4 changed files with 51 additions and 23 deletions
+5 -1
View File
@@ -214,7 +214,11 @@ class NextcloudClient:
)
response.raise_for_status()
data = response.json()
entries = data.get("ocs", {}).get("data", []) or []
# ``X or {}``/``or []`` (not ``.get(k, default)``) so a present-but-null
# ``ocs``/``data`` (``{"ocs": null}``) coerces to empty instead of
# raising AttributeError on ``None.get``.
ocs = data.get("ocs") or {}
entries = ocs.get("data") or []
enabled: set[str] = set()
for entry in entries:
# ``app`` is the canonical app id; ``id`` matches it for the apps we