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

RCORE-2100: Restore ability to create test users #7632

Merged
merged 2 commits into from
Apr 26, 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
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* 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)).
* 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)).
* 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).
* 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)).
* 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)
* 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))

Expand Down Expand Up @@ -34,12 +34,13 @@
- SyncUser::all_sessions() -> SyncManager::get_all_sessions_for(User&)
- SyncManager::immediately_run_file_actions() -> App::immediately_run_file_actions()
- realm_sync_user_subscription_token -> realm_app_user_subscription_token
([PR #7300](https://github.com/realm/realm-core/pull/7300).
* 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).
* 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).
* 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).
* 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).
* 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).
- SyncManager::get_user -> App::create_fake_user_for_testing
([PR #7300](https://github.com/realm/realm-core/pull/7300)).
* 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)).
* 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)).
* 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)).
* 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)).
* 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)).
* 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)).

### Compatibility
Expand Down
16 changes: 16 additions & 0 deletions src/realm/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,22 @@ void App::link_user(const std::shared_ptr<User>& user, const AppCredentials& cre
log_in_with_credentials(credentials, user, std::move(completion));
}

std::shared_ptr<User> App::create_fake_user_for_testing(const std::string& user_id, const std::string& access_token,
const std::string& refresh_token)
{
std::shared_ptr<User> user;
{
m_metadata_store->create_user(user_id, refresh_token, access_token, "fake_device");
util::CheckedLockGuard lock(m_user_mutex);
user_data_updated(user_id); // FIXME: needs to be callback from metadata store
user = get_user_for_id(user_id);
}

switch_user(user);
return user;
}


void App::refresh_custom_data(const std::shared_ptr<User>& user,
UniqueFunction<void(Optional<AppError>)>&& completion)
{
Expand Down
8 changes: 8 additions & 0 deletions src/realm/object-store/sync/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ class App : public std::enable_shared_from_this<App>,
util::UniqueFunction<void(std::optional<AppError>)>&& completion)
REQUIRES(!m_route_mutex, !m_user_mutex);

/// Creates a fake user with the provided access and refresh tokens. No validation is done to ensure that the
/// credentials are actually valid and as such, this should only be used for testing purposes.
/// @param user_id The id of the user that will be created
/// @param access_token The access token of the user
/// @param refresh_token The refresh token of the user
std::shared_ptr<User> create_fake_user_for_testing(const std::string& user_id, const std::string& access_token,
const std::string& refresh_token);

// MARK: - Provider Clients

/// A struct representing a user API key as returned by the App server.
Expand Down
Loading