Exemplo n.º 1
0
        public void ShouldHaveTenantTrimmedWhenCreated()
        {
            var tenant = Generator.RandomString(5);
            var client = new Services.MeshyClient(Generator.RandomString(5), $" {tenant} ", Generator.RandomString(36));

            Assert.Equal(tenant, client.Tenant);
        }
Exemplo n.º 2
0
        public void ShouldVerifySuccessfully()
        {
            var client      = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService = new Mock <IAuthenticationService>();
            var passedUserVerificationCheck = default(UserVerificationCheck);

            authService.Setup(x => x.VerifyAsync(It.IsAny <UserVerificationCheck>()))
            .Callback <UserVerificationCheck>((sentUserVerificationCheck) =>
            {
                passedUserVerificationCheck = sentUserVerificationCheck;
            })
            .Returns(() =>
            {
                return(Task.FromResult <object>(null));
            });

            client.AuthenticationService = authService.Object;

            var now = DateTimeOffset.Now;
            var userVerificationCheck = new UserVerificationCheck()
            {
                Expires          = now,
                Hash             = Generator.RandomString(5),
                Hint             = Generator.RandomString(5),
                Username         = Generator.RandomString(5),
                VerificationCode = Generator.RandomString(5)
            };

            client.Verify(userVerificationCheck);
            Assert.Equal(userVerificationCheck.Hash, passedUserVerificationCheck.Hash);
            Assert.Equal(userVerificationCheck.Expires, passedUserVerificationCheck.Expires);
            Assert.Equal(userVerificationCheck.Hint, passedUserVerificationCheck.Hint);
            Assert.Equal(userVerificationCheck.Username, passedUserVerificationCheck.Username);
            Assert.Equal(userVerificationCheck.VerificationCode, passedUserVerificationCheck.VerificationCode);
        }
Exemplo n.º 3
0
        public void ShouldForgotPasswordSuccessfully()
        {
            var client         = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService    = new Mock <IAuthenticationService>();
            var expected       = new UserVerificationHash();
            var passedUsername = string.Empty;

            authService.Setup(x => x.ForgotPasswordAsync(It.IsAny <string>(), It.IsAny <int>()))
            .Callback <string, int>((sentUsername, sentAttempt) =>
            {
                passedUsername = sentUsername;
            })
            .Returns(() =>
            {
                return(Task.FromResult(expected));
            });

            client.AuthenticationService = authService.Object;

            var username = Generator.RandomString(5);
            var actual   = client.ForgotPassword(username);

            Assert.Equal(expected, actual);
            Assert.Equal(username, passedUsername);
        }
Exemplo n.º 4
0
        public void ShouldIncludeAccountNameInAuthUrl()
        {
            var accountName = Generator.RandomString(5);
            var client      = new Services.MeshyClient(accountName, Generator.RandomString(36));

            Assert.Equal($"https://auth.meshydb.com/{accountName}".ToLowerInvariant(), client.GetAuthUrl().ToLowerInvariant());
        }
Exemplo n.º 5
0
        public void ShouldHaveMeshesService()
        {
            var client      = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService = new Mock <IAuthenticationService>();

            authService.Setup(x => x.LoginAnonymouslyAsync(It.IsAny <string>()))
            .Returns(() =>
            {
                return(Task.FromResult(Generator.RandomString(25)));
            });

            client.AuthenticationService = authService.Object;
            var connection = client.LoginAnonymously(Generator.RandomString(5));

            Assert.NotNull(connection.Meshes);
        }
Exemplo n.º 6
0
        public void ShouldRegisterUserSuccessfully()
        {
            var client      = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService = new Mock <IAuthenticationService>();
            var expected    = new UserVerificationHash();

            authService.Setup(x => x.RegisterAsync(It.IsAny <RegisterUser>())).Returns(() =>
            {
                return(Task.FromResult(expected));
            });

            client.AuthenticationService = authService.Object;

            var actual = client.RegisterUser(new RegisterUser(Generator.RandomString(5), Generator.RandomString(5)));

            Assert.Equal(expected, actual);
        }
Exemplo n.º 7
0
        public void ShouldLoginWithRefreshSuccessfully()
        {
            var client      = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService = new Mock <IAuthenticationService>();
            var identifier  = Generator.RandomString(25);

            authService.Setup(x => x.LoginWithRefreshTokenAsync(It.IsAny <string>()))
            .Returns(() =>
            {
                return(Task.FromResult(identifier));
            });

            client.AuthenticationService = authService.Object;
            var connection = client.LoginWithRefreshToken(Generator.RandomString(10));

            Assert.NotNull(connection);
        }
Exemplo n.º 8
0
        public void ShouldLoginWithPasswordAsyncSuccessfully()
        {
            var client      = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService = new Mock <IAuthenticationService>();
            var identifier  = Generator.RandomString(25);

            authService.Setup(x => x.LoginWithPasswordAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() =>
            {
                return(Task.FromResult(identifier));
            });

            client.AuthenticationService = authService.Object;
            var connection = client.LoginWithPasswordAsync(Generator.RandomString(10), Generator.RandomString(10)).ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.NotNull(connection);
        }
Exemplo n.º 9
0
        public void ShouldCheckHashAsyncSuccessfully()
        {
            var client      = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService = new Mock <IAuthenticationService>();
            var passedUserVerificationCheck = default(UserVerificationCheck);

            authService.Setup(x => x.CheckHashAsync(It.IsAny <UserVerificationCheck>()))
            .Callback <UserVerificationCheck>((sentUserVerificationCheck) =>
            {
                passedUserVerificationCheck = sentUserVerificationCheck;
            })
            .Returns(() =>
            {
                return(Task.FromResult(new Valid {
                    IsValid = true
                }));
            });

            client.AuthenticationService = authService.Object;

            var now = DateTimeOffset.Now;
            var userVerificationCheck = new UserVerificationCheck()
            {
                Expires          = now,
                Hash             = Generator.RandomString(5),
                Hint             = Generator.RandomString(5),
                Username         = Generator.RandomString(5),
                VerificationCode = Generator.RandomString(5)
            };

            var result = client.CheckHashAsync(userVerificationCheck).ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.True(result.IsValid);
            Assert.Equal(userVerificationCheck.Hash, passedUserVerificationCheck.Hash);
            Assert.Equal(userVerificationCheck.Expires, passedUserVerificationCheck.Expires);
            Assert.Equal(userVerificationCheck.Hint, passedUserVerificationCheck.Hint);
            Assert.Equal(userVerificationCheck.Username, passedUserVerificationCheck.Username);
            Assert.Equal(userVerificationCheck.VerificationCode, passedUserVerificationCheck.VerificationCode);
        }
Exemplo n.º 10
0
        public void ShouldResetPasswordSuccessfully()
        {
            var client              = new Services.MeshyClient(Generator.RandomString(5), Generator.RandomString(36));
            var authService         = new Mock <IAuthenticationService>();
            var passedResetPassword = default(ResetPassword);

            authService.Setup(x => x.ResetPasswordAsync(It.IsAny <ResetPassword>()))
            .Callback <ResetPassword>((sentPasswordReset) =>
            {
                passedResetPassword = sentPasswordReset;
            })
            .Returns(() =>
            {
                return(Task.FromResult <object>(null));
            });

            client.AuthenticationService = authService.Object;

            var now           = DateTimeOffset.Now;
            var resetPassword = new ResetPassword()
            {
                Expires          = now,
                Hash             = Generator.RandomString(5),
                Hint             = Generator.RandomString(5),
                NewPassword      = Generator.RandomString(5),
                Username         = Generator.RandomString(5),
                VerificationCode = Generator.RandomString(5)
            };

            client.ResetPassword(resetPassword);
            Assert.Equal(resetPassword.Hash, passedResetPassword.Hash);
            Assert.Equal(resetPassword.Expires, passedResetPassword.Expires);
            Assert.Equal(resetPassword.Hint, passedResetPassword.Hint);
            Assert.Equal(resetPassword.NewPassword, passedResetPassword.NewPassword);
            Assert.Equal(resetPassword.Username, passedResetPassword.Username);
            Assert.Equal(resetPassword.VerificationCode, passedResetPassword.VerificationCode);
        }
Exemplo n.º 11
0
        public void ShouldCreateWithNullTenant()
        {
            var client = new Services.MeshyClient(Generator.RandomString(5), null, Generator.RandomString(36));

            Assert.NotNull(client);
        }