From 072ce418c9f3108767347665f61611f7c2678412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Edelbo?= Date: Wed, 18 Aug 2021 12:40:03 +0200 Subject: [PATCH 1/2] Create custom error code for InvalidPassword response --- how-to-build.md | 2 +- .../object-store/sync/generic_network_transport.cpp | 1 + .../object-store/sync/generic_network_transport.hpp | 1 + test/object-store/sync/app.cpp | 12 ++++++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/how-to-build.md b/how-to-build.md index a8438e8b26a..c75dc35cd3d 100644 --- a/how-to-build.md +++ b/how-to-build.md @@ -181,7 +181,7 @@ To run the [app] tests against the local image, you need to configure a build wi ``` mkdir build.sync.ninja cmake -B build.sync.ninja -G Ninja -DREALM_ENABLE_AUTH_TESTS=1 -DREALM_MONGODB_ENDPOINT=http://localhost:9090 -cmake --build build.sync.ninja --target tests +cmake --build build.sync.ninja --target realm-object-store-tests ./build.sync.ninja/test/object-store/realm-object-store-tests -d=1 ``` ### Developing inside a container diff --git a/src/realm/object-store/sync/generic_network_transport.cpp b/src/realm/object-store/sync/generic_network_transport.cpp index 1ccd78919c2..fc41074a6f2 100644 --- a/src/realm/object-store/sync/generic_network_transport.cpp +++ b/src/realm/object-store/sync/generic_network_transport.cpp @@ -103,6 +103,7 @@ static const std::map service_error_map = { {"AuthError", ServiceErrorCode::auth_error}, {"BadRequest", ServiceErrorCode::bad_request}, {"AccountNameInUse", ServiceErrorCode::account_name_in_use}, + {"InvalidPassword", ServiceErrorCode::invalid_email_password}, {"Unknown", ServiceErrorCode::unknown}, }; diff --git a/src/realm/object-store/sync/generic_network_transport.hpp b/src/realm/object-store/sync/generic_network_transport.hpp index cb88d1186a7..b6f81e2c095 100644 --- a/src/realm/object-store/sync/generic_network_transport.hpp +++ b/src/realm/object-store/sync/generic_network_transport.hpp @@ -91,6 +91,7 @@ enum class ServiceErrorCode { auth_error = 47, bad_request = 48, account_name_in_use = 49, + invalid_email_password = 50, unknown = -1, none = 0 diff --git a/test/object-store/sync/app.cpp b/test/object-store/sync/app.cpp index a50ca9139fb..4cf35814cfa 100644 --- a/test/object-store/sync/app.cpp +++ b/test/object-store/sync/app.cpp @@ -282,6 +282,18 @@ TEST_CASE("app: UsernamePasswordProviderClient integration", "[sync][app]") { CHECK(user->user_profile().email() == email); } + SECTION("cannot login with wrong password") { + app->log_in_with_credentials(realm::app::AppCredentials::username_password(email, "boogeyman"), + [&](std::shared_ptr user, Optional error) { + CHECK(!user); + REQUIRE(error); + REQUIRE(error->error_code.value() == + int(ServiceErrorCode::invalid_email_password)); + processed = true; + }); + CHECK(processed); + } + SECTION("confirm user") { app->provider_client().confirm_user( "a_token", "a_token_id", [&](Optional error) { From 6230749f0a7f2e286d2d5cb8e0f3121220c41baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Edelbo?= Date: Wed, 18 Aug 2021 21:51:23 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f874bed8be9..869c2e4757d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Enhancements * InstructionApplier exceptions now contain information about what object/changeset was being applied when the exception was thrown. ([#4836](https://github.com/realm/realm-core/issues/4836)) +* Added ServiceErrorCode for wrong username/password. ([#4581](https://github.com/realm/realm-core/issues/4581)) ### Fixed * ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)