Updated App to track attempts in sessions rather then globally#9
Merged
Updated App to track attempts in sessions rather then globally#9
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Wake-on-LAN service to use session-based tracking of attempt counts instead of a global counter and updates the configuration and tests accordingly.
- Replace global ATTEMPTS counter with a session-specific counter in the status blueprint.
- Update the app configuration and tests to support session management and enforce the use of a SECRET_KEY.
- Enhance the test suite to verify the new session-based behavior.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_status.py | Updated tests to initialize sessions, patch URL checking, and verify per-session attempt counts. |
| tests/unit/test_app.py | Modified tests to check for the presence of SECRET_KEY and removed deprecated ATTEMPTS assertions. |
| src/wakeonlanservice/blueprints/status.py | Replaced global attempt-tracking with session-based tracking and updated error handling logic. |
| src/wakeonlanservice/app.py | Updated app creation to pass a SECRET_KEY for secure session handling. |
| src/wakeonlanservice/init.py | Enabled instance-relative configuration and configured default settings, removing the global ATTEMPTS counter. |
Comments suppressed due to low confidence (1)
src/wakeonlanservice/app.py:7
- Using a randomly generated SECRET_KEY when one is not provided might lead to session invalidation across application restarts in production. It is recommended to ensure a fixed SECRET_KEY is configured in production environments.
app = create_app({"SECRET_KEY": os.environ.get("SECRET_KEY", os.urandom(24))})
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.
This pull request introduces session-based tracking for the number of attempts in the Wake-on-LAN service, replacing the previous global application state approach. It also enhances the application configuration and updates the corresponding tests to reflect these changes.
Application Configuration Updates:
create_appinsrc/wakeonlanservice/__init__.pyto useinstance_relative_config=Trueand added a default configuration withSECRET_KEYandTESTINGvalues. ([src/wakeonlanservice/__init__.pyL21-L34](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-9f9c5b75d118fb79c9eeac61b8fb5d50f02d0d8d304962eae93f77b0a9e0a50eL21-L34))src/wakeonlanservice/app.pyto pass aSECRET_KEYduring app creation, ensuring secure session handling. ([src/wakeonlanservice/app.pyR3-R8](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-0a87bdac4315a2a87ec46d673b02d7bd8dc2e656dab3d7b5474b0153e7fa7fcfR3-R8))Session-Based Attempt Tracking:
attemptscounter insrc/wakeonlanservice/blueprints/status.py, replacing the globalcurrent_app.config["ATTEMPTS"]. This ensures per-session isolation of the counter. ([[1]](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-8f259fd8657dff014b6e35ec7e32814514b55790783fbe3a496d6a71f67f1d13R30-R33),[[2]](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-8f259fd8657dff014b6e35ec7e32814514b55790783fbe3a496d6a71f67f1d13L54-R61),[[3]](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-8f259fd8657dff014b6e35ec7e32814514b55790783fbe3a496d6a71f67f1d13L70-R85))Test Suite Enhancements:
tests/unit/test_app.pyto validate the presence and integrity ofSECRET_KEYin the app configuration. Removed assertions related to the deprecatedATTEMPTSconfiguration. ([tests/unit/test_app.pyR17-R31](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-fcbbe89d576bb1122eba8970740c18a3f3eb876b634ed6b62789d7561cae8372R17-R31))tests/unit/test_status.pyto include session initialization and mocking for testing session-specific behavior, including multiple app instances and attempt counters. ([[1]](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-1f6a6d9200040e2b045b49c7118ce4ef04d36692c67cf7802961c914a91a46d6R5-R17),[[2]](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-1f6a6d9200040e2b045b49c7118ce4ef04d36692c67cf7802961c914a91a46d6L38-R113))…y configuration