public void Publics() { TokenValidationParameters validationParameters = new TokenValidationParameters(); Type type = typeof(TokenValidationParameters); PropertyInfo[] properties = type.GetProperties(); if (properties.Length != 35) { Assert.True(false, "Number of properties has changed from 35 to: " + properties.Length + ", adjust tests"); } TokenValidationParameters actorValidationParameters = new TokenValidationParameters(); SecurityKey issuerSigningKey = KeyingMaterial.DefaultX509Key_Public_2048; SecurityKey issuerSigningKey2 = KeyingMaterial.RsaSecurityKey_2048; List <SecurityKey> issuerSigningKeys = new List <SecurityKey> { KeyingMaterial.DefaultX509Key_Public_2048, KeyingMaterial.RsaSecurityKey_2048 }; List <SecurityKey> issuerSigningKeysDup = new List <SecurityKey> { KeyingMaterial.DefaultX509Key_Public_2048, KeyingMaterial.RsaSecurityKey_2048 }; string validAudience = "ValidAudience"; List <string> validAudiences = new List <string> { validAudience }; string validIssuer = "ValidIssuer"; List <string> validIssuers = new List <string> { validIssuer }; TokenValidationParameters validationParametersInline = new TokenValidationParameters() { ActorValidationParameters = actorValidationParameters, AudienceValidator = ValidationDelegates.AudienceValidatorReturnsTrue, IssuerSigningKey = issuerSigningKey, IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return(new List <SecurityKey> { issuerSigningKey }); }, IssuerSigningKeys = issuerSigningKeys, IssuerValidator = ValidationDelegates.IssuerValidatorEcho, LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue, SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs, SaveSigninToken = true, ValidateAudience = false, ValidateIssuer = false, ValidAudience = validAudience, ValidAudiences = validAudiences, ValidIssuer = validIssuer, ValidIssuers = validIssuers, }; Assert.True(object.ReferenceEquals(actorValidationParameters, validationParametersInline.ActorValidationParameters)); Assert.True(object.ReferenceEquals(validationParametersInline.IssuerSigningKey, issuerSigningKey)); Assert.True(validationParametersInline.SaveSigninToken); Assert.False(validationParametersInline.ValidateAudience); Assert.False(validationParametersInline.ValidateIssuer); Assert.True(object.ReferenceEquals(validationParametersInline.ValidAudience, validAudience)); Assert.True(object.ReferenceEquals(validationParametersInline.ValidAudiences, validAudiences)); Assert.True(object.ReferenceEquals(validationParametersInline.ValidIssuer, validIssuer)); TokenValidationParameters validationParametersSets = new TokenValidationParameters(); validationParametersSets.ActorValidationParameters = actorValidationParameters; validationParametersSets.AudienceValidator = ValidationDelegates.AudienceValidatorReturnsTrue; validationParametersSets.IssuerSigningKey = KeyingMaterial.DefaultX509Key_Public_2048; validationParametersSets.IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return(new List <SecurityKey> { issuerSigningKey2 }); }; validationParametersSets.IssuerSigningKeys = issuerSigningKeysDup; validationParametersSets.IssuerValidator = ValidationDelegates.IssuerValidatorEcho; validationParametersSets.LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue; validationParametersSets.SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs; validationParametersSets.SaveSigninToken = true; validationParametersSets.ValidateAudience = false; validationParametersSets.ValidateIssuer = false; validationParametersSets.ValidAudience = validAudience; validationParametersSets.ValidAudiences = validAudiences; validationParametersSets.ValidIssuer = validIssuer; validationParametersSets.ValidIssuers = validIssuers; var compareContext = new CompareContext(); IdentityComparer.AreEqual(validationParametersInline, validationParametersSets, compareContext); TokenValidationParameters tokenValidationParametersCloned = validationParametersInline.Clone() as TokenValidationParameters; IdentityComparer.AreEqual(tokenValidationParametersCloned, validationParametersInline, compareContext); //tokenValidationParametersCloned.AudienceValidator(new string[]{"bob"}, JwtTestTokens.Simple(); string id = Guid.NewGuid().ToString(); DerivedTokenValidationParameters derivedValidationParameters = new DerivedTokenValidationParameters(id, validationParametersInline); DerivedTokenValidationParameters derivedValidationParametersCloned = derivedValidationParameters.Clone() as DerivedTokenValidationParameters; IdentityComparer.AreEqual(derivedValidationParameters, derivedValidationParametersCloned, compareContext); IdentityComparer.AreEqual(derivedValidationParameters.InternalString, derivedValidationParametersCloned.InternalString, compareContext); TestUtilities.AssertFailIfErrors("TokenValidationParameters", compareContext.Diffs); }
protected DerivedTokenValidationParameters(DerivedTokenValidationParameters other) : base(other) { _internalString = other._internalString; }
public void TokenValidationParameters_Publics() { TokenValidationParameters validationParameters = new TokenValidationParameters(); Type type = typeof(TokenValidationParameters); PropertyInfo[] properties = type.GetProperties(); if (properties.Length != 30) { Assert.Fail("Number of properties has changed from 30 to: " + properties.Length + ", adjust tests"); } SecurityKey issuerSigningKey = KeyingMaterial.DefaultSymmetricSecurityKey_256; SecurityKey issuerSigningKey2 = KeyingMaterial.SymmetricSecurityKey2_256; List <SecurityKey> issuerSigningKeys = new List <SecurityKey> { KeyingMaterial.DefaultSymmetricSecurityKey_256, KeyingMaterial.SymmetricSecurityKey2_256 }; List <SecurityKey> issuerSigningKeysDup = new List <SecurityKey> { new InMemorySymmetricSecurityKey(KeyingMaterial.SymmetricKeyBytes2_256), new InMemorySymmetricSecurityKey(KeyingMaterial.DefaultSymmetricKeyBytes_256) }; string validAudience = "ValidAudience"; List <string> validAudiences = new List <string> { validAudience }; string validIssuer = "ValidIssuer"; List <string> validIssuers = new List <string> { validIssuer }; TokenValidationParameters validationParametersInline = new TokenValidationParameters() { AudienceValidator = IdentityUtilities.AudienceValidatorReturnsTrue, IssuerSigningKey = issuerSigningKey, IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return(issuerSigningKey); }, IssuerSigningKeys = issuerSigningKeys, IssuerValidator = IdentityUtilities.IssuerValidatorEcho, LifetimeValidator = IdentityUtilities.LifetimeValidatorReturnsTrue, SaveSigninToken = true, ValidateAudience = false, ValidateIssuer = false, ValidAudience = validAudience, ValidAudiences = validAudiences, ValidIssuer = validIssuer, ValidIssuers = validIssuers, }; Assert.IsTrue(object.ReferenceEquals(validationParametersInline.IssuerSigningKey, issuerSigningKey)); Assert.IsTrue(validationParametersInline.SaveSigninToken); Assert.IsFalse(validationParametersInline.ValidateAudience); Assert.IsFalse(validationParametersInline.ValidateIssuer); Assert.IsTrue(object.ReferenceEquals(validationParametersInline.ValidAudience, validAudience)); Assert.IsTrue(object.ReferenceEquals(validationParametersInline.ValidAudiences, validAudiences)); Assert.IsTrue(object.ReferenceEquals(validationParametersInline.ValidIssuer, validIssuer)); TokenValidationParameters validationParametersSets = new TokenValidationParameters(); validationParametersSets.AudienceValidator = IdentityUtilities.AudienceValidatorReturnsTrue; validationParametersSets.IssuerSigningKey = new InMemorySymmetricSecurityKey(KeyingMaterial.DefaultSymmetricKeyBytes_256); validationParametersSets.IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return(issuerSigningKey2); }; validationParametersSets.IssuerSigningKeys = issuerSigningKeysDup; validationParametersSets.IssuerValidator = IdentityUtilities.IssuerValidatorEcho; validationParametersSets.LifetimeValidator = IdentityUtilities.LifetimeValidatorReturnsTrue; validationParametersSets.SaveSigninToken = true; validationParametersSets.ValidateAudience = false; validationParametersSets.ValidateIssuer = false; validationParametersSets.ValidAudience = validAudience; validationParametersSets.ValidAudiences = validAudiences; validationParametersSets.ValidIssuer = validIssuer; validationParametersSets.ValidIssuers = validIssuers; Assert.IsTrue(IdentityComparer.AreEqual <TokenValidationParameters>(validationParametersInline, validationParametersSets)); TokenValidationParameters tokenValidationParametersCloned = validationParametersInline.Clone() as TokenValidationParameters; Assert.IsTrue(IdentityComparer.AreEqual <TokenValidationParameters>(tokenValidationParametersCloned, validationParametersInline)); //tokenValidationParametersCloned.AudienceValidator(new string[]{"bob"}, JwtTestTokens.Simple(); string id = Guid.NewGuid().ToString(); DerivedTokenValidationParameters derivedValidationParameters = new DerivedTokenValidationParameters(id, validationParametersInline); DerivedTokenValidationParameters derivedValidationParametersCloned = derivedValidationParameters.Clone() as DerivedTokenValidationParameters; Assert.IsTrue(IdentityComparer.AreEqual <TokenValidationParameters>(derivedValidationParameters, derivedValidationParametersCloned)); Assert.AreEqual(derivedValidationParameters.InternalString, derivedValidationParametersCloned.InternalString); }
public void Publics() { TokenValidationParameters validationParameters = new TokenValidationParameters(); Type type = typeof(TokenValidationParameters); PropertyInfo[] properties = type.GetProperties(); if (properties.Length != 43) { Assert.True(false, "Number of properties has changed from 43 to: " + properties.Length + ", adjust tests"); } TokenValidationParameters actorValidationParameters = new TokenValidationParameters(); SecurityKey issuerSigningKey = KeyingMaterial.DefaultX509Key_2048_Public; SecurityKey issuerSigningKey2 = KeyingMaterial.RsaSecurityKey_2048; List <SecurityKey> issuerSigningKeys = new List <SecurityKey> { KeyingMaterial.DefaultX509Key_2048_Public, KeyingMaterial.RsaSecurityKey_2048 }; List <SecurityKey> issuerSigningKeysDup = new List <SecurityKey> { KeyingMaterial.DefaultX509Key_2048_Public, KeyingMaterial.RsaSecurityKey_2048 }; string validAudience = "ValidAudience"; List <string> validAudiences = new List <string> { validAudience }; string validIssuer = "ValidIssuer"; List <string> validIssuers = new List <string> { validIssuer }; var propertyBag = new Dictionary <string, Object> { { "CustomKey", "CustomValue" } }; TypeValidator typeValidator = (typ, token, parameters) => "ActualType"; AlgorithmValidator algorithmValidator = ValidationDelegates.AlgorithmValidatorBuilder(false); var validTypes = new List <string> { "ValidType1", "ValidType2", "ValidType3" }; var validAlgorithms = new List <string> { "RSA2048", "RSA1024" }; TokenValidationParameters validationParametersInline = new TokenValidationParameters() { AlgorithmValidator = algorithmValidator, ActorValidationParameters = actorValidationParameters, AudienceValidator = ValidationDelegates.AudienceValidatorReturnsTrue, IssuerSigningKey = issuerSigningKey, IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return(new List <SecurityKey> { issuerSigningKey }); }, IssuerSigningKeys = issuerSigningKeys, IssuerValidator = ValidationDelegates.IssuerValidatorEcho, LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue, PropertyBag = propertyBag, SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs, SaveSigninToken = true, TypeValidator = typeValidator, ValidAlgorithms = validAlgorithms, ValidateAudience = false, ValidateIssuer = false, ValidAudience = validAudience, ValidAudiences = validAudiences, ValidIssuer = validIssuer, ValidIssuers = validIssuers, ValidTypes = validTypes }; Assert.True(object.ReferenceEquals(actorValidationParameters, validationParametersInline.ActorValidationParameters)); Assert.True(object.ReferenceEquals(validationParametersInline.IssuerSigningKey, issuerSigningKey)); Assert.True(object.ReferenceEquals(validationParametersInline.PropertyBag, propertyBag)); Assert.True(validationParametersInline.SaveSigninToken); Assert.False(validationParametersInline.ValidateAudience); Assert.False(validationParametersInline.ValidateIssuer); Assert.True(object.ReferenceEquals(validationParametersInline.ValidAlgorithms, validAlgorithms)); Assert.True(object.ReferenceEquals(validationParametersInline.AlgorithmValidator, algorithmValidator)); Assert.True(object.ReferenceEquals(validationParametersInline.TypeValidator, typeValidator)); Assert.True(object.ReferenceEquals(validationParametersInline.ValidAudience, validAudience)); Assert.True(object.ReferenceEquals(validationParametersInline.ValidAudiences, validAudiences)); Assert.True(object.ReferenceEquals(validationParametersInline.ValidIssuer, validIssuer)); Assert.True(validationParametersInline.IgnoreTrailingSlashWhenValidatingAudience); TokenValidationParameters validationParametersSets = new TokenValidationParameters(); validationParametersSets.AlgorithmValidator = algorithmValidator; validationParametersSets.ActorValidationParameters = actorValidationParameters; validationParametersSets.AudienceValidator = ValidationDelegates.AudienceValidatorReturnsTrue; validationParametersSets.IssuerSigningKey = KeyingMaterial.DefaultX509Key_2048_Public; validationParametersSets.IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return(new List <SecurityKey> { issuerSigningKey2 }); }; validationParametersSets.IssuerSigningKeys = issuerSigningKeysDup; validationParametersSets.IssuerValidator = ValidationDelegates.IssuerValidatorEcho; validationParametersSets.LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue; validationParametersSets.PropertyBag = propertyBag; validationParametersSets.SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs; validationParametersSets.SaveSigninToken = true; validationParametersSets.TypeValidator = typeValidator; validationParametersSets.ValidateAudience = false; validationParametersSets.ValidateIssuer = false; validationParametersSets.ValidAlgorithms = validAlgorithms; validationParametersSets.ValidAudience = validAudience; validationParametersSets.ValidAudiences = validAudiences; validationParametersSets.ValidIssuer = validIssuer; validationParametersSets.ValidIssuers = validIssuers; validationParametersSets.ValidTypes = validTypes; var compareContext = new CompareContext(); IdentityComparer.AreEqual(validationParametersInline, validationParametersSets, compareContext); IdentityComparer.AreEqual(validationParametersInline.Clone() as TokenValidationParameters, validationParametersInline, compareContext); string id = Guid.NewGuid().ToString(); DerivedTokenValidationParameters derivedValidationParameters = new DerivedTokenValidationParameters(id, validationParametersInline); DerivedTokenValidationParameters derivedValidationParametersCloned = derivedValidationParameters.Clone() as DerivedTokenValidationParameters; IdentityComparer.AreEqual(derivedValidationParameters, derivedValidationParametersCloned, compareContext); IdentityComparer.AreEqual(derivedValidationParameters.InternalString, derivedValidationParametersCloned.InternalString, compareContext); TestUtilities.AssertFailIfErrors(compareContext); }
protected DerivedTokenValidationParameters(DerivedTokenValidationParameters other) : base(other) { _internalString = other._internalString; }
public void TokenValidationParameters_Publics() { TokenValidationParameters validationParameters = new TokenValidationParameters(); Type type = typeof(TokenValidationParameters); PropertyInfo[] properties = type.GetProperties(); if (properties.Length != 30) Assert.Fail("Number of properties has changed from 30 to: " + properties.Length + ", adjust tests"); SecurityKey issuerSigningKey = KeyingMaterial.DefaultSymmetricSecurityKey_256; SecurityKey issuerSigningKey2 = KeyingMaterial.SymmetricSecurityKey2_256; List<SecurityKey> issuerSigningKeys = new List<SecurityKey> { KeyingMaterial.DefaultSymmetricSecurityKey_256, KeyingMaterial.SymmetricSecurityKey2_256 }; List<SecurityKey> issuerSigningKeysDup = new List<SecurityKey> { new InMemorySymmetricSecurityKey(KeyingMaterial.SymmetricKeyBytes2_256), new InMemorySymmetricSecurityKey(KeyingMaterial.DefaultSymmetricKeyBytes_256) }; string validAudience = "ValidAudience"; List<string> validAudiences = new List<string>{ validAudience }; string validIssuer = "ValidIssuer"; List<string> validIssuers = new List<string>{ validIssuer }; TokenValidationParameters validationParametersInline = new TokenValidationParameters() { AudienceValidator = IdentityUtilities.AudienceValidatorDoesNotThrow, IssuerSigningKey = issuerSigningKey, IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return issuerSigningKey; }, IssuerSigningKeys = issuerSigningKeys, IssuerValidator = IdentityUtilities.IssuerValidatorEcho, LifetimeValidator = IdentityUtilities.LifetimeValidatorDoesNotThrow, SaveSigninToken = true, ValidateAudience = false, ValidateIssuer = false, ValidAudience = validAudience, ValidAudiences = validAudiences, ValidIssuer = validIssuer, ValidIssuers = validIssuers, }; Assert.IsTrue(object.ReferenceEquals(validationParametersInline.IssuerSigningKey, issuerSigningKey)); Assert.IsTrue(validationParametersInline.SaveSigninToken); Assert.IsFalse(validationParametersInline.ValidateAudience); Assert.IsFalse(validationParametersInline.ValidateIssuer); Assert.IsTrue(object.ReferenceEquals(validationParametersInline.ValidAudience, validAudience)); Assert.IsTrue(object.ReferenceEquals(validationParametersInline.ValidAudiences, validAudiences)); Assert.IsTrue(object.ReferenceEquals(validationParametersInline.ValidIssuer, validIssuer)); TokenValidationParameters validationParametersSets = new TokenValidationParameters(); validationParametersSets.AudienceValidator = IdentityUtilities.AudienceValidatorDoesNotThrow; validationParametersSets.IssuerSigningKey = new InMemorySymmetricSecurityKey(KeyingMaterial.DefaultSymmetricKeyBytes_256); validationParametersSets.IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tvp) => { return issuerSigningKey2; }; validationParametersSets.IssuerSigningKeys = issuerSigningKeysDup; validationParametersSets.IssuerValidator = IdentityUtilities.IssuerValidatorEcho; validationParametersSets.LifetimeValidator = IdentityUtilities.LifetimeValidatorDoesNotThrow; validationParametersSets.SaveSigninToken = true; validationParametersSets.ValidateAudience = false; validationParametersSets.ValidateIssuer = false; validationParametersSets.ValidAudience = validAudience; validationParametersSets.ValidAudiences = validAudiences; validationParametersSets.ValidIssuer = validIssuer; validationParametersSets.ValidIssuers = validIssuers; Assert.IsTrue(IdentityComparer.AreEqual<TokenValidationParameters>(validationParametersInline, validationParametersSets)); var tokenValidationParametersCloned = validationParametersInline.Clone(); Assert.IsTrue(IdentityComparer.AreEqual<TokenValidationParameters>(tokenValidationParametersCloned, validationParametersInline)); //tokenValidationParametersCloned.AudienceValidator(new string[]{"bob"}, JwtTestTokens.Simple(); string id = Guid.NewGuid().ToString(); DerivedTokenValidationParameters derivedValidationParameters = new DerivedTokenValidationParameters(id, validationParametersInline); DerivedTokenValidationParameters derivedValidationParametersCloned = derivedValidationParameters.Clone() as DerivedTokenValidationParameters; Assert.IsTrue(IdentityComparer.AreEqual<TokenValidationParameters>(derivedValidationParameters, derivedValidationParametersCloned)); Assert.AreEqual(derivedValidationParameters.InternalString, derivedValidationParametersCloned.InternalString); }