Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Korjataan väärinymmärrys Suomi.fi REST salasanan vaihdossa #5917

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ class MockSfiMessagesRestEndpoint {
@RequestBody body: ChangePasswordRequestBody,
): ResponseEntity<Any> =
lock.withLock {
val accessToken = authorization?.removePrefix("Bearer ")
val accessToken = body.accessToken
if (!tokens.contains(accessToken)) {
ResponseEntity.status(401).body(ApiError("Invalid token"))
} else if (body.accessToken != accessToken) {
ResponseEntity.status(400).body(ApiError("Invalid token in body"))
ResponseEntity.status(400).body(ApiError("Invalid token"))
} else if (body.currentPassword != password) {
ResponseEntity.status(400).body(ApiError("Invalid password"))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,19 @@ class SfiMessagesRestClientIntegrationTest : FullApplicationTest(resetDbBeforeEa
client.send(message)
assertEquals(1, MockSfiMessagesRestEndpoint.getCapturedMessages().size)
}

@Test
fun `password change handles access token expiry gracefully`() {
client.send(message)
assertEquals(1, MockSfiMessagesRestEndpoint.getCapturedMessages().size)
MockSfiMessagesRestEndpoint.clearTokens()
val oldPassword = MockSfiMessagesRestEndpoint.getCurrentPassword()
client.rotatePassword()
val newPassword = MockSfiMessagesRestEndpoint.getCurrentPassword()
assertNotEquals(oldPassword, newPassword)

// sending a message should still work after password change
client.send(message)
assertEquals(1, MockSfiMessagesRestEndpoint.getCapturedMessages().size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,11 @@ class SfiMessagesRestClient(
}
}

val authorization = authorizationHeader.get()
val accessToken = authorization.value.removePrefix("Bearer ")
val accessToken = getAccessToken(current.password)
httpClient
.newCall(
Request.Builder()
.url(config.urls.changePassword)
.header("Authorization", authorizationHeader.get().value)
.header("Accept", "application/json")
.post(
jsonRequestBody(
Expand Down