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
Draft
Conversation
…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.
Collaborator
|
Holding this during the merge pass because the live �pi check is failing. Please fix/rebase and rerun CI before review/merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add two pytest cases for the early-return guard introduced by #1069 in
GET /api/privacy-shield/stats:test_privacy_shield_stats_missing_shield_key—SHIELD_API_KEYunsettest_privacy_shield_stats_empty_shield_api_key—SHIELD_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+patchonaiohttp.ClientSession).Testing
pytest tests/test_privacy.py: full file passespytest -k "shield_api_key or shield_key": 2 passedReview
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
_missing_shield_keytest on a payload-only basis. Rebase will resolve to keep this PR's enhanced version with the no-HTTP-call invariant.Platform Impact
Must merge after #1069.