Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
SyncConfig::realm_url() returns a partial sync url of the
Browse files Browse the repository at this point in the history
form:

/reference/__partial/user-id/identifier

which is needed for partial sync permissions.

Unit test for this form of the realm_url().

Updated sync dependency to 3.0.0-alpha.2
  • Loading branch information
morten-krogh committed Feb 1, 2018
1 parent 436c111 commit cf1381f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -27,3 +27,6 @@ MinSizeRel/

# Linters
compile_commands.json

# vim
*.swp
2 changes: 1 addition & 1 deletion dependencies.list
@@ -1,4 +1,4 @@
REALM_CORE_VERSION=5.1.2
REALM_SYNC_VERSION=2.3.0
REALM_SYNC_VERSION=3.0.0-alpha.2
ANDROID_OPENSSL_VERSION=1.0.2k
REALM_CORE_PACKAGING=2
2 changes: 1 addition & 1 deletion src/sync/sync_config.cpp
Expand Up @@ -57,7 +57,7 @@ std::string SyncConfig::realm_url() const
if (custom_partial_sync_identifier)
return base_url + "/__partial/" + *custom_partial_sync_identifier;

return base_url + "/__partial/" + partial_sync_identifier(*user);
return base_url + "/__partial/" + user->identity() + "/" + partial_sync_identifier(*user);
}

} // namespace realm
22 changes: 21 additions & 1 deletion tests/sync/sync_manager.cpp
Expand Up @@ -46,7 +46,27 @@ bool validate_user_in_vector(std::vector<std::shared_ptr<SyncUser>> vector,

}

TEST_CASE("sync_config: basic functionality", "[sync") {
TEST_CASE("sync_config: realm_url", "[sync]") {
auto cleanup = util::make_scope_exit([=]() noexcept { SyncManager::shared().reset_for_testing(); });
reset_test_directory(base_path);
SyncManager::shared().configure_file_system(base_path, SyncManager::MetadataMode::NoEncryption);

SECTION("realm url should contain user identity") {
const std::string identity = "useridentity";
const std::string auth_server_url = "https://realm.example.org";
auto user = SyncManager::shared().get_user({ identity, auth_server_url }, "dummy_token");
const std::string reference_realm_url = "realm:://example.org:9080/reference";
SyncConfig config {user, reference_realm_url};
config.is_partial = true;

const std::string realm_url = config.realm_url();
const std::string expected_prefix = reference_realm_url + "/__partial/" + identity + "/";
REQUIRE(realm_url.compare(0, expected_prefix.size(), expected_prefix) == 0);
}
}


TEST_CASE("sync_config: basic functionality", "[sync]") {
SECTION("should reject URLs containing \"/__partial/\"") {
auto make_bad_config = [] { SyncConfig{nullptr, "realm://example.org:9080/123456/__partial/realm"}; };
REQUIRE_THROWS(make_bad_config());
Expand Down

0 comments on commit cf1381f

Please sign in to comment.