Skip to content

Commit 9894889

Browse files
authored
RCORE-2100: Restore ability to create test users (#7632)
* Restore ability to create test users * Switch to fake user after creating it
1 parent 816920b commit 9894889

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
55
* Add `SyncClientConfig::security_access_group` which allows specifying the access group to use for the sync metadata Realm's encryption key. Setting this is required when sharing the metadata Realm between apps on Apple platforms ([#7552](https://github.com/realm/realm-core/pull/7552)).
66
* When connecting to multiple server apps, a unique encryption key is used for each of the metadata Realms rather than sharing one between them ([#7552](https://github.com/realm/realm-core/pull/7552)).
7-
* Introduce the new `SyncUser` interface which can be implemented by SDKs to use sync without the core App Services implementation (or just for greater control over user behavior in tests). ([PR #7300](https://github.com/realm/realm-core/pull/7300).
7+
* Introduce the new `SyncUser` interface which can be implemented by SDKs to use sync without the core App Services implementation (or just for greater control over user behavior in tests). ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
88
* Improve perfomance of "chained OR equality" queries for UUID/ObjectId types and RQL parsed "IN" queries on string/int/uuid/objectid types. ([.Net #3566](https://github.com/realm/realm-dotnet/issues/3566), since the introduction of these types)
99
* Introducing `Query::in()` which allows SDKs to take advantage of improved performance when building equality conditions against many constants. ([#7582](https://github.com/realm/realm-core/pull/7582))
1010

@@ -34,12 +34,13 @@
3434
- SyncUser::all_sessions() -> SyncManager::get_all_sessions_for(User&)
3535
- SyncManager::immediately_run_file_actions() -> App::immediately_run_file_actions()
3636
- realm_sync_user_subscription_token -> realm_app_user_subscription_token
37-
([PR #7300](https://github.com/realm/realm-core/pull/7300).
38-
* The `ClientAppDeallocated` error code no longer exists as this error code can no longer occur. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
39-
* Some fields have moved from SyncClientConfig to AppConfig. AppConfig now has a SyncClientConfig field rather than it being passed separately to App::get_app(). ([PR #7300](https://github.com/realm/realm-core/pull/7300).
40-
* Sync user management has been removed from SyncManager. This functionality was already additionally available on App. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
41-
* AuditConfig now has a base_file_path field which must be set by the SDK rather than inheriting it from the SyncManager. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
42-
* App::switch_user() no longer returns a user. The return value was always exactly the passed-in user and any code which needs it can just use that. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
37+
- SyncManager::get_user -> App::create_fake_user_for_testing
38+
([PR #7300](https://github.com/realm/realm-core/pull/7300)).
39+
* The `ClientAppDeallocated` error code no longer exists as this error code can no longer occur. ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
40+
* Some fields have moved from SyncClientConfig to AppConfig. AppConfig now has a SyncClientConfig field rather than it being passed separately to App::get_app(). ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
41+
* Sync user management has been removed from SyncManager. This functionality was already additionally available on App. ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
42+
* AuditConfig now has a base_file_path field which must be set by the SDK rather than inheriting it from the SyncManager. ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
43+
* App::switch_user() no longer returns a user. The return value was always exactly the passed-in user and any code which needs it can just use that. ([PR #7300](https://github.com/realm/realm-core/pull/7300)).
4344
* Non-streaming download progress callback no longer stops reporting values immediately after the registration (if the progress update has happened earlier), but waits for the next batch of data to start syncing to report its progress, since the previous behaviour was not useful (PR [#7561](https://github.com/realm/realm-core/issues/7561)).
4445

4546
### Compatibility

src/realm/object-store/sync/app.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,22 @@ void App::link_user(const std::shared_ptr<User>& user, const AppCredentials& cre
976976
log_in_with_credentials(credentials, user, std::move(completion));
977977
}
978978

979+
std::shared_ptr<User> App::create_fake_user_for_testing(const std::string& user_id, const std::string& access_token,
980+
const std::string& refresh_token)
981+
{
982+
std::shared_ptr<User> user;
983+
{
984+
m_metadata_store->create_user(user_id, refresh_token, access_token, "fake_device");
985+
util::CheckedLockGuard lock(m_user_mutex);
986+
user_data_updated(user_id); // FIXME: needs to be callback from metadata store
987+
user = get_user_for_id(user_id);
988+
}
989+
990+
switch_user(user);
991+
return user;
992+
}
993+
994+
979995
void App::refresh_custom_data(const std::shared_ptr<User>& user,
980996
UniqueFunction<void(Optional<AppError>)>&& completion)
981997
{

src/realm/object-store/sync/app.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ class App : public std::enable_shared_from_this<App>,
184184
util::UniqueFunction<void(std::optional<AppError>)>&& completion)
185185
REQUIRES(!m_route_mutex, !m_user_mutex);
186186

187+
/// Creates a fake user with the provided access and refresh tokens. No validation is done to ensure that the
188+
/// credentials are actually valid and as such, this should only be used for testing purposes.
189+
/// @param user_id The id of the user that will be created
190+
/// @param access_token The access token of the user
191+
/// @param refresh_token The refresh token of the user
192+
std::shared_ptr<User> create_fake_user_for_testing(const std::string& user_id, const std::string& access_token,
193+
const std::string& refresh_token);
194+
187195
// MARK: - Provider Clients
188196

189197
/// A struct representing a user API key as returned by the App server.

0 commit comments

Comments
 (0)