Skip to content

Updated App to track attempts in sessions rather then globally#9

Merged
drache42 merged 1 commit intomainfrom
dev/fix-sessions
Apr 19, 2025
Merged

Updated App to track attempts in sessions rather then globally#9
drache42 merged 1 commit intomainfrom
dev/fix-sessions

Conversation

@drache42
Copy link
Owner

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:

  • Modified create_app in src/wakeonlanservice/__init__.py to use instance_relative_config=True and added a default configuration with SECRET_KEY and TESTING values. ([src/wakeonlanservice/__init__.pyL21-L34](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-9f9c5b75d118fb79c9eeac61b8fb5d50f02d0d8d304962eae93f77b0a9e0a50eL21-L34))
  • Updated src/wakeonlanservice/app.py to pass a SECRET_KEY during 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:

  • Introduced session-based tracking for the attempts counter in src/wakeonlanservice/blueprints/status.py, replacing the global current_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:

  • Updated tests/unit/test_app.py to validate the presence and integrity of SECRET_KEY in the app configuration. Removed assertions related to the deprecated ATTEMPTS configuration. ([tests/unit/test_app.pyR17-R31](https://github.com/drache42/WakeOnLanService/pull/9/files#diff-fcbbe89d576bb1122eba8970740c18a3f3eb876b634ed6b62789d7561cae8372R17-R31))
  • Enhanced tests/unit/test_status.py to 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

@drache42 drache42 requested a review from Copilot April 19, 2025 16:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))})

@drache42 drache42 merged commit 781890c into main Apr 19, 2025
8 checks passed
@drache42 drache42 deleted the dev/fix-sessions branch April 19, 2025 16:38
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