Beispiel #1
0
        public void ValidateEmail()
        {
            string id                         = "1234";
            string validationCode             = "abcdefghi";
            ServerConfiguration configuration = new ServerConfiguration()
            {
                JwtSecretKey = "secret"
            };

            User tmpUser = Users.CreateNewUser("*****@*****.**")
                           .SetPassword("password123");

            tmpUser.id = id;
            tmpUser.emailValidationCode    = validationCode;
            tmpUser.emailValidationExpires = DateTime.Now.AddHours(1);

            string jwt = Tokens.TokenForUser(tmpUser, DateTime.Now.AddHours(-1), "secret");

            DataProviderMock.When(x => x.GetUserByEmailValidation(validationCode)).Return(Task.FromResult <User>(tmpUser));
            DataProviderMock.When(x => x.SaveUser(It.IsAny <User>())).Return(Task.FromResult(BlueDogResult.Ok));

            UserServices  userServices = new UserServices(DataProviderMock);
            BlueDogResult res          = BlueDogResult.Ok;

            Task.Run(async() =>
            {
                res = await userServices.ValidateEmail("*****@*****.**", validationCode, configuration);
            }).Wait();

            Assert.AreEqual(res, BlueDogResult.Ok);
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> Register(HttpRequestMessage req, TraceWriter log)
        {
            string email = await req.QueryOrBody("email");

            string password = await req.QueryOrBody("password");

            string passlog = password != null ? "###" : "<null>";

            log.Info($"Logging in with {email} and {passlog}");


            BlueDogResult result = await UserServices.Register(email, password, ServerConfiguration);

            ResponseCode code = result == BlueDogResult.Ok ? ResponseCode.Ok : ResponseCode.EmailInUse;


            return(req.CreateResponse(HttpStatusCode.OK, new ServerResponse {
                status = code
            }));
        }
Beispiel #3
0
        public void ValidateEmailBadEmail()
        {
            string validationCode             = "abcdefghi";
            ServerConfiguration configuration = new ServerConfiguration()
            {
                JwtSecretKey = "secret"
            };

            DataProviderMock.When(x => x.GetUserByEmailValidation(validationCode)).Return(Task.FromResult <User>(null));

            UserServices  userServices = new UserServices(DataProviderMock);
            BlueDogResult res          = BlueDogResult.Ok;

            Task.Run(async() =>
            {
                res = await userServices.ValidateEmail("*****@*****.**", validationCode, configuration);
            }).Wait();

            Assert.AreEqual(res, BlueDogResult.NoSuchUser);
        }
Beispiel #4
0
        public void RegisterUserEmailUsed()
        {
            ServerConfiguration configuration = new ServerConfiguration
            {
                JwtSecretKey = "secret"
            };

            BlueDogResult res = BlueDogResult.Ok;

            DataProviderMock.When(x => x.GetUserByEmail(It.IsAny <string>())).Return(Task.FromResult <User>(new User()));
            UserServices userServices = new UserServices(DataProviderMock);

            Task.Run(async() =>
            {
                res = await userServices.Register("*****@*****.**", "password123", configuration);
            }).Wait();

            DataProviderMock.Verify(x => x.GetUserByEmail("*****@*****.**")).WasCalledExactlyOnce();
            Assert.AreEqual(res, BlueDogResult.EmailInUse);

            Console.WriteLine("Done");
        }
Beispiel #5
0
        public void CompletePasswordResetBadEmail()
        {
            string id                         = "1234";
            string validationCode             = "abcdefghi";
            ServerConfiguration configuration = new ServerConfiguration()
            {
                JwtSecretKey = "secret",
                PasswordResetDurationMinutes = 30
            };

            DataProviderMock.When(x => x.GetUserByEmail("*****@*****.**")).Return(Task.FromResult <User>(null));
            DataProviderMock.When(x => x.SaveUser(It.IsAny <User>())).Return(Task.FromResult(BlueDogResult.Ok));

            UserServices  userServices = new UserServices(DataProviderMock);
            BlueDogResult res          = BlueDogResult.Ok;

            Task.Run(async() =>
            {
                res = await userServices.CompleteResetPassword("*****@*****.**", validationCode, "newpass", configuration);
            }).Wait();

            Assert.AreEqual(res, BlueDogResult.NoSuchUser);
        }
Beispiel #6
0
 public StartResetEmailResult(BlueDogResult result) : base(result)
 {
 }
Beispiel #7
0
 public StartResetPasswordResult(BlueDogResult result) : base(result)
 {
 }
Beispiel #8
0
 public UserResult(BlueDogResult result) : base(result)
 {
 }
Beispiel #9
0
 public LoginResult(BlueDogResult result) : base(result)
 {
 }
Beispiel #10
0
 /// <summary>
 /// Initializases the result.
 /// </summary>
 /// <param name="result"></param>
 public UserServiceResult(BlueDogResult result)
 {
     Result = result;
 }