Ejemplo n.º 1
0
        public void GetInstanceAsync_Cancel_ShouldCancelWait()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var config = await SyncTestHelpers.GetIntegrationConfigAsync("foo");
                await PopulateData(config);
                // Update config to make sure we're not opening the same Realm file.
                config = new FullSyncConfiguration(config.ServerUri, config.User, config.DatabasePath + "1");

                using (var cts = new CancellationTokenSource())
                {
                    var _ = Task.Run(async() =>
                    {
                        await Task.Delay(1);
                        cts.Cancel();
                    });

                    try
                    {
                        var realm = await Realm.GetInstanceAsync(config, cts.Token);
                        CleanupOnTearDown(realm);
                        Assert.Fail("Expected task to be cancelled.");
                    }
                    catch (Exception ex)
                    {
                        Assert.That(ex, Is.InstanceOf <TaskCanceledException>());
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public void GetInstanceAsync_ReportsProgress()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var config = await SyncTestHelpers.GetIntegrationConfigAsync("foo");
                await PopulateData(config);

                var callbacksInvoked = 0;

                var lastProgress = default(SyncProgress);
                config           = new FullSyncConfiguration(config.ServerUri, config.User, config.DatabasePath + "1")
                {
                    OnProgress = (progress) =>
                    {
                        callbacksInvoked++;
                        lastProgress = progress;
                    }
                };

                using (var realm = await GetRealmAsync(config))
                {
                    Assert.That(realm.All <HugeSyncObject>().Count(), Is.EqualTo(NumberOfObjects));
                    Assert.That(callbacksInvoked, Is.GreaterThan(0));
                    Assert.That(lastProgress.TransferableBytes, Is.EqualTo(lastProgress.TransferredBytes));
                }
            });
        }
Ejemplo n.º 3
0
        public void User_InvalidateOffer_InvalidatesTheOffer()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var alice   = await SyncTestHelpers.GetUserAsync();
                var bob     = await SyncTestHelpers.GetUserAsync();
                var charlie = await SyncTestHelpers.GetUserAsync();

                var realmUrl = SyncTestHelpers.RealmUri($"{alice.Identity}/testPermission").AbsoluteUri;
                await EnsureRealmExists(alice, realmUrl);

                var token  = await alice.OfferPermissionsAsync(realmUrl, AccessLevel.Write);
                var bobUrl = await bob.AcceptPermissionOfferAsync(token);
                Assert.That(bobUrl, Is.EqualTo($"/{alice.Identity}/testPermission"));

                await alice.InvalidateOfferAsync(token);

                await TestHelpers.AssertThrows <HttpException>(() => charlie.AcceptPermissionOfferAsync(token), ex =>
                {
                    Assert.That(ex.StatusCode, Is.EqualTo(HttpStatusCode.Forbidden));
                    Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCode.ExpiredPermissionOffer));
                    Assert.That(ex.Message, Is.EqualTo("The permission offer is expired."));
                });
            });
        }
Ejemplo n.º 4
0
        public void SyncConfiguration_LoggerFactory_Test(LogLevel logLevel)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var logBuilder = new StringBuilder();

                SyncConfigurationBase.CustomLogger = (message, level) =>
                {
                    logBuilder.AppendLine($"[{level}] {message}");
                };
                SyncConfigurationBase.LogLevel = logLevel;

                var config = await SyncTestHelpers.GetIntegrationConfigAsync(Guid.NewGuid().ToString());
                using (var realm = await GetRealmAsync(config))
                {
                    realm.Write(() =>
                    {
                        realm.Add(new Person());
                    });

                    await SyncTestHelpers.WaitForUploadAsync(realm);
                }

                var log = logBuilder.ToString();

                Assert.That(log, Does.Contain($"[{logLevel}]"));
                Assert.That(log, Does.Not.Contain($"[{(logLevel - 1)}]"));
            });
        }
Ejemplo n.º 5
0
        public void NamedSubscription_CanUnsubscribe(bool openAsync)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                using (var realm = await GetQueryBasedRealm(openAsync))
                {
                    var query        = realm.All <ObjectA>().Where(o => o.IntValue < 5);
                    var subscription = query.Subscribe(new SubscriptionOptions {
                        Name = "query"
                    });

                    await subscription.WaitForSynchronizationAsync().Timeout(2000);

                    Assert.That(subscription.Results.Count(), Is.EqualTo(5));

                    await subscription.UnsubscribeAsync();

                    Assert.That(subscription.State, Is.EqualTo(SubscriptionState.Invalidated));

                    await TestHelpers.WaitForConditionAsync(() => query.Count() == 0);
                    Assert.That(query.Count(), Is.EqualTo(0));
                    Assert.That(subscription.Results.Count(), Is.EqualTo(0));
                }
            });
        }
Ejemplo n.º 6
0
        public void TestManualClientResync()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var config = await GetClientResyncConfig(ClientResyncMode.Manual);

                Realm.DeleteRealm(config);
                using (var realm = await Realm.GetInstanceAsync(config))
                {
                    realm.Write(() =>
                    {
                        realm.Add(new IntPrimaryKeyWithValueObject());
                    });

                    await WaitForUploadAsync(realm);
                }

                // Delete Realm in ROS
                Debugger.Break();

                Exception ex   = null;
                Session.Error += (s, e) =>
                {
                    ex = e.Exception;
                };

                using (var realm = Realm.GetInstance(config))
                {
                    await Task.Delay(100);
                }

                Assert.That(ex, Is.InstanceOf <ClientResetException>());
            });
        }
Ejemplo n.º 7
0
        public void NamedSubscription_CanResubscribe(bool openAsync)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                using (var realm = await GetQueryBasedRealm(openAsync))
                {
                    var query        = realm.All <ObjectA>().Where(o => o.IntValue < 5);
                    var subscription = query.Subscribe(new SubscriptionOptions {
                        Name = "less than 5"
                    });

                    await subscription.WaitForSynchronizationAsync().Timeout(2000);

                    Assert.That(subscription.Results.Count(), Is.EqualTo(5));

                    var subscription2 = realm.All <ObjectA>().Where(o => o.IntValue < 5).Subscribe(new SubscriptionOptions {
                        Name = "less than 5"
                    });
                    await subscription2.WaitForSynchronizationAsync().Timeout(2000);

                    Assert.That(subscription.Results.Count(), Is.EqualTo(5));
                    Assert.That(subscription2.Results.Count(), Is.EqualTo(5));
                }
            });
        }
Ejemplo n.º 8
0
        public void NamedSubscription_CannotChangeQuery(bool openAsync)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                using (var realm = await GetQueryBasedRealm(openAsync))
                {
                    var query        = realm.All <ObjectA>().Where(o => o.IntValue < 5);
                    var subscription = query.Subscribe(new SubscriptionOptions {
                        Name = "foo"
                    });

                    await subscription.WaitForSynchronizationAsync().Timeout(2000);

                    Assert.That(subscription.Results.Count(), Is.EqualTo(5));

                    var subscription2 = realm.All <ObjectA>()
                                        .Where(o => o.IntValue > 5)
                                        .Subscribe(new SubscriptionOptions {
                        Name = "foo"
                    });

                    await TestHelpers.AssertThrows <RealmException>(() => subscription2.WaitForSynchronizationAsync(), ex =>
                    {
                        Assert.That(subscription2.State, Is.EqualTo(SubscriptionState.Error));
                        Assert.That(subscription2.Error, Is.Not.Null);
                        Assert.That(subscription2.Error.Message, Does.Contain("An existing subscription exists with the name"));
                        Assert.That(ex, Is.EqualTo(subscription2.Error));
                    });
                }
            });
        }
Ejemplo n.º 9
0
        public void Subscription_GetAll_FindsSubscription(bool openAsync, bool isNamed)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                using (var realm = await GetQueryBasedRealm(openAsync))
                {
                    var name         = isNamed ? "some subscription" : null;
                    var query        = realm.All <ObjectA>().Where(o => o.IntValue < 5);
                    var now          = DateTimeOffset.UtcNow;
                    var subscription = query.Subscribe(new SubscriptionOptions {
                        Name = name
                    });

                    await subscription.WaitForSynchronizationAsync().Timeout(2000);

                    var sub = realm.GetAllSubscriptions().FirstOrDefault(s => s.ObjectType == nameof(ObjectA));

                    Assert.That(sub, Is.Not.Null);
                    Assert.That(sub.Error, Is.Null);
                    Assert.That(sub.Name, isNamed ? (IResolveConstraint)Is.EqualTo(name) : Is.Not.Null);
                    Assert.That(sub.ObjectType, Is.EqualTo(nameof(ObjectA)));
                    Assert.That(sub.CreatedAt, Is.InRange(now, now.AddSeconds(2)));
                    Assert.That(sub.CreatedAt, Is.EqualTo(sub.UpdatedAt));
                    Assert.That(sub.ExpiresAt, Is.Null);
                    Assert.That(sub.TimeToLive, Is.Null);
                }
            });
        }
Ejemplo n.º 10
0
        public void UserLogout_RevokesRefreshToken()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var userId      = Guid.NewGuid().ToString();
                var credentials = Credentials.UsernamePassword(userId, OriginalPassword, createUser: true);
                var user        = await User.LoginAsync(credentials, SyncTestHelpers.AuthServerUri);

                var token = user.RefreshToken;
                await user.LogOutAsync();

                // Changing user's password uses the RefreshToken as authorization
                var json = new Dictionary <string, object>
                {
                    ["data"] = new Dictionary <string, object>
                    {
                        ["new_password"] = "******"
                    }
                };

                await TestHelpers.AssertThrows <HttpException>(
                    () => AuthenticationHelper.MakeAuthRequestAsync(HttpMethod.Put, new Uri(SyncTestHelpers.AuthServerUri, "auth/password"), json, token),
                    ex =>
                {
                    Assert.That(ex.StatusCode, Is.EqualTo(HttpStatusCode.Forbidden));
                    Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCode.AccessDenied));
                });
            });
        }
Ejemplo n.º 11
0
        public void SubscribeForObjects_WhenTwoQueriesOverlap_SynchronizesTheUnion(bool openAsync)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                using (var realm = await GetQueryBasedRealm(openAsync))
                {
                    var youngerThan3Subscription = realm.All <ObjectA>().Where(o => o.IntValue < 3).Subscribe();
                    var range1to6Subscription    = realm.All <ObjectA>().Where(o => o.IntValue > 1 && o.IntValue < 6).Subscribe();

                    await youngerThan3Subscription.WaitForSynchronizationAsync().Timeout(2000);
                    await range1to6Subscription.WaitForSynchronizationAsync().Timeout(2000);

                    var youngerThan3 = youngerThan3Subscription.Results;
                    var range1to6    = range1to6Subscription.Results;

                    Assert.That(youngerThan3.Count(), Is.EqualTo(3));
                    Assert.That(range1to6.Count(), Is.EqualTo(4));

                    Assert.That(youngerThan3.ToArray().All(o => o.IntValue < 3));
                    Assert.That(range1to6.ToArray().All(o => o.IntValue > 1 && o.IntValue < 6));

                    var allInRealm = realm.All <ObjectA>();

                    Assert.That(allInRealm.Count(), Is.EqualTo(6));
                    Assert.That(allInRealm.ToArray().All(o => o.IntValue < 6));
                }
            });
        }
        public void Test_ObjectDelete()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var userA = await SyncTestHelpers.GetUserAsync();
                var userB = await SyncTestHelpers.GetUserAsync();

                var realmUri = await CreateRealm(r =>
                {
                    var reader = PermissionRole.Get(r, "reader");
                    reader.Users.Add(userA);
                    reader.Users.Add(userB);

                    var writer = PermissionRole.Get(r, "writer");
                    writer.Users.Add(userA);

                    var obj1 = r.Add(new ObjectWithPermissions
                    {
                        Id          = 1,
                        StringValue = "Value 1"
                    });
                    CreatePermissions(obj1.Permissions);
                }, addObjects: false);

                using (var realmA = GetRealm(userA, realmUri))
                    using (var realmB = GetRealm(userB, realmUri))
                    {
                        var subscriptionB = await SubscribeToObjectsAsync(realmB);
                        var objB          = subscriptionB.Results.Single();
                        realmB.Write(() =>
                        {
                            realmB.Remove(objB);
                        });

                        Assert.That(subscriptionB.Results.Count(), Is.Zero);
                        await SyncTestHelpers.WaitForSyncAsync(realmB);
                        Assert.That(subscriptionB.Results.Count(), Is.EqualTo(1));
                        objB = subscriptionB.Results.Single();

                        var subscriptionA = await SubscribeToObjectsAsync(realmA);
                        var objA          = subscriptionA.Results.Single();
                        realmA.Write(() =>
                        {
                            realmA.Remove(objA);
                        });

                        await SyncTestHelpers.WaitForSyncAsync(realmA);
                        await SyncTestHelpers.WaitForSyncAsync(realmB);

                        Assert.That(subscriptionA.Results.Count(), Is.Zero);
                        Assert.That(subscriptionB.Results.Count(), Is.Zero);

                        Assert.That(objA.IsValid, Is.False);
                        Assert.That(objB.IsValid, Is.False);
                    }
            });
        }
Ejemplo n.º 13
0
        public void UserLookup_WhenUserIsNotAdmin_ShouldThrow()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var alice = await SyncTestHelpers.GetUserAsync();

                await TestHelpers.AssertThrows <InvalidOperationException>(() => alice.RetrieveInfoForUserAsync(Credentials.Provider.UsernamePassword, "some-id"));
            });
        }
        public void Test_ClassUpdate()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var userA = await SyncTestHelpers.GetUserAsync();
                var userB = await SyncTestHelpers.GetUserAsync();

                var realmUri = await CreateRealm(r =>
                {
                    CreatePermissions(ClassPermission.Get <ObjectWithPermissions>(r).Permissions);

                    var reader = PermissionRole.Get(r, "reader");
                    reader.Users.Add(userA);
                    reader.Users.Add(userB);

                    var writer = PermissionRole.Get(r, "writer");
                    writer.Users.Add(userA);
                });

                using (var realm = GetRealm(userA, realmUri))
                {
                    var subscription = await SubscribeToObjectsAsync(realm);
                    AssertRealmPrivileges(realm, RealmPrivileges.Read | RealmPrivileges.Update | RealmPrivileges.ModifySchema | RealmPrivileges.SetPermissions);
                    AssertClassPrivileges(realm, ClassPrivileges.Read | ClassPrivileges.Subscribe | ClassPrivileges.Update | ClassPrivileges.Create);
                    AssertObjectPrivileges(realm, ObjectPrivileges.Read | ObjectPrivileges.Update | ObjectPrivileges.Delete | ObjectPrivileges.SetPermissions);

                    var obj = realm.Find <ObjectWithPermissions>(1);
                    realm.Write(() =>
                    {
                        obj.StringValue = "New value";
                    });

                    await SyncTestHelpers.WaitForSyncAsync(realm);
                    Assert.That(obj.StringValue, Is.EqualTo("New value"));
                }

                using (var realm = GetRealm(userB, realmUri))
                {
                    var subscription = await SubscribeToObjectsAsync(realm);
                    AssertRealmPrivileges(realm, RealmPrivileges.Read | RealmPrivileges.Update | RealmPrivileges.ModifySchema | RealmPrivileges.SetPermissions);
                    AssertClassPrivileges(realm, ClassPrivileges.Read | ClassPrivileges.Subscribe);
                    AssertObjectPrivileges(realm, ObjectPrivileges.Read);

                    var obj = realm.Find <ObjectWithPermissions>(1);
                    realm.Write(() =>
                    {
                        obj.StringValue = "New value 2";
                    });

                    Assert.That(obj.StringValue, Is.EqualTo("New value 2"));
                    await SyncTestHelpers.WaitForSyncAsync(realm);

                    // Change is reverted
                    Assert.That(obj.StringValue, Is.EqualTo("New value"));
                }
            });
        }
Ejemplo n.º 15
0
        public void User_ApplyPermissions_WithUserId_GrantsAndRevokesPermissions()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var alice = await SyncTestHelpers.GetUserAsync();
                var bob   = await SyncTestHelpers.GetUserAsync();

                await TestApplyPermissions(alice, bob, PermissionCondition.UserId(bob.Identity)).Timeout(20000);
            });
        }
Ejemplo n.º 16
0
        public void UserLookup_WhenTargetUserDoesNotExist_ShouldReturnNull()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var admin = await User.LoginAsync(SyncTestHelpers.AdminCredentials(), SyncTestHelpers.AuthServerUri);

                var lookupResponse = await admin.RetrieveInfoForUserAsync(Credentials.Provider.UsernamePassword, "something");
                Assert.That(lookupResponse, Is.Null);
            });
        }
Ejemplo n.º 17
0
        public void UserLogin_WhenNickname_LogsUserIn()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var credentials = Credentials.Nickname(Guid.NewGuid().ToString());
                var user        = await User.LoginAsync(credentials, SyncTestHelpers.AuthServerUri);

                Assert.That(user, Is.Not.Null);
                Assert.That(user.Identity, Is.Not.Null);
            });
        }
Ejemplo n.º 18
0
        public void UserLogin_WhenAnonymous_LogsUserIn()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var credentials = Credentials.Anonymous();
                var user        = await User.LoginAsync(credentials, SyncTestHelpers.AuthServerUri);

                Assert.That(user, Is.Not.Null);
                Assert.That(user.Identity, Is.Not.Null);
            });
        }
        public void Test_ObjectUpdate()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var userA = await SyncTestHelpers.GetUserAsync();
                var userB = await SyncTestHelpers.GetUserAsync();

                var realmUri = await CreateRealm(r =>
                {
                    var reader = PermissionRole.Get(r, "reader");
                    reader.Users.Add(userA);
                    reader.Users.Add(userB);

                    var writer = PermissionRole.Get(r, "writer");
                    writer.Users.Add(userA);

                    var obj1 = r.Add(new ObjectWithPermissions
                    {
                        Id          = 1,
                        StringValue = "Value 1"
                    });
                    CreatePermissions(obj1.Permissions);
                }, addObjects: false);

                using (var realm = GetRealm(userA, realmUri))
                {
                    var subscription = await SubscribeToObjectsAsync(realm);
                    var obj1         = subscription.Results.Single();
                    realm.Write(() =>
                    {
                        obj1.StringValue = "New value";
                    });

                    await SyncTestHelpers.WaitForSyncAsync(realm);

                    Assert.That(obj1.StringValue, Is.EqualTo("New value"));
                }

                using (var realm = GetRealm(userB, realmUri))
                {
                    var subscription = await SubscribeToObjectsAsync(realm);
                    var obj1         = subscription.Results.Single();
                    realm.Write(() =>
                    {
                        obj1.StringValue = "New value #2";
                    });

                    Assert.That(obj1.StringValue, Is.EqualTo("New value #2"));
                    await SyncTestHelpers.WaitForSyncAsync(realm);

                    Assert.That(obj1.StringValue, Is.EqualTo("New value"));
                }
            });
        }
Ejemplo n.º 20
0
        public void UserLogin_WhenAnonymousAndDifferentCredentials_ShouldLoginDifferentUser()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var first  = await User.LoginAsync(Credentials.Anonymous(), SyncTestHelpers.AuthServerUri);
                var second = await User.LoginAsync(Credentials.Anonymous(), SyncTestHelpers.AuthServerUri);

                Assert.That(first.Identity, Is.Not.EqualTo(second.Identity));
                Assert.That(User.AllLoggedIn.Length, Is.EqualTo(2));
            });
        }
Ejemplo n.º 21
0
        public void User_OfferPermissions_WhenNoAccess_ShouldThrow()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var alice = await SyncTestHelpers.GetUserAsync();

                var realmUrl = SyncTestHelpers.RealmUri($"{alice.Identity}/testPermission").AbsoluteUri;
                await EnsureRealmExists(alice, realmUrl);

                await TestHelpers.AssertThrows <ArgumentException>(() => alice.OfferPermissionsAsync(realmUrl, AccessLevel.None));
            });
        }
Ejemplo n.º 22
0
        public void User_OfferPermissions_WhenExpired_ShouldThrow()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var alice = await SyncTestHelpers.GetUserAsync();

                var realmUrl = SyncTestHelpers.RealmUri($"{alice.Identity}/testPermission").AbsoluteUri;
                await EnsureRealmExists(alice, realmUrl);

                await TestHelpers.AssertThrows <ArgumentException>(() => alice.OfferPermissionsAsync(realmUrl, AccessLevel.Write, DateTimeOffset.UtcNow.AddDays(-1)));
            });
        }
Ejemplo n.º 23
0
        public void User_AcceptPermissionOffer_WhenTokenIsInvalid_ShouldGetError()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var user = await SyncTestHelpers.GetUserAsync();

                await TestHelpers.AssertThrows <HttpException>(() => user.AcceptPermissionOfferAsync("some string"), ex =>
                {
                    Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCode.InvalidParameters));
                });
            });
        }
Ejemplo n.º 24
0
 public void TrustedCA_WhenFileDoesntExist_Throws()
 {
     SyncTestHelpers.RunRosTestAsync(async() =>
     {
         var user   = await SyncTestHelpers.GetUserAsync();
         var config = new FullSyncConfiguration(SyncTestHelpers.RealmUri("~/TrustedCA_WhenFileDoesntExist_Throws"), user)
         {
             TrustedCAPath = "something.pem"
         };
         Assert.That(() => GetRealm(config), Throws.TypeOf <FileNotFoundException>());
     });
 }
Ejemplo n.º 25
0
        public void User_ApplyPermissions_WithEmail_GrantsAndRevokesPermissions()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var alice          = await SyncTestHelpers.GetUserAsync();
                var bobEmail       = $"{Guid.NewGuid()}@foo.bar";
                var bobCredentials = Credentials.UsernamePassword(bobEmail, "a", createUser: true);
                var bob            = await User.LoginAsync(bobCredentials, SyncTestHelpers.AuthServerUri);

                await TestApplyPermissions(alice, bob, PermissionCondition.Email(bobEmail)).Timeout(20000);
            });
        }
        public void Test_RealmUpdate()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var userA = await SyncTestHelpers.GetUserAsync();
                var userB = await SyncTestHelpers.GetUserAsync();

                var realmUri = await CreateRealm(r =>
                {
                    CreatePermissions(RealmPermission.Get(r).Permissions);
                    var reader = PermissionRole.Get(r, "reader");
                    reader.Users.Add(userA);
                    reader.Users.Add(userB);

                    var writer = PermissionRole.Get(r, "writer");
                    writer.Users.Add(userA);
                });

                using (var realm = GetRealm(userA, realmUri))
                {
                    var subscription = await SubscribeToObjectsAsync(realm);
                    AssertRealmPrivileges(realm, RealmPrivileges.Read | RealmPrivileges.Update);
                    AssertClassPrivileges(realm, ClassPrivileges.Read | ClassPrivileges.Subscribe | ClassPrivileges.Create | ClassPrivileges.SetPermissions | ClassPrivileges.Update);
                    AssertObjectPrivileges(realm, ObjectPrivileges.Read | ObjectPrivileges.Delete | ObjectPrivileges.SetPermissions | ObjectPrivileges.Update);

                    Assert.That(subscription.Results.Count(), Is.EqualTo(3));
                    AddObjectsToRealm(realm, new[] { 4, 5, 6 });

                    Assert.That(subscription.Results.Count(), Is.EqualTo(6));

                    await SyncTestHelpers.WaitForSyncAsync(realm);
                    Assert.That(subscription.Results.Count(), Is.EqualTo(6));
                }

                using (var realm = GetRealm(userB, realmUri))
                {
                    var subscription = await SubscribeToObjectsAsync(realm);

                    AssertRealmPrivileges(realm, RealmPrivileges.Read);
                    AssertClassPrivileges(realm, ClassPrivileges.Read | ClassPrivileges.Subscribe);
                    AssertObjectPrivileges(realm, ObjectPrivileges.Read);

                    Assert.That(subscription.Results.Count(), Is.EqualTo(6));
                    AddObjectsToRealm(realm, new[] { 7, 8, 9 });

                    Assert.That(subscription.Results.Count(), Is.EqualTo(9));

                    await SyncTestHelpers.WaitForSyncAsync(realm);
                    Assert.That(subscription.Results.Count(), Is.EqualTo(6));
                }
            });
        }
Ejemplo n.º 27
0
        public void UserLogin_WhenNicknameAfterLogout_LogsSameUserIn()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var nickname = Guid.NewGuid().ToString();
                var first    = await User.LoginAsync(Credentials.Nickname(nickname), SyncTestHelpers.AuthServerUri);
                await first.LogOutAsync();

                var second = await User.LoginAsync(Credentials.Nickname(nickname), SyncTestHelpers.AuthServerUri);

                Assert.That(first.Identity, Is.EqualTo(second.Identity));
            });
        }
Ejemplo n.º 28
0
        public void Subcribe_WaitForSynchronization_Multiple(bool openAsync)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                using (var realm = await GetQueryBasedRealm(openAsync))
                {
                    var subscription = realm.All <ObjectA>().Where(f => f.IntValue > 0).Subscribe();
                    await subscription.WaitForSynchronizationAsync().Timeout(5000);

                    var subscription2 = realm.All <ObjectA>().Where(f => f.IntValue > 0).Subscribe();
                    await subscription2.WaitForSynchronizationAsync().Timeout(5000);
                }
            });
        }
Ejemplo n.º 29
0
        public void UserChangePasswordTest()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var userId      = Guid.NewGuid().ToString();
                var credentials = Credentials.UsernamePassword(userId, OriginalPassword, createUser: true);
                var user        = await User.LoginAsync(credentials, SyncTestHelpers.AuthServerUri);
                await user.ChangePasswordAsync(NewPassword);
                await user.LogOutAsync();

                Assert.That(async() => await user.ChangePasswordAsync("c"), Throws.TypeOf <InvalidOperationException>());

                await TestNewPassword(userId);
            });
        }
Ejemplo n.º 30
0
        public void UserLogin_WhenAnonymous_AfterLogoutShouldLoginDifferentUser()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                // Login an anonymous user
                var first = await User.LoginAsync(Credentials.Anonymous(), SyncTestHelpers.AuthServerUri);
                await first.LogOutAsync();

                // Login a second anonymous user
                var second = await User.LoginAsync(Credentials.Anonymous(), SyncTestHelpers.AuthServerUri);

                // Expect that the anonymous users to be different
                Assert.That(first.Identity, Is.Not.EqualTo(second.Identity));
                Assert.That(User.AllLoggedIn.Length, Is.EqualTo(1));
            });
        }