-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: --fresh flag fails to clean cookie_storage and fact_store #3354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bddeb20
fix: --fresh now cleans cookie_storage and fact_store; auth_svc recov…
35c7acd
Add tests proving --fresh cleanup and stale cookie recovery
dae58d3
Address Copilot: remove fact_store from DATA_FILE_GLOBS, narrow Syste…
a6e5101
Fix flake8 F401, asyncio mark, and test teardown cleanup
d406cb3
Fix flake8 E302: add missing blank line before class
60bb5ca
Rewrite test to save/restore BaseWorld state — no leakage to other tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| """Tests for --fresh cleanup and auth_svc cookie recovery.""" | ||
| import copy | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| from app.service.auth_svc import AuthService, CONFIG_API_KEY_RED | ||
| from app.service.data_svc import DATA_FILE_GLOBS | ||
| from app.service.file_svc import FileSvc | ||
| from app.utility.base_world import BaseWorld | ||
|
|
||
|
|
||
| class TestDataFileGlobs: | ||
| """Verify that critical encrypted files are in the --fresh cleanup list.""" | ||
|
|
||
| def test_cookie_storage_in_data_file_globs(self): | ||
| assert any('cookie_storage' in p for p in DATA_FILE_GLOBS), \ | ||
| 'data/cookie_storage must be in DATA_FILE_GLOBS so --fresh cleans it up' | ||
|
|
||
| def test_object_store_in_data_file_globs(self): | ||
| assert any('object_store' in p for p in DATA_FILE_GLOBS), \ | ||
| 'data/object_store must be in DATA_FILE_GLOBS' | ||
|
|
||
|
|
||
|
deacon-mp marked this conversation as resolved.
|
||
| class TestAuthSvcCookieRecovery: | ||
| """Verify auth_svc recovers when cookie_storage has a stale encryption key.""" | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def setup_and_teardown(self): | ||
| self.cookie_path = os.path.join('data', 'cookie_storage') | ||
| # Save existing state | ||
| self._saved_config = copy.deepcopy(BaseWorld._app_configuration) | ||
| # Clean pre-existing cookie | ||
| if os.path.exists(self.cookie_path): | ||
| os.remove(self.cookie_path) | ||
| yield | ||
| # Restore original state — leave no trace | ||
| if os.path.exists(self.cookie_path): | ||
| os.remove(self.cookie_path) | ||
| BaseWorld._app_configuration = self._saved_config | ||
|
|
||
| def _apply_config(self, encryption_key): | ||
| BaseWorld.clear_config() | ||
| BaseWorld.apply_config( | ||
| name='main', | ||
| config={ | ||
| CONFIG_API_KEY_RED: 'abc123', | ||
| 'crypt_salt': 'REPLACE_WITH_RANDOM_VALUE', | ||
| 'encryption_key': encryption_key, | ||
| 'users': { | ||
| 'red': {'reduser': 'redpass'}, | ||
| 'blue': {'blueuser': 'bluepass'} | ||
| }, | ||
| }, | ||
| apply_hash=True | ||
| ) | ||
|
deacon-mp marked this conversation as resolved.
|
||
| FileSvc() | ||
|
|
||
|
deacon-mp marked this conversation as resolved.
deacon-mp marked this conversation as resolved.
|
||
| @pytest.mark.asyncio | ||
| async def test_stale_cookie_does_not_crash_server(self): | ||
| """Cookie encrypted with key A must not crash server when loaded with key B.""" | ||
| from aiohttp import web | ||
|
|
||
| # Round 1: create cookie_storage with key A | ||
| self._apply_config('KEY_ALPHA_123') | ||
| auth1 = AuthService() | ||
| await auth1.apply(app=web.Application(), users=BaseWorld.get_config('users')) | ||
| assert os.path.exists(self.cookie_path), 'cookie_storage should be created' | ||
|
|
||
| # Round 2: switch to key B — before fix this was sys.exit(1) | ||
| self._apply_config('KEY_BETA_456') | ||
| auth2 = AuthService() | ||
| await auth2.apply(app=web.Application(), users=BaseWorld.get_config('users')) | ||
| assert os.path.exists(self.cookie_path), 'cookie_storage should be regenerated' | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.