Skip to content

Conversation

@ReenigneArcher
Copy link
Member

@ReenigneArcher ReenigneArcher commented Jan 30, 2026

Description

Initial motivation for the PR was to consolidate multiple individual HTML page handler functions into a single getPage function. This works by providing the page as a parameter. Then HTTP handler functions were updated to take response and request by const reference, which was a clang-tidy suggestion. New helper functions for page handlers were added to simplify the server route setup.

Introduced check_request_body_empty to validate that certain API endpoints receive no request body, replacing previous content-type checks where appropriate. I am not 100% sure if this is necessary. Docs were updated to only include the Content-Type headers when necessary.

Also, added some initial tests for confighttp.cpp/h.

Lastly, I had to add macros to ignore some error/warnings in tests/tests_common.h due to failures in the ArchLinux build. I am not fully understanding what caused these errors to start occurring.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@codecov
Copy link

codecov bot commented Jan 30, 2026

Bundle Report

Changes will increase total bundle size by 740 bytes (0.1%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sunshine-esm 771.45kB 740 bytes (0.1%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: sunshine-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/_plugin-*.js 307 bytes 350.12kB 0.09%
assets/config-*.js 433 bytes 67.53kB 0.65%

Files in assets/_plugin-*.js:

  • ./src_assets/common/assets/web/public/assets/locale/en.json → Total Size: 37.59kB

Files in assets/config-*.js:

  • ./src_assets/common/assets/web/configs/tabs/Network.vue → Total Size: 13.28kB

  • ./src_assets/common/assets/web/config.html → Total Size: 0 bytes

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 30.12048% with 174 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.37%. Comparing base (f59e6aa) to head (b1252cf).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/confighttp.cpp 33.93% 101 Missing and 45 partials ⚠️
src/config.cpp 0.00% 23 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4645      +/-   ##
==========================================
+ Coverage   15.49%   16.37%   +0.88%     
==========================================
  Files          94       94              
  Lines       19248    19336      +88     
  Branches     8907     8962      +55     
==========================================
+ Hits         2982     3167     +185     
- Misses      12868    14558    +1690     
+ Partials     3398     1611    -1787     
Flag Coverage Δ
Archlinux 12.77% <24.12%> (+1.16%) ⬆️
FreeBSD-14.3-aarch64 ?
FreeBSD-14.3-amd64 14.69% <20.64%> (+0.95%) ⬆️
Homebrew-ubuntu-22.04 15.21% <29.38%> (+1.29%) ⬆️
Linux-AppImage 13.19% <29.38%> (+1.26%) ⬆️
Windows-AMD64 14.67% <27.94%> (+1.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/config.h 0.00% <ø> (ø)
src/config.cpp 3.05% <0.00%> (+0.01%) ⬆️
src/confighttp.cpp 21.04% <33.93%> (+21.04%) ⬆️

... and 46 files with indirect coverage changes

@ReenigneArcher ReenigneArcher force-pushed the refactor/confighttp/common-functions branch 2 times, most recently from edee013 to 1f0d6d4 Compare January 30, 2026 21:42
@ReenigneArcher ReenigneArcher force-pushed the refactor/confighttp/common-functions branch 4 times, most recently from c5b6f8f to 129fe3d Compare January 31, 2026 02:54
Consolidated multiple individual HTML page handler functions into a single getPage function that serves different HTML files based on parameters. Updated server route bindings to use the new generic handler, reducing code duplication and improving maintainability.
Updated all HTTP handler functions to take const reference parameters for response and request objects, improving const-correctness and clarity. Introduced a helper for page handlers and refactored server route setup to use concise lambda expressions and handler typedefs, reducing code duplication and improving maintainability.
Introduced check_request_body_empty to validate that certain API endpoints receive no request body, replacing previous content-type checks where appropriate. This improves request validation and ensures correct client usage for endpoints that do not expect a body.
Updated function signatures in confighttp.cpp to ensure consistent spacing between type and parameter names, improving code readability and style consistency.
Refactors the generateExamples function to only include Content-Type headers and body parameters in cURL, JavaScript, and PowerShell examples when a request body is present. This prevents unnecessary headers and parameters in generated code samples for endpoints that do not require a body.
Add initial unit tests for confighttp using a real HTTPS client/server (tests/unit/test_confighttp.cpp). Update confighttp public API and types: add necessary includes (nlohmann::json, Simple-Web-Server), introduce HTTPS type aliases (https_server_t, resp_https_t, req_https_t), and declare helper functions (print_req, send_response, send_unauthorized, send_redirect, authenticate, not_found, bad_request, check_* utilities, getPage, etc.). Align implementations in src/confighttp.cpp with the header by removing default parameters from not_found, bad_request, and getPage signatures. These changes improve test coverage and clarify the confighttp interface.
Wrap test header includes with #pragma GCC diagnostic push/pop to ignore -Warray-bounds and -Wstringop-overflow on GCC (excluding clang). This suppresses known false-positive warnings originating from Boost.Asio's basic_resolver_results.hpp on some GCC versions (notably observed on Arch Linux) and restores diagnostics after the includes.
Rename confighttp::getNodeModules to confighttp::getAsset and update the server resource mapping. Add function declarations for getAsset and getLocale to confighttp.h. Expand unit tests (tests/unit/test_confighttp.cpp): include iostream, persist/restore locale in setup/teardown, create a test HTML file in WEB_DIR, register multiple test routes exercising send_response, send_redirect, check_content_type, check_request_body_empty, getPage, and getLocale, and add many corresponding test cases to improve coverage and validate headers, content types, redirects, auth behavior, and JSON responses.
@ReenigneArcher ReenigneArcher force-pushed the refactor/confighttp/common-functions branch from 8b8ffcf to d19f7c2 Compare January 31, 2026 15:08
Override SUNSHINE_ASSETS_DIR in tests to ${CMAKE_CURRENT_BINARY_DIR}/test_assets so tests use a writable assets directory. Update test_confighttp setup to create a temporary web directory, use std::filesystem::create_directories for WEB_DIR, and write test_page.html directly (removing the previous try/catch and existence checks). These changes simplify test setup and ensure test files are created in writable temp locations.
@ReenigneArcher ReenigneArcher force-pushed the refactor/confighttp/common-functions branch from d19f7c2 to cb500b9 Compare January 31, 2026 15:29
@ReenigneArcher ReenigneArcher marked this pull request as draft January 31, 2026 15:56
Implement CSRF protection across HTTP API endpoints and expose a token endpoint. Changes include:

- Add docs: API and configuration docs updated to describe CSRF protection and the new GET /api/csrf-token endpoint.
- Config: add csrf_allowed_origins to config struct; parse comma-separated origin lists; include built-in localhost defaults and append web UI port-specific origins once port is known.
- confighttp: implement CSRF token generation, storage (with expiration), client identification, and validation logic. Validation allows same-origin requests via Origin/Referer to bypass tokens and requires X-CSRF-Token header or csrf_token query param for cross-origin requests. Register GET /api/csrf-token and integrate validation into state-changing endpoints.
- Web UI: add form field and localization strings for csrf_allowed_origins and include it in config HTML.
- Tests: add unit tests for CSRF token generation, header/query validation, same-origin exemptions, and restore/cleanup of config state.

Also remove usages of the old empty-body checker where CSRF/authentication flow was applied. This commit wires CSRF protection end-to-end (docs, config, server, UI, and tests).
@ReenigneArcher ReenigneArcher force-pushed the refactor/confighttp/common-functions branch from 38816e8 to b1252cf Compare February 1, 2026 20:40
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 1, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
28 New issues
7.4% Duplication on New Code (required ≤ 2%)
10 Duplicated Blocks on New Code (required ≤ 0)
28 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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