Example #1
0
        public void InvalidRegInfoQuestion()
        {
            var user = new UserCredential("TeamOutcast", "Spring2018");

            var securityQuestions = new List <SecurityQuestion>();

            securityQuestions.Add(new SecurityQuestion("What is your favorite sports team?", "Patriots"));
            securityQuestions.Add(new SecurityQuestion("What is your favorite song?", "Baldwin Park"));
            securityQuestions.Add(new SecurityQuestion("What is your favorite song?", "Pokemon"));

            var userLocation = new Address("1653 La Golondrina Ave", "Alhambra", "California", "91803");

            var regInfo = new RegInfo()
            {
                UserCredInfo   = user,
                SecurityQandAs = securityQuestions,
                UserLocation   = userLocation
            };

            RegInfoValidator   validator = new RegInfoValidator();
            RegInfoResponseDTO dto       = new RegInfoResponseDTO();

            dto = validator.Validate(regInfo);
            Assert.False(dto.isSuccessful);
            Assert.Equal(AccountConstants.QUESTION_INVALID_ERROR, dto.Messages.First());
        }
        public IHttpActionResult DisableUser([FromBody] UserManagementDTO obj)
        {
            // Filter if no username was passed
            if (obj.UserName == null || !ModelState.IsValid)
            {
                return(Content(HttpStatusCode.BadRequest, "Failure: Bad Request"));
            }
            // Pass input through business rules to see if a valid username was passed
            RegInfoValidator validator = new RegInfoValidator();

            if (!validator.ValidateUserName(obj.UserName))
            {
                return(Content(HttpStatusCode.BadRequest, "Failure: No valid data."));
            }
            // Implement the actual status change of that user
            UserManagementService service = new UserManagementService();
            var response = service.DisableUser(obj);

            if (!response.IsSuccessful)
            {
                return(Content(HttpStatusCode.BadRequest, response.Messages));
            }
            // Everything was successful, returning message
            return(Content(HttpStatusCode.OK, "Success: Account was disabled for " + obj.UserName));
        }
Example #3
0
        public void ValidRegInfo()
        {
            var user = new UserCredential("TeamOutcast", "Spring2018");

            var securityQuestions = new List <SecurityQuestion>();

            securityQuestions.Add(new SecurityQuestion("What is your favorite sports team?", "Patriots"));
            securityQuestions.Add(new SecurityQuestion("In what city or town does your nearest sibling live?", "Baldwin Park"));
            securityQuestions.Add(new SecurityQuestion("What is your favorite song?", "Pokemon"));

            var userLocation = new Address("1653 La Golondrina Ave", "Alhambra", "California", "91803");

            var regInfo = new RegInfo()
            {
                UserCredInfo   = user,
                SecurityQandAs = securityQuestions,
                UserLocation   = userLocation
            };

            RegInfoValidator   validator = new RegInfoValidator();
            RegInfoResponseDTO dto       = new RegInfoResponseDTO();

            dto = validator.Validate(regInfo);

            //JObject json = validator.result;
            //Assert.Equal(json["results"][0]["address_components"][3]["long_name"], "Los Angeles County");

            Assert.True(dto.isSuccessful);
        }
Example #4
0
        /// <summary>
        /// Validates Registration Information
        /// </summary>
        /// <param name="creds"> Registration Information </param>
        /// <returns> status of the validation </returns>
        public bool ValidateCredentials(RegInfo creds)
        {
            var validator = new RegInfoValidator();

            // validates Register info
            Response     = validator.Validate(creds);
            UserLocation = validator.ValidatedLocation;
            return(Response.isSuccessful);
        }
Example #5
0
        public void DuplicateQuestions()
        {
            var securityQuestions        = new List <SecurityQuestion>();
            RegInfoValidator   validator = new RegInfoValidator();
            RegInfoResponseDTO dto       = new RegInfoResponseDTO();

            // Testing for duplicate Security Question
            securityQuestions.Add(new SecurityQuestion("What is your favorite sports team?", "Patriots"));
            securityQuestions.Add(new SecurityQuestion("What is your favorite sports team?", "Patriots"));
            securityQuestions.Add(new SecurityQuestion("What is your favorite song?", "Pokemon Theme Song"));
            Assert.False(validator.ValidateQandAs(securityQuestions, dto));
            Assert.Equal(dto.Messages.ElementAt(0), AccountConstants.QUESTION_INVALID_ERROR);
        }
Example #6
0
        public void ValidateUsername()
        {
            UserCredential     user      = new UserCredential("TestUser55", "Spring2018");
            RegInfoValidator   validator = new RegInfoValidator();
            RegInfoResponseDTO dto       = new RegInfoResponseDTO();

            Assert.False(validator.ValidateUserCred(user, dto));

            Assert.False(dto.isSuccessful);
            Assert.Equal("Username already exists. Please try again", dto.Messages.ElementAt(0));

            user = new UserCredential("TeamO¶tcast", "Spring2018");
            Assert.False(validator.ValidateUserCred(user, dto));
            Assert.Equal(dto.Messages.ElementAt(0), AccountConstants.USERNAME_INVALID_CHARACTERS_ERROR);
        }
Example #7
0
        public void ValidateUserPassword()
        {
            UserCredential     user      = new UserCredential("TeamOutcast", "Spring");
            RegInfoValidator   validator = new RegInfoValidator();
            RegInfoResponseDTO dto       = new RegInfoResponseDTO();

            Assert.False(validator.ValidateUserCred(user, dto));

            Assert.False(dto.isSuccessful);
            Assert.Equal(dto.Messages.ElementAt(0), AccountConstants.PASSWORD_SHORT_ERROR);

            user = new UserCredential("TeamOutcast", "Spring2018");
            Assert.True(validator.ValidateUserCred(user, dto));

            user = new UserCredential("TeamOutcast", "Sprin¶g2018");
            Assert.False(validator.ValidateUserCred(user, dto));
            Assert.Equal(dto.Messages.ElementAt(0), AccountConstants.PASSWORD_INVALID_CHARACTERS_ERROR);
        }
Example #8
0
        public void InvalidAnswer()
        {
            var securityQuestions        = new List <SecurityQuestion>();
            RegInfoValidator   validator = new RegInfoValidator();
            RegInfoResponseDTO dto       = new RegInfoResponseDTO();

            securityQuestions.Add(new SecurityQuestion("What is your favorite sports team?", "Patriots"));
            securityQuestions.Add(new SecurityQuestion("In what city or town does your nearest sibling live?", "Baldwin Park"));
            securityQuestions.Add(new SecurityQuestion("What is your favorite song?", ""));

            Assert.False(validator.ValidateQandAs(securityQuestions, dto));
            Assert.Equal(dto.Messages.ElementAt(0), AccountConstants.ANSWER_INVALID_ERROR);

            securityQuestions.Clear();
            securityQuestions.Add(new SecurityQuestion("What is your favorite sports team?", "Patriots"));
            securityQuestions.Add(new SecurityQuestion("In what city or town does your nearest sibling live?", "Baldwin Park"));
            securityQuestions.Add(new SecurityQuestion("What is your favorite song?", null));

            Assert.False(validator.ValidateQandAs(securityQuestions, dto));
            Assert.Equal(dto.Messages.ElementAt(0), AccountConstants.ANSWER_INVALID_ERROR);
        }