Skip to content

Commit

Permalink
Fix expected messages on auth errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed May 23, 2024
1 parent cd6cc63 commit 6cf1cd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ internal fun convertAppError(appError: AppError): Throwable {
// Custom JWT
// See https://github.com/10gen/baas/blob/master/authprovider/providers/custom/provider.go
InvalidCredentialsException(msg)
} else if (msg.contains("unauthorized")) {
// Sanitized error messages
// See https://github.com/10gen/baas/pull/14005/files
InvalidCredentialsException(msg)
} else {
// It does not look possible to reliably detect Facebook, Google and Apple
// invalid tokens: https://github.com/10gen/baas/blob/master/authprovider/providers/oauth2/oauth.go#L139
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class CredentialsTests {
payload = mapOf("mail" to TestHelper.randomEmail(), "id" to 0)
)

assertFailsWithMessage<AuthException>("Error: Authentication failed.") {
assertFailsWithMessage<AuthException>("unauthorized") {
runBlocking {
app.login(credentials)
}
Expand All @@ -383,7 +383,7 @@ class CredentialsTests {
}
fail()
} catch (error: AppException) {
assertTrue(error.message!!.contains("authentication via"), error.message)
assertTrue(error.message!!.contains("unauthorized"), error.message)
}
}
}

0 comments on commit 6cf1cd5

Please sign in to comment.