public void User_LinkCredentials_MultipleTimes_AllowsLoginWithAllCredentials()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var user = await DefaultApp.LogInAsync(Credentials.Anonymous());

                var email = SyncTestHelpers.GetVerifiedUsername();
                await DefaultApp.EmailPasswordAuth.RegisterUserAsync(email, SyncTestHelpers.DefaultPassword);
                var linkedUser1 = await user.LinkCredentialsAsync(Credentials.EmailPassword(email, SyncTestHelpers.DefaultPassword));
                Assert.That(linkedUser1.Id, Is.EqualTo(user.Id));

                var functionId  = Guid.NewGuid().ToString();
                var linkedUser2 = await user.LinkCredentialsAsync(Credentials.Function(new { realmCustomAuthFuncUserId = functionId }));
                Assert.That(linkedUser2.Id, Is.EqualTo(user.Id));

                var emailPasswordUser = await DefaultApp.LogInAsync(Credentials.EmailPassword(email, SyncTestHelpers.DefaultPassword));
                Assert.That(emailPasswordUser.Id, Is.EqualTo(user.Id));

                var functionUser = await DefaultApp.LogInAsync(Credentials.Function(new { realmCustomAuthFuncUserId = functionId }));
                Assert.That(functionUser.Id, Is.EqualTo(user.Id));

                Assert.That(user.Identities, Has.Length.EqualTo(3));
                Assert.That(user.Identities[0].Provider, Is.EqualTo(Credentials.AuthProvider.Anonymous));
                Assert.That(user.Identities[0].Id, Is.Not.Null);

                Assert.That(user.Identities[1].Provider, Is.EqualTo(Credentials.AuthProvider.EmailPassword));
                Assert.That(user.Identities[1].Id, Is.Not.Null);

                Assert.That(user.Identities[2].Provider, Is.EqualTo(Credentials.AuthProvider.Function));
                Assert.That(user.Identities[2].Id, Is.EqualTo(functionId));
            });
        }
        public void User_LinkCredentials_AllowsLoginWithNewCredentials()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var user = await DefaultApp.LogInAsync(Credentials.Anonymous());

                Assert.That(user.Identities, Has.Length.EqualTo(1));
                Assert.That(user.Identities[0].Provider, Is.EqualTo(Credentials.AuthProvider.Anonymous));
                Assert.That(user.Identities[0].Id, Is.Not.Null);

                var email = SyncTestHelpers.GetVerifiedUsername();
                await DefaultApp.EmailPasswordAuth.RegisterUserAsync(email, SyncTestHelpers.DefaultPassword);
                var linkedUser = await user.LinkCredentialsAsync(Credentials.EmailPassword(email, SyncTestHelpers.DefaultPassword));

                Assert.That(user.Identities, Has.Length.EqualTo(2));
                Assert.That(user.Identities[1].Provider, Is.EqualTo(Credentials.AuthProvider.EmailPassword));
                Assert.That(user.Identities[1].Id, Is.Not.Null);

                Assert.That(linkedUser.Identities, Has.Length.EqualTo(2));
                Assert.That(linkedUser.Id, Is.EqualTo(user.Id));
                Assert.That(linkedUser.Identities, Is.EquivalentTo(user.Identities));

                var emailPasswordUser = await DefaultApp.LogInAsync(Credentials.EmailPassword(email, SyncTestHelpers.DefaultPassword));

                Assert.That(emailPasswordUser.Id, Is.EqualTo(user.Id));
                Assert.That(emailPasswordUser.Identities, Is.EquivalentTo(user.Identities));
            });
        }
        public void UserApiKeys_CanLoginWithReenabledKey()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var user   = await GetUserAsync();
                var apiKey = await user.ApiKeys.CreateAsync("my-api-key");

                await user.ApiKeys.DisableAsync(apiKey.Id);

                var credentials = Credentials.ApiKey(apiKey.Value);

                var ex = await TestHelpers.AssertThrows <AppException>(() => DefaultApp.LogInAsync(credentials));
                Assert.That(ex.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
                Assert.That(ex.HelpLink, Does.Contain("logs?co_id="));
                Assert.That(ex.Message, Is.EqualTo("AuthError: invalid API key"));

                await user.ApiKeys.EnableAsync(apiKey.Id);

                var apiKeyUser = await DefaultApp.LogInAsync(credentials);

                Assert.That(apiKeyUser.Id, Is.EqualTo(user.Id));

                Assert.That(apiKeyUser.Provider, Is.EqualTo(Credentials.AuthProvider.ApiKey));
                Assert.That(apiKeyUser.RefreshToken, Is.Not.EqualTo(user.RefreshToken));
            });
        }
Example #4
0
 public void App_Login_Anonymous()
 {
     SyncTestHelpers.RunBaasTestAsync(async() =>
     {
         var user = await DefaultApp.LogInAsync(Credentials.Anonymous());
     });
 }
        public void AppSwitchUser_SwitchesCurrentUser()
        {
            var first  = GetFakeUser();
            var second = GetFakeUser();

            Assert.That(DefaultApp.CurrentUser, Is.EqualTo(second));

            DefaultApp.SwitchUser(first);

            Assert.That(DefaultApp.CurrentUser, Is.EqualTo(first));
        }
Example #6
0
 public void CheckPlatformServices()
 {
     DefaultApp.Initialize(AppPlatform);
     CheckSingleResolved <IViewProvider>("UI service");
     CheckSingleResolved <IBackgroundService>("Background tasks");
     CheckResolved <IStorageService>();
     CheckResolved <ISettingsService>();
     CheckResolved <INotificationService>();
     CheckResolved <ILauncher>();
     CheckAllResolved <IDispatcher>("Dispatchers");
 }
Example #7
0
        public void CheckDefaultServices()
        {
            DefaultApp.Initialize(AppPlatform);
            CheckSingleResolved <INavigationHistory>("Default navigation history");
            CheckSingleResolved <INavigationService>("Default navigation service");
            CheckSingleResolved <ICommandRouter>("Default command router");
            var package = CheckSingleResolved <IPackageInfo>("TestingApp package info");

            Assert.AreEqual(DefaultApp.PackageInfo, package, "Returned package info is not equivalent to the app's package info.");
            CheckResolved <ILifetimeScope>("DI container");
        }
        public void AppSwitchUser_WhenUserIsCurrent_DoesNothing()
        {
            var first = GetFakeUser();

            Assert.That(DefaultApp.CurrentUser, Is.EqualTo(first));

            var second = GetFakeUser();

            Assert.That(DefaultApp.CurrentUser, Is.EqualTo(second));

            DefaultApp.SwitchUser(second);

            Assert.That(DefaultApp.CurrentUser, Is.EqualTo(second));
        }
        public void User_Facebook_LogsInAndReadsDataFromFacebook()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                const string fbToken = "EAAFYw2aZAL1EBAHBBH22XBDZAutJFQ65KxH0bZAexYul5KtsHcjhI722XYEr4jKlaNvlosFsdZCT8dGUQNy2euZB684mpvtIIJEWWYMoH66bbEbKIrHRWqZBC8KMpSscoyzhFTJMpDYsrIilZBRN1A6bicXGaUNXVz5A0ucyZB7WkmQ8uUmdRWel9q6S8BJH3ZBCZAzWtcZCYmgEwZDZD";
                var credentials      = Credentials.Facebook(fbToken);
                var user             = await DefaultApp.LogInAsync(credentials);

                Assert.That(user.Id, Is.Not.Null);

                Assert.That(user.Profile.FirstName, Is.Not.Null);
                Assert.That(user.Profile.LastName, Is.Not.Null);
            });
        }
        public void User_LinkCredentials_WhenInUse_Throws()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var existingEmail = SyncTestHelpers.GetVerifiedUsername();
                await DefaultApp.EmailPasswordAuth.RegisterUserAsync(existingEmail, SyncTestHelpers.DefaultPassword);
                var emailUser = await DefaultApp.LogInAsync(Credentials.EmailPassword(existingEmail, SyncTestHelpers.DefaultPassword));

                var anonUser = await DefaultApp.LogInAsync(Credentials.Anonymous());

                var ex = await TestHelpers.AssertThrows <AppException>(() => anonUser.LinkCredentialsAsync(Credentials.EmailPassword(existingEmail, SyncTestHelpers.DefaultPassword)));

                Assert.That(ex.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
                Assert.That(ex.Message, Does.Contain("a user already exists with the specified provider"));
            });
        }
        public void UserApiKeys_CanLoginWithGeneratedKey()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var user   = await GetUserAsync();
                var apiKey = await user.ApiKeys.CreateAsync("my-api-key");

                var credentials = Credentials.ApiKey(apiKey.Value);
                var apiKeyUser  = await DefaultApp.LogInAsync(credentials);

                Assert.That(apiKeyUser.Id, Is.EqualTo(user.Id));

                Assert.That(apiKeyUser.Provider, Is.EqualTo(Credentials.AuthProvider.ApiKey));
                Assert.That(apiKeyUser.RefreshToken, Is.Not.EqualTo(user.RefreshToken));
            });
        }
Example #12
0
        public publish_versus_send_mechanics(DefaultApp @default) : base(@default)
        {
            with(_ =>
            {
                _.Handlers.DisableConventionalDiscovery();

                _.Endpoints.Publish(x => x
                                    .Message <Message1>()
                                    .Message <Message2>()
                                    .ToLocalQueue("one"));

                _.Endpoints.Publish(x => x.Message <Message2>().ToLocalQueue("two"));

                _.Extensions.UseMessageTrackingTestingSupport();
            });
        }
        public void EmailPasswordRegisterUser_Works()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var username = SyncTestHelpers.GetVerifiedUsername();
                await DefaultApp.EmailPasswordAuth.RegisterUserAsync(username, SyncTestHelpers.DefaultPassword);

                var user = await DefaultApp.LogInAsync(Credentials.EmailPassword(username, SyncTestHelpers.DefaultPassword));

                Assert.That(user, Is.Not.Null);
                Assert.That(user.State, Is.EqualTo(UserState.LoggedIn));
                Assert.That(user.Provider, Is.EqualTo(Credentials.AuthProvider.EmailPassword));
                Assert.That(user.AccessToken, Is.Not.Empty);
                Assert.That(user.RefreshToken, Is.Not.Empty);

                Assert.That(DefaultApp.CurrentUser, Is.EqualTo(user));
            });
        }
        public void User_JWT_LogsInAndReadsDataFromToken()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                const string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxMjM0NTY3ODkwIiwic3ViIjoiMTIzNDU2Nzg5MCIsIm5hbWUiOnsiZmlyc3QiOiJKb2huIiwibGFzdCI6IkRvZSJ9LCJqb2JUaXRsZSI6IkJyZWFrZXIgb2YgdGhpbmdzIiwiZW1haWwiOiJqb2huQGRvZS5jb20iLCJwaWN0dXJlVXJsIjoiaHR0cHM6Ly9kb2UuY29tL215cGljdHVyZSIsImdlbmRlciI6Im90aGVyIiwiYmlydGhkYXkiOiIxOTM0LTA1LTE1IiwibWluQWdlIjoiODAiLCJtYXhBZ2UiOiI5MCIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoyMDE2MjM5MDIyLCJhdWQiOiJteS1hdWRpZW5jZSJ9.B6u3SkU-pzCH_LA_HsevAJF1EI1LbAOfL6GP3bhjVpP4FBtrmZYQD_b7Z_wJLE0vaffX1eN6U_vE9t26bmXz2ig4jJRmbg7Kx9ka1BkcE7MF9nmdC90ffHgNBvU40yKpMBtVL9VNQCe-F6mSvUqpox2tQQpNKaXf8yQslAf_tfvqTvF0mPXnqU1v_5KtieMybOb7O8nV6LITrjsAA5ff4spWSgcskjXcyjq6DIdWbLlVJycodr-MjKu94fNXXsBLf0iK5XHYpL1Bs-ILs494_aK_Pf2GD3pYa56XjqN-nO_cYbIxzmsBkNtAp0hvg_Gp0O6QFi66Qkr7ORbkRasGAg";
                var credentials    = Credentials.JWT(token);
                var user           = await DefaultApp.LogInAsync(credentials);

                Assert.That(user.Profile.FirstName, Is.EqualTo("John"));
                Assert.That(user.Profile.LastName, Is.EqualTo("Doe"));
                Assert.That(user.Profile.Email, Is.EqualTo("*****@*****.**"));
                Assert.That(user.Profile.Birthday, Is.EqualTo("1934-05-15"));
                Assert.That(user.Profile.Gender, Is.EqualTo("other"));
                Assert.That(user.Profile.MinAge, Is.EqualTo("80"));
                Assert.That(user.Profile.MaxAge, Is.EqualTo("90"));
                Assert.That(user.Profile.PictureUrl.AbsoluteUri, Is.EqualTo("https://doe.com/mypicture"));

                // TODO: add other checks once https://github.com/realm/realm-core/issues/4131 is implemented.
            });
        }
        public void User_LinkCredentials_MultipleTimesSameCredentials_IsNoOp()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var user = await DefaultApp.LogInAsync(Credentials.Anonymous());

                var functionId = Guid.NewGuid().ToString();
                var linkedUser = await user.LinkCredentialsAsync(Credentials.Function(new { realmCustomAuthFuncUserId = functionId }));
                Assert.That(linkedUser.Id, Is.EqualTo(user.Id));

                var sameLinkedUser = await user.LinkCredentialsAsync(Credentials.Function(new { realmCustomAuthFuncUserId = functionId }));
                Assert.That(sameLinkedUser.Id, Is.EqualTo(user.Id));

                var functionUser = await DefaultApp.LogInAsync(Credentials.Function(new { realmCustomAuthFuncUserId = functionId }));
                Assert.That(functionUser.Id, Is.EqualTo(user.Id));

                Assert.That(user.Identities, Has.Length.EqualTo(2));
                Assert.That(user.Identities[1].Id, Is.EqualTo(functionId));
                Assert.That(user.Identities[1].Provider, Is.EqualTo(Credentials.AuthProvider.Function));
            });
        }
        public void AppRemoveUser_RemovesUser()
        {
            SyncTestHelpers.RunBaasTestAsync(async() =>
            {
                var first  = await GetUserAsync();
                var second = await GetUserAsync();

                Assert.That(DefaultApp.CurrentUser, Is.EqualTo(second));

                var rereshToken = second.RefreshToken;
                var secondId    = second.Id;

                await DefaultApp.RemoveUserAsync(second);

                // TODO: validate that the refresh token is invalidated.
                Assert.That(second.State, Is.EqualTo(UserState.Removed));
                Assert.That(second.AccessToken, Is.Empty);
                Assert.That(second.RefreshToken, Is.Empty);
                Assert.That(second.Id, Is.EqualTo(secondId));

                Assert.That(DefaultApp.CurrentUser, Is.EqualTo(first));
            });
        }
 public message_type_specific_envelope_rules(DefaultApp @default) : base(@default)
 {
 }
Example #18
0
 public can_compile_a_handler_chain_for_an_inner_type(DefaultApp @default) : base(@default)
 {
 }
Example #19
0
 public endpoints_and_handlers_are_scoped(DefaultApp @default) : base(@default)
 {
 }
 public can_use_custom_generation_sources(DefaultApp @default) : base(@default)
 {
 }
Example #21
0
 public saga_action_discovery(DefaultApp @default) : base(@default)
 {
     _fixture = @default;
 }
Example #22
0
 public applying_handler_policies(DefaultApp @default) : base(@default)
 {
 }
Example #23
0
 public registering_and_discovering_custom_readers_and_writers(DefaultApp @default) : base(@default)
 {
     @default.RecycleIfNecessary();
 }
Example #24
0
 private IEnumerable <ModuleInfo> GetModules(DefaultApp app)
 {
     return((IEnumerable <ModuleInfo>) this.modulesField.GetValue(app));
 }
 public content_type_preferences_with_request_reply(DefaultApp @default) : base(@default)
 {
 }
Example #26
0
 public registering_and_discovering_custom_readers_and_writers(DefaultApp @default) : base(@default)
 {
 }
Example #27
0
 public ExtensionLoadingAndDiscoveryTests(DefaultApp @default) : base(@default)
 {
 }
Example #28
0
 public find_handlers_with_the_default_handler_discovery(DefaultApp @default) : base(@default)
 {
 }
Example #29
0
 public customized_finding(DefaultApp @default) : base(@default)
 {
 }
 public void AppSwitchUser_WhenUserIsNull_Throws()
 {
     Assert.That(() => DefaultApp.SwitchUser(null), Throws.InstanceOf <ArgumentNullException>());
 }