diff --git a/src/main/kotlin/com/fiap/order/config/JWTSecurityConfig.kt b/src/main/kotlin/com/fiap/order/config/JWTSecurityConfig.kt index 465d549..bc76867 100644 --- a/src/main/kotlin/com/fiap/order/config/JWTSecurityConfig.kt +++ b/src/main/kotlin/com/fiap/order/config/JWTSecurityConfig.kt @@ -20,11 +20,7 @@ import org.springframework.security.web.SecurityFilterChain bearerFormat = "JWT", scheme = "bearer" ) -@ConditionalOnProperty( - value = ["security.enable"], - havingValue = "true", - matchIfMissing = true -) +@ConditionalOnProperty(value = ["security.enable"], havingValue = "true", matchIfMissing = true) class JWTSecurityConfig { @Bean fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { diff --git a/src/test/kotlin/com/fiap/order/TestAnnotations.kt b/src/test/kotlin/com/fiap/order/TestAnnotations.kt index 28d7e1f..c888703 100644 --- a/src/test/kotlin/com/fiap/order/TestAnnotations.kt +++ b/src/test/kotlin/com/fiap/order/TestAnnotations.kt @@ -1,5 +1,6 @@ package com.fiap.order +import com.fiap.order.it.JWTSecurityTestConfig import com.fiap.order.it.LocalStackContainerInitializer import com.fiap.order.it.PostgreSQLContainerInitializer import com.fiap.order.it.LocalStackTestConfig @@ -25,6 +26,7 @@ annotation class IntegrationTest LocalStackTestConfig::class, FeignAutoConfiguration::class, ServletWebServerFactoryAutoConfiguration::class, + JWTSecurityTestConfig::class, ] ) @Target(AnnotationTarget.CLASS, AnnotationTarget.FILE) diff --git a/src/test/kotlin/com/fiap/order/it/JWTSecurityTestConfig.kt b/src/test/kotlin/com/fiap/order/it/JWTSecurityTestConfig.kt new file mode 100644 index 0000000..a7ddd1f --- /dev/null +++ b/src/test/kotlin/com/fiap/order/it/JWTSecurityTestConfig.kt @@ -0,0 +1,27 @@ +package com.fiap.order.it + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.security.config.annotation.web.builders.HttpSecurity +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity +import org.springframework.security.web.SecurityFilterChain + +@Configuration +@EnableWebSecurity +@ConditionalOnProperty(name = ["security.enable"], havingValue = "false") +class JWTSecurityTestConfig { + + @Bean + fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { + http + .csrf { csrf -> + csrf.disable() + } + .authorizeHttpRequests { authorize -> + authorize.anyRequest().permitAll() + } + + return http.build() + } +} \ No newline at end of file