Skip to content

Add tests for CSRF middleware and versioning deprecation middleware - #1665

Merged
hman38705 merged 2 commits into
solutions-plug:mainfrom
popsman01:drips/1502-1503
Sep 28, 2026
Merged

hman38705 merged 2 commits into
solutions-plug:mainfrom
popsman01:drips/1502-1503

Conversation

@popsman01

Copy link
Copy Markdown
Contributor

Summary

Add tests for CSRF middleware and versioning deprecation middleware

What was solved

#1502 — Add unit tests for CSRF protection middleware

Add focused unit/integration tests for the CSRF protection middleware in services/api/src/csrf.rs, covering allowed-origin pass, mismatched-origin rejection, missing Origin/Referer handling per documented policy, and the X-Api-Key short-circuit path. Tests should live alongside the middleware (a #[cfg(test)] module) or in services/api/tests/csrf_tests.rs, with no production logic changes.

Addressed:

  • Changed: services/api/src/csrf.rs, services/api/tests/csrf_tests.rs, services/api/tests/csrf_tests.rs
  • Add tests covering: matching allowed origin passes
  • Add tests covering: mismatched origin is rejected
  • Add tests covering: missing Origin/Referer on a mutating request is handled per documented policy

#1503 — Add unit tests for API versioning/deprecation middleware

Add a #[cfg(test)] module to services/api/src/versioning.rs covering the deprecation middleware and per-client sampling logic, verifying deprecation headers/links for deprecated versions, absence for current versions, that deprecated_api_calls_total increments on every deprecated request, and that sampling behavior is exercised so refactors can't silently break it.

Addressed:

  • Changed: services/api/src/versioning.rs
  • Add unit tests (in-file #[cfg(test)] module) for services/api/src/versioning.rs
  • Verify deprecation header/link is added for deprecated versions
  • Verify deprecation header/link is omitted for current versions

Changes

  • services/api/src/versioning.rs (modify)
  • services/api/src/csrf.rs (modify)
  • services/api/tests/csrf_tests.rs (create)

Approach

  1. Add unit tests for CSRF protection middleware #1502 — Add unit tests for CSRF protection middleware (Changed: services/api/src/csrf.rs, services/api/tests/csrf_tests.rs, services/api/tests/csrf_tests.rs)
  2. Add unit tests for API versioning/deprecation middleware #1503 — Add unit tests for API versioning/deprecation middleware (Changed: services/api/src/versioning.rs)

Issues

Closes #1502
Closes #1503

@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@popsman01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@hman38705
hman38705 merged commit 1a64e99 into solutions-plug:main Sep 28, 2026
15 of 60 checks passed
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.

Add unit tests for API versioning/deprecation middleware Add unit tests for CSRF protection middleware

2 participants