public void MissingUsernameWhenSignedRequestThrows() { IDelegatedApp client = this.GetDelegatedClient(); ServiceLocator.Instance.RegisterPayloadClaimsManager(InvalidUsernamePayloadClaim.AvoidingClaim()); AspenException exception = Assert.Throws <AspenException>(() => client.Settings.GetDocTypes()); Assert.That(exception.EventId, Is.EqualTo("15852")); Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); StringAssert.IsMatch("'Username' no puede ser nulo ni vacío", exception.Message); }
public void MismatchUsernameWhenUserSignedRequestThrows() { IDelegatedApp client = this.GetDelegatedClient(); IUserIdentity userIdentityHelper = RecognizedUserIdentity.Helper; IPayloadClaimsManager mismatchUsernameClaimBehavior = InvalidUsernamePayloadClaim.WithClaimBehavior(() => $"{userIdentityHelper.DocType}-{userIdentityHelper.DocNumber}"); ServiceLocator.Instance.RegisterPayloadClaimsManager(mismatchUsernameClaimBehavior); AspenException exception = Assert.Throws <AspenException>(() => client.Settings.GetDocTypes()); Assert.That(exception.EventId, Is.EqualTo("15846")); Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized)); StringAssert.IsMatch("No coinciden los datos recibidos del token vs los valores esperados. ¿Se modificaron los valores en tránsito o está utilizando el ApiKey en otra aplicación?", exception.Message); }
public void NotFoundUsernameWhenUserSignedRequestThrows() { IDelegatedApp client = this.GetDelegatedClient(); string fixedDocType = "CC"; string randomDocNumber = new Random().Next(1000000000, int.MaxValue).ToString(); IPayloadClaimsManager randomUsernameClaimBehavior = InvalidUsernamePayloadClaim.WithClaimBehavior(() => $"{fixedDocType}-{randomDocNumber}"); ServiceLocator.Instance.RegisterPayloadClaimsManager(randomUsernameClaimBehavior); AspenException exception = Assert.Throws <AspenException>(() => client.Settings.GetDocTypes()); Assert.That(exception.EventId, Is.EqualTo("15847")); Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized)); StringAssert.IsMatch("No hay un token de autenticación vigente.", exception.Message); }
public void NullOrEmptyUsernameWhenSignedRequestThrows() { IDelegatedApp client = this.GetDelegatedClient(); IList <IPayloadClaimsManager> payloadBehaviors = new List <IPayloadClaimsManager>() { InvalidUsernamePayloadClaim.WithClaimBehavior(() => null), InvalidUsernamePayloadClaim.WithClaimBehavior(() => string.Empty), InvalidUsernamePayloadClaim.WithClaimBehavior(() => " ") }; foreach (IPayloadClaimsManager behavior in payloadBehaviors) { ServiceLocator.Instance.RegisterPayloadClaimsManager(behavior); AspenException exception = Assert.Throws <AspenException>(() => client.Settings.GetDocTypes()); Assert.That(exception.EventId, Is.EqualTo("15852")); Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); StringAssert.IsMatch("'Username' no puede ser nulo ni vacío", exception.Message); } }
public void InvalidFormatUsernameWhenSignedRequestThrows() { IDelegatedApp client = this.GetDelegatedClient(); IList <IPayloadClaimsManager> payloadBehaviors = new List <IPayloadClaimsManager>() { InvalidUsernamePayloadClaim.WithClaimBehavior(() => "CC|123456"), InvalidUsernamePayloadClaim.WithClaimBehavior(() => "cc-abcdef"), InvalidUsernamePayloadClaim.WithClaimBehavior(() => "1234656"), InvalidUsernamePayloadClaim.WithClaimBehavior(() => "*****@*****.**"), InvalidUsernamePayloadClaim.WithClaimBehavior(() => Environment.UserName), InvalidUsernamePayloadClaim.WithClaimBehavior(() => Guid.NewGuid().ToString()) }; foreach (IPayloadClaimsManager behavior in payloadBehaviors) { ServiceLocator.Instance.RegisterPayloadClaimsManager(behavior); AspenException exception = Assert.Throws <AspenException>(() => client.Settings.GetDocTypes()); Assert.That(exception.EventId, Is.EqualTo("15852")); Assert.That(exception.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); StringAssert.IsMatch("'Username' debe coincidir con el patrón", exception.Message); } }