Skip to content

test(dashboard-api): cover SHIELD_API_KEY early-return in /privacy-shield/stats#1121

Draft
yasinBursali wants to merge 1 commit intoLight-Heart-Labs:mainfrom
yasinBursali:test/dashboard-api-shield-api-key-empty
Draft

test(dashboard-api): cover SHIELD_API_KEY early-return in /privacy-shield/stats#1121
yasinBursali wants to merge 1 commit intoLight-Heart-Labs:mainfrom
yasinBursali:test/dashboard-api-shield-api-key-empty

Conversation

@yasinBursali
Copy link
Copy Markdown
Contributor

What

Add two pytest cases for the early-return guard introduced by #1069 in GET /api/privacy-shield/stats:

  1. test_privacy_shield_stats_missing_shield_keySHIELD_API_KEY unset
  2. test_privacy_shield_stats_empty_shield_api_keySHIELD_API_KEY=""

Both assert (a) 200 + {"error": "SHIELD_API_KEY not configured", "enabled": False} payload, AND (b) aiohttp.ClientSession.assert_not_called() — the stricter security invariant proving no HTTP machinery is constructed when the key is missing or empty.

Why

Issue requested empty-string parity coverage for the early-return. The assert_not_called() invariant is a security regression guard: a future change that re-introduced the network path when the key is unset would slip past payload-only assertions.

How

26 lines of pure pytest in tests/test_privacy.py. Reuses existing test conventions (test_client + monkeypatch + MagicMock + patch on aiohttp.ClientSession).

Testing

  • pytest tests/test_privacy.py: full file passes
  • pytest -k "shield_api_key or shield_key": 2 passed

Review

Critique Guardian: APPROVED (round 2). Round 1 flagged a redundancy with #1069's existing test; round 2 collapsed: one enhanced missing-case test (with assert_not_called) + one empty-string case, no duplicates.

Known Considerations

Platform Impact

  • macOS / Linux / Windows: identical (pytest, platform-independent).

Must merge after #1069.

…ield/stats

Adds two tests for the early-return guard introduced by PR Light-Heart-Labs#1069
(GET /api/privacy-shield/stats short-circuits with
{"error": "SHIELD_API_KEY not configured", "enabled": False}
when SHIELD_API_KEY is unset or empty):

  - test_privacy_shield_stats_missing_shield_key: SHIELD_API_KEY unset.
    Asserts session_factory.assert_not_called() — the stricter security
    invariant that no aiohttp.ClientSession is constructed (no socket,
    no DNS, no header) when the key is missing.

  - test_privacy_shield_stats_empty_shield_api_key: SHIELD_API_KEY="".
    Same invariant, parity with empty-string input.

Must merge after Light-Heart-Labs#1069. PR Light-Heart-Labs#1069 also
introduces a similar test that this version supersedes; rebase will
de-duplicate when Light-Heart-Labs#1069 lands.
@Lightheartdevs
Copy link
Copy Markdown
Collaborator

Holding this during the merge pass because the live �pi check is failing. Please fix/rebase and rerun CI before review/merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants