Example #1
0
        private void ValidateDerived(JwtSecurityToken jwt, string encodedJwt, DerivedJwtSecurityTokenHandler derivedHandler, TokenValidationParameters tvp, ExpectedException ee)
        {
            try
            {
                if (tvp != null)
                {
                    if (jwt != null)
                    {
                        derivedHandler.ValidateToken(jwt, tvp);
                    }
                    else
                    {
                        derivedHandler.ValidateToken(encodedJwt, tvp);
                    }
                }
                else
                {
                    if (jwt != null)
                    {
                        derivedHandler.ValidateToken(jwt);
                    }
                    else
                    {
                        derivedHandler.ValidateToken(encodedJwt);
                    }
                }

                DerivedJwtSecurityToken jwtDerived = jwt as DerivedJwtSecurityToken;
                if (jwtDerived == null && jwt != null)
                {
                    Assert.IsFalse(derivedHandler.DerivedTokenType == typeof(DerivedJwtSecurityToken), "Expected DerivedJwtSecurityToken type, got: " + jwt.GetType());
                }
                else if (jwtDerived != null)
                {
                    Assert.IsFalse(!jwtDerived.ValidateAudienceCalled, "!jwtDerived.ValidateAudienceCalled");

                    Assert.IsFalse(!jwtDerived.ValidateIssuerCalled, "!jwtDerived.ValidateAudienceCalled");

                    Assert.IsFalse(!jwtDerived.ValidateLifetimeCalled, "!jwtDerived.ValidateLifetimeCalled");

                    Assert.IsFalse(!jwtDerived.ValidateSignatureCalled, "!jwtDerived.ValidateSignatureCalled");

                    Assert.IsFalse(!jwtDerived.ValidateSigningTokenCalled, "!jwtDerived.ValidateSigningTokenCalled");
                }

                ExpectedException.ProcessNoException(ee);
            }
            catch (Exception ex)
            {
                ExpectedException.ProcessException(ee, ex);
            }
        }
 private void ValidateDerived(string jwt, DerivedJwtSecurityTokenHandler handler, TokenValidationParameters validationParameters, ExpectedException expectedException)
 {
     try
     {
         SecurityToken validatedToken;
         handler.ValidateToken(jwt, validationParameters, out validatedToken);
         Assert.IsNotNull(handler.Jwt as DerivedJwtSecurityToken);
         Assert.IsTrue(handler.ReadTokenCalled);
         Assert.IsFalse(handler.ValidateAudienceCalled);
         Assert.IsTrue(handler.ValidateIssuerCalled);
         Assert.IsTrue(handler.ValidateIssuerSigningKeyCalled);
         Assert.IsTrue(handler.ValidateLifetimeCalled);
         Assert.IsTrue(handler.ValidateSignatureCalled);
         expectedException.ProcessNoException();
     }
     catch (Exception ex)
     {
         expectedException.ProcessException(ex);
     }
 }
 private void ValidateDerived(string jwt, DerivedJwtSecurityTokenHandler handler, TokenValidationParameters validationParameters, ExpectedException expectedException)
 {
     try
     {
         SecurityToken validatedToken;
         handler.ValidateToken(jwt, validationParameters, out validatedToken);
         Assert.IsNotNull(handler.Jwt as DerivedJwtSecurityToken);
         Assert.IsTrue(handler.ReadTokenCalled);
         Assert.IsTrue(handler.ValidateAudienceCalled);
         Assert.IsTrue(handler.ValidateIssuerCalled);
         Assert.IsTrue(handler.ValidateIssuerSigningKeyCalled);
         Assert.IsTrue(handler.ValidateLifetimeCalled);
         Assert.IsTrue(handler.ValidateSignatureCalled);
         expectedException.ProcessNoException();
     }
     catch (Exception ex)
     {
         expectedException.ProcessException(ex);
     }
 }