Ejemplo n.º 1
0
        public void UserLockedOutForFailedAttemptsSignin()
        {
            string                 password     = Guid.Empty.ToString();
            IAppIdentity           appIdentity  = DelegatedAppIdentity.Master;
            RecognizedUserIdentity userIdentity = new RecognizedUserIdentity(
                RecognizedUserIdentity.Master.DocType,
                RecognizedUserIdentity.Master.DocNumber,
                password);

            TestContext.CurrentContext.DatabaseHelper().EnsureUserIsNotLocked(userIdentity.DocType, userIdentity.DocNumber);
            int maxFailedPasswordAttempt = TestContext.CurrentContext.DatabaseHelper().GetAppMaxFailedPasswordAttempt(appIdentity.ApiKey);

            void Authenticate() =>
            DelegatedApp.Initialize(CachePolicy.BypassCache)
            .RoutingTo(TestingEndpointProvider.Default)
            .WithIdentity(appIdentity)
            .Authenticate(userIdentity)
            .GetClient();

            AspenException exception;

            for (int index = 1; index < maxFailedPasswordAttempt; index++)
            {
                exception = Assert.Throws <AspenException>(Authenticate);
                Assert.That(exception.EventId, Is.EqualTo("97414"));
                Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
                StringAssert.IsMatch("Combinación de usuario y contraseña invalida. Por favor revise los valores ingresados e intente de nuevo", exception.Message);
            }

            exception = Assert.Throws <AspenException>(Authenticate);
            Assert.That(exception.EventId, Is.EqualTo("97415"));
            Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            StringAssert.IsMatch("Usuario ha sido bloqueado por superar el número máximo de intentos de sesión inválidos", exception.Message);
            TestContext.CurrentContext.DatabaseHelper().EnsureUserIsNotLocked(userIdentity.DocType, userIdentity.DocNumber);
        }
Ejemplo n.º 2
0
        public void InvalidSecretFormatUserProfilePropertiesThrows()
        {
            string        fixedDocType              = "CC";
            string        randomDocNumber           = new Random().Next(1000000000, int.MaxValue).ToString();
            string        password                  = Guid.Empty.ToString();
            IAppIdentity  appIdentity               = DelegatedAppIdentity.Master;
            IUserIdentity tempUserIdentity          = new RecognizedUserIdentity(fixedDocType, randomDocNumber, password);
            Dictionary <string, string> userProfile = new Dictionary <string, string>()
            {
                { "Secret", password },
                { "SecretFormat", "InvalidTypeName" }
            };

            TestContext.CurrentContext.DatabaseHelper().EnsureUserAndProfileInfo(
                appIdentity.ApiKey,
                tempUserIdentity.DocType,
                tempUserIdentity.DocNumber,
                userProfile);

            AspenException exception = Assert.Throws <AspenException>(() =>
            {
                DelegatedApp.Initialize(CachePolicy.BypassCache)
                .RoutingTo(TestingEndpointProvider.Default)
                .WithIdentity(appIdentity)
                .Authenticate(tempUserIdentity)
                .GetClient();
            });

            TestContext.CurrentContext.DatabaseHelper().RemoveUserInfo(tempUserIdentity.DocType, tempUserIdentity.DocNumber);
            Assert.That(exception.EventId, Is.EqualTo("97417"));
            Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.InternalServerError));
            StringAssert.IsMatch("No es posible verificar las credenciales del usuario.", exception.Message);
        }
Ejemplo n.º 3
0
        public void UnrecognizedUserThrows()
        {
            string fixedDocType    = "CC";
            string randomDocNumber = new Random().Next(1000000000, int.MaxValue).ToString();
            string password        = Guid.Empty.ToString();
            RecognizedUserIdentity unrecognizedUserIdentity = new RecognizedUserIdentity(fixedDocType, randomDocNumber, password);

            AspenException exception = Assert.Throws <AspenException>(() =>
            {
                DelegatedApp.Initialize(CachePolicy.BypassCache)
                .RoutingTo(TestingEndpointProvider.Default)
                .WithIdentity(DelegatedAppIdentity.Master)
                .Authenticate(unrecognizedUserIdentity)
                .GetClient();
            });

            Assert.That(exception.EventId, Is.EqualTo("97412"));
            Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            StringAssert.IsMatch("Combinación de usuario y contraseña invalida. Por favor revise los valores ingresados e intente de nuevo", exception.Message);
        }