Skip to content

Commit

Permalink
added a property for backend url
Browse files Browse the repository at this point in the history
  • Loading branch information
jamcunha committed Jun 28, 2023
1 parent 413af20 commit 1be6f37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pt.up.fe.ni.website.backend.controller

import org.springframework.beans.factory.annotation.Value
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
Expand All @@ -15,6 +16,9 @@ import pt.up.fe.ni.website.backend.service.AuthService
@RestController
@RequestMapping("/auth")
class AuthController(val authService: AuthService) {
@field:Value("\${backend.url}")
private lateinit var backendUrl: String

@PostMapping("/new")
fun getNewToken(@RequestBody loginDto: LoginDto): Map<String, String> {
val account = authService.authenticate(loginDto.email, loginDto.password)
Expand All @@ -33,7 +37,7 @@ class AuthController(val authService: AuthService) {
fun generateRecoveryToken(@PathVariable id: Long): Map<String, String> {
val recoveryToken = authService.generateRecoveryToken(id)
// TODO: Change URL Later
return mapOf("recovery_url" to "localhost:8080/accounts/recoverPassword/$recoveryToken")
return mapOf("recovery_url" to "$backendUrl/accounts/recoverPassword/$recoveryToken")
}

@GetMapping
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ upload.static-path=classpath:static
# URL that will serve static content
upload.static-serve=http://localhost:3000/static

# Backend URL
backend.url=http://localhost:8080

# Due to a problem with Hibernate, which is using a deprecated property. This should be removed when fixed
# See https://github.com/spring-projects/spring-data-jpa/issues/2717 for more information
spring.jpa.properties.jakarta.persistence.sharedCache.mode=UNSPECIFIED
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.MediaType
import org.springframework.mock.web.MockPart
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete
Expand Down Expand Up @@ -907,6 +908,9 @@ class AccountControllerTest @Autowired constructor(
@NestedTest
@DisplayName("PUT /recoverPassword/{recoveryToken}")
inner class RecoverPassword {
@field:Value("\${backend.url}")
private lateinit var backendUrl: String

private val newPassword = "new-password"

private val parameters = listOf(
Expand All @@ -930,7 +934,7 @@ class AccountControllerTest @Autowired constructor(
mockMvc.perform(post("/auth/recoverPassword/${testAccount.id}"))
.andReturn().response.let { authResponse ->
val recoveryToken = objectMapper.readTree(authResponse.contentAsString)["recovery_url"].asText()
.removePrefix("localhost:8080/accounts/recoverPassword/")
.removePrefix("$backendUrl/accounts/recoverPassword/")
mockMvc.perform(
put("/accounts/recoverPassword/{recoveryToken}", recoveryToken)
.contentType(MediaType.APPLICATION_JSON)
Expand Down

0 comments on commit 1be6f37

Please sign in to comment.