Exemplo n.º 1
0
        public async Task Register_DuplicateEmail()
        {
            var name     = "namename";
            var email    = "*****@*****.**";
            var password = "******";

            var dnsLookup       = MockDnsLookup();
            var hashProvider    = MockHashProvider();
            var messagPublisher = AppMocks.MessagingPublisher();

            using var db = AppMocks.CreateInMemoryDB();
            Register register = new Register(db, dnsLookup, hashProvider, messagPublisher, new NullLogger <Register>());

            // First register
            var response = await register.Handle(new RegisterRequest(name, email, password));

            Assert.True(response.Success);
            Assert.Null(response.Error);
            Assert.NotNull(response.Value);
            Assert.NotNull(response.Value.Name);
            Assert.NotEqual(Guid.Empty, response.Value.Id);

            // Second register
            await Assert.ThrowsAsync <SqliteException>(async() => await register.Handle(new RegisterRequest(name, email, password)));
        }
Exemplo n.º 2
0
        private async Task <Result <RegisterResponse> > RegisterUser(IUnitOfWork db, IHashProvider hashProvider, string name, string email, string password)
        {
            var dnsLookup       = MockDnsLookup();
            var publisher       = AppMocks.MessagingPublisher();
            var registerHandler = new Register(db, dnsLookup, hashProvider, publisher, new NullLogger <Register>());
            var regRequest      = new RegisterRequest(name, email, password);
            var regResult       = await registerHandler.Handle(regRequest);

            return(regResult);
        }
Exemplo n.º 3
0
        public async Task Register_DomainWithoutMX()
        {
            using var db = AppMocks.CreateInMemoryDB();
            var dnsLookup       = MockDnsLookup();
            var hashProvider    = MockHashProvider();
            var messagPublisher = AppMocks.MessagingPublisher();
            var register        = new Register(db, dnsLookup, hashProvider, messagPublisher, new NullLogger <Register>());
            var request         = new RegisterRequest("name", "*****@*****.**", "password");

            var response = await register.Handle(request);

            Assert.False(response.Success);
            Assert.NotNull(response.Error);
            Assert.Equal(Error.EMAIL_HOST_UNREACHABLE, response.Error);
            Assert.Null(response.Value);
        }
Exemplo n.º 4
0
        public async Task ConfirmEmail_NotSuccess()
        {
            using var db = AppMocks.CreateInMemoryDB();
            var registerResult = await RegisterUser(db, "name", "*****@*****.**", "password");

            ConfirmEmail confirmEmail = new ConfirmEmail(db, new NullLogger <ConfirmEmail>());

            var dbUserBefore = await db.Users.GetByIDAsync(registerResult.Value.Id);

            Assert.False(dbUserBefore.EmailConfirmed);
            Assert.NotNull(dbUserBefore.EmailConfirmationSecret);

            await confirmEmail.Handle(new ConfirmEmailRequest(registerResult.Value.Id, Guid.NewGuid()));

            var dbUserAfter = await db.Users.GetByIDAsync(registerResult.Value.Id);

            Assert.False(dbUserBefore.EmailConfirmed);
            Assert.NotNull(dbUserBefore.EmailConfirmationSecret);
        }
Exemplo n.º 5
0
        public async Task LoginValidation(string email, string password, string fingerprint, string useragent, bool isValid)
        {
            using var db = AppMocks.CreateInMemoryDB();
            var   hashProvider = MockHashProvider();
            var   tokenService = MockTokenService();
            Login login        = new Login(db, hashProvider, tokenService);
            var   request      = new LoginRequest(email, password, fingerprint, useragent);

            if (isValid)
            {
                var response = await login.Handle(request);

                Assert.False(response.Success);
                Assert.Equal(Error.ACCESS_DENIED, response.Error);
            }
            else
            {
                await Assert.ThrowsAsync <ValidationException>(async() => await login.Handle(request));
            }
        }
Exemplo n.º 6
0
        public async Task Login_Success()
        {
            using var db = AppMocks.CreateInMemoryDB();
            var hashProvider = MockHashProvider();
            var tokenService = MockTokenService();

            var email       = "*****@*****.**";
            var password    = "******";
            var fingerprint = "123123123";
            var useragent   = "12312312312";
            var regResult   = await RegisterUser(db, hashProvider, Guid.NewGuid().ToString(), email, password);

            Assert.True(regResult.Success);

            var loginHandler = new Login(db, hashProvider, tokenService);
            var request      = new LoginRequest(email, password, fingerprint, useragent);

            var response = await loginHandler.Handle(request);

            Assert.True(response.Success);
            Assert.NotNull(response.Value.AuthToken);
            Assert.NotNull(response.Value.RefreshToken);
        }
Exemplo n.º 7
0
        public async Task Login_NotValidPassword()
        {
            using var db = AppMocks.CreateInMemoryDB();
            var hashProvider = MockHashProvider();
            var tokenService = MockTokenService();
            var email        = "*****@*****.**";
            var password     = "******";
            var fingerprint  = "123123123";
            var useragent    = "12312312312";
            var regResult    = await RegisterUser(db, hashProvider, Guid.NewGuid().ToString(), email, password);

            Assert.True(regResult.Success);
            Assert.True(regResult.Success);

            var loginHandler  = new Login(db, hashProvider, tokenService);
            var wrongPassword = "******";
            var request       = new LoginRequest(email, wrongPassword, fingerprint, useragent);

            var response = await loginHandler.Handle(request);

            Assert.False(response.Success);
            Assert.Equal(Error.ACCESS_DENIED, response.Error);
        }
Exemplo n.º 8
0
        public async Task Register_Validation(string name, string email, string password, bool isValid)
        {
            using var db = AppMocks.CreateInMemoryDB();
            var dnsLookup       = MockDnsLookup();
            var hashProvider    = MockHashProvider();
            var messagPublisher = AppMocks.MessagingPublisher();
            var register        = new Register(db, dnsLookup, hashProvider, messagPublisher, new NullLogger <Register>());
            var request         = new RegisterRequest(name, email, password);

            if (isValid)
            {
                var response = await register.Handle(request);

                Assert.True(response.Success);
                Assert.Null(response.Error);
                Assert.NotNull(response.Value);
                Assert.NotNull(response.Value.Name);
                Assert.NotEqual(Guid.Empty, response.Value.Id);
            }
            else
            {
                await Assert.ThrowsAsync <ValidationException>(async() => await register.Handle(request));
            }
        }