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:
co-authored by
Claude Opus 4.8
parent
2e609cbea7
commit
b11d1b17a3
@@ -94,6 +94,20 @@ class TestGetEnabledApps:
|
||||
|
||||
assert await client.get_enabled_apps() == {"notes"}
|
||||
|
||||
@pytest.mark.parametrize("body", [{}, {"ocs": None}, {"ocs": {"data": None}}])
|
||||
async def test_malformed_envelope_returns_empty_set(self, body):
|
||||
"""A missing/null ``ocs``/``data`` envelope yields an empty set rather
|
||||
than raising — the scanner then gates every app off, and its own
|
||||
fallback (``_get_enabled_apps_or_none``) keeps indexing safe."""
|
||||
client = _make_client()
|
||||
response = MagicMock()
|
||||
response.raise_for_status = MagicMock()
|
||||
response.json.return_value = body
|
||||
client._client = AsyncMock()
|
||||
client._client.get = AsyncMock(return_value=response)
|
||||
|
||||
assert await client.get_enabled_apps() == set()
|
||||
|
||||
|
||||
class TestNormaliseSearchResult:
|
||||
def test_adds_leading_slash_to_path(self):
|
||||
|
||||
Reference in New Issue
Block a user