diff --git a/src/main/resources/entry-point/rest-webflux/router-functions/config.unit.test.java.mustache b/src/main/resources/entry-point/rest-webflux/router-functions/config.unit.test.java.mustache new file mode 100644 index 00000000..9ef9f419 --- /dev/null +++ b/src/main/resources/entry-point/rest-webflux/router-functions/config.unit.test.java.mustache @@ -0,0 +1,36 @@ +package {{package}}.api.config; + +import {{package}}.api.Handler; +import {{package}}.api.RouterRest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.web.reactive.server.WebTestClient; + +@ContextConfiguration(classes = {RouterRest.class, Handler.class}) +@WebFluxTest +@Import({CorsConfig.class, SecurityHeadersConfig.class}) +class ConfigTest { + + @Autowired + private WebTestClient webTestClient; + + @Test + void corsConfigurationShouldAllowOrigins() { + webTestClient.get() + .uri("/api/usecase/path") + .exchange() + .expectStatus().isOk() + .expectHeader().valueEquals("Content-Security-Policy", + "default-src 'self'; frame-ancestors 'self'; form-action 'self'") + .expectHeader().valueEquals("Strict-Transport-Security", "max-age=31536000;") + .expectHeader().valueEquals("X-Content-Type-Options", "nosniff") + .expectHeader().valueEquals("Server", "") + .expectHeader().valueEquals("Cache-Control", "no-store") + .expectHeader().valueEquals("Pragma", "no-cache") + .expectHeader().valueEquals("Referrer-Policy", "strict-origin-when-cross-origin"); + } + +} \ No newline at end of file diff --git a/src/main/resources/entry-point/rest-webflux/router-functions/definition.json b/src/main/resources/entry-point/rest-webflux/router-functions/definition.json index b4eab2a6..2d50dd19 100644 --- a/src/main/resources/entry-point/rest-webflux/router-functions/definition.json +++ b/src/main/resources/entry-point/rest-webflux/router-functions/definition.json @@ -8,6 +8,7 @@ "entry-point/rest-webflux/cors-config.java.mustache": "infrastructure/entry-points/reactive-web/src/main/java/{{packagePath}}/api/config/CorsConfig.java", "entry-point/rest-webflux/security-headers-filter.java.mustache": "infrastructure/entry-points/reactive-web/src/main/java/{{packagePath}}/api/config/SecurityHeadersConfig.java", "entry-point/rest-webflux/router-functions/router.unit.test.java.mustache": "infrastructure/entry-points/reactive-web/src/test/java/{{packagePath}}/api/RouterRestTest.java", + "entry-point/rest-webflux/router-functions/config.unit.test.java.mustache": "infrastructure/entry-points/reactive-web/src/test/java/{{packagePath}}/api/config/ConfigTest.java", "entry-point/rest-webflux/build.gradle.mustache": "infrastructure/entry-points/reactive-web/build.gradle" } }