28eebbc95a
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/212 Reviewed-by: Marc Sandlus <hsh-marcsandlus@noreply.dev.hostsharing.net>
1.5 KiB
1.5 KiB
PR#212: CORS-config using spring-props and adding tests
The Problems
- CORS handling was configured via
System.getenv("ALLOWED_ORIGINS")inHsadminNgApplication, which made configuration and testing harder. - Spring Security had CORS disabled, so CORS behavior was not aligned with the security filter chain.
/api/pongonly supportedGET, which limited testing and client integration scenarios for CORS-enabled protected endpoints.
In total, with this PR we want the CORS configuration to work properly and to be configurable for:
- prod env
- dev env
- local env
- JUnit-based tests
The Solution
- Introduced a
WebMvcConfigurerbean that readshsadminng.cors.allowed-originsand applies origin and method rules for/api/**. - Kept
/api/pingexplicitly open forGETfrom any origin to preserve its public health-check style behavior. - Added CORS integration tests for preflight and actual requests, including allowed and denied origins and unauthorized token scenarios.
- Added
POST /api/pongto the OpenAPI definition and implementedpongPost()inPingControllerusing the same response logic aspong(). - Added REST and acceptance tests for
POST /api/pongto verify translated responses and authenticated behavior.
Additional Changes
- Moved CORS configuration into
BaseWebSecurityConfig, thus it's closer to related configurations. - Included cleanup changes from rebasing and cyclic reference fixes while keeping the final behavior covered by tests.
Attachments
None.