Skip to content

Commit

Permalink
fix(cors): Disabled CORS for development
Browse files Browse the repository at this point in the history
  • Loading branch information
vehagn committed Jan 21, 2024
1 parent 2f2858e commit 18c9cdf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ class SecurityConfiguration {
httpSecurity.csrf { request ->
request.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRequestHandler(CsrfTokenRequestAttributeHandler())
//TODO: DON'T DISABLE CSRF!!!
.disable()
}.authorizeHttpRequests { request ->
request.anyRequest().permitAll()
}
return httpSecurity.build()
}

// @Bean
// fun corsConfigurationSource(): CorsConfigurationSource {
// val configuration = CorsConfiguration()
// configuration.allowedOrigins = listOf("*")
// configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE", "OPTIONS")
// configuration.allowedHeaders = listOf("*")
// configuration.allowCredentials = true
// configuration.maxAge = 3600
// val source = UrlBasedCorsConfigurationSource()
// source.registerCorsConfiguration("/**", configuration)
// return source
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import org.springframework.web.bind.annotation.*
class WalletController(
@Autowired val walletService: WalletService,
) {
@PostMapping("/users/{id}/wallet/buy")

@GetMapping("/users/{id}/wallet", produces = [MediaType.APPLICATION_JSON_VALUE])
fun getWallet(@PathVariable id: Long): UserWalletDTO {
return UserWalletDTO(walletService.getWallet(id))
}

@PostMapping("/users/{id}/wallet/spend")
fun purchase(@PathVariable id: Long, @RequestParam value: Short) {
walletService.purchase(id, value)
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application-test-stonegarden.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
datasource-url: jdbc:postgresql://192.168.1.140:5432/bar
datasource-username: veh
datasource-password: 1QtlsofDJ1zLL40cRWo690UuAo0Ogf4lCpwyzklng1WTnNebxWbPx3ytrNCTSJbD

springdoc:
swagger-ui:
csrf:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class WalletControllerTest(@Autowired val mockMvc: MockMvc) {
fun purchase() {
every { mockWalletService.purchase(any(), any()) } returns UserWallet(testUserA, walletA)
mockMvc
.post(urlTemplate = "/api/v1/users/123/wallet/buy?value=100") { with(csrf()) }
.post(urlTemplate = "/api/v1/users/123/wallet/spend?value=100") { with(csrf()) }
.andExpect {
status { isOk() }
}
Expand Down

0 comments on commit 18c9cdf

Please sign in to comment.