From 6cf1cd5977f779538684003f02f112e9dbf2e972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Thu, 23 May 2024 10:59:39 +0200 Subject: [PATCH] Fix expected messages on auth errors --- .../kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt | 4 ++++ .../io/realm/kotlin/test/mongodb/common/CredentialsTests.kt | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt index b86783b6f0..af5463f9a4 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/RealmSyncUtils.kt @@ -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 diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt index b666ebb3dc..d76391c980 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt @@ -369,7 +369,7 @@ class CredentialsTests { payload = mapOf("mail" to TestHelper.randomEmail(), "id" to 0) ) - assertFailsWithMessage("Error: Authentication failed.") { + assertFailsWithMessage("unauthorized") { runBlocking { app.login(credentials) } @@ -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) } } }