Skip to content

Commit

Permalink
Update tests to use CsClaimsIdentity.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaytak committed Jul 12, 2024
1 parent c4bbcf6 commit b19d572
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public CaseSensitiveClaimsIdentity() : base()
{
}

/// <summary>
/// Initializes an instance of <see cref="CaseSensitiveClaimsIdentity"/>.
/// </summary>
/// <param name="authenticationType">The authentication method used to establish this identity.</param>
public CaseSensitiveClaimsIdentity(string authenticationType) : base(authenticationType)
{
}

/// <summary>
/// Initializes an instance of <see cref="CaseSensitiveClaimsIdentity"/>.
/// </summary>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void BoolClaimsEncodedAsExpected()
SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
{
SigningCredentials = creds,
Subject = new ClaimsIdentity(claims),
Subject = new CaseSensitiveClaimsIdentity(claims),
Expires = (new DateTime(2038, 1, 20)).ToUniversalTime(),
};

Expand Down Expand Up @@ -108,7 +108,7 @@ public void DateTime2038Issue()
SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
{
SigningCredentials = creds,
Subject = new ClaimsIdentity(claims),
Subject = new CaseSensitiveClaimsIdentity(claims),
Expires = (new DateTime(2038, 1, 20)).ToUniversalTime(),
};

Expand All @@ -130,7 +130,7 @@ public void JWETouchAllProperties()
{
SigningCredentials = KeyingMaterial.JsonWebKeyRsa256SigningCredentials,
EncryptingCredentials = KeyingMaterial.DefaultSymmetricEncryptingCreds_Aes256_Sha512_512,
Subject = new ClaimsIdentity(Default.PayloadClaims),
Subject = new CaseSensitiveClaimsIdentity(Default.PayloadClaims),
TokenType = "TokenType"
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void LogSecurityArtifactTest()
var jwsTokenDescriptor = new SecurityTokenDescriptor
{
SigningCredentials = KeyingMaterial.JsonWebKeyRsa256SigningCredentials,
Subject = new ClaimsIdentity(Default.PayloadClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.PayloadClaims)
};

string stringJwe = new JsonWebTokenHandler().CreateToken(jweTokenDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private static SamlSecurityToken CreateSamlToken(IList<Claim> claims)
IssuedAt = Default.IssueInstant,
Issuer = Default.Issuer,
SigningCredentials = Default.AsymmetricSigningCredentials,
Subject = new ClaimsIdentity(claims)
Subject = new CaseSensitiveClaimsIdentity(claims)
};

var token = samlTokenHandler.CreateToken(tokenDescriptor) as SamlSecurityToken;
Expand All @@ -267,7 +267,7 @@ private static Saml2SecurityToken CreateSaml2Token(IList<Claim> claims)
IssuedAt = Default.IssueInstant,
Issuer = Default.Issuer,
SigningCredentials = Default.AsymmetricSigningCredentials,
Subject = new ClaimsIdentity(claims)
Subject = new CaseSensitiveClaimsIdentity(claims)
};

var token = saml2TokenHandler.CreateToken(tokenDescriptor) as Saml2SecurityToken;
Expand Down
10 changes: 5 additions & 5 deletions test/Microsoft.IdentityModel.TestUtils/ClaimSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ static ClaimSets()
claims.AddRange(DefaultClaims);
DefaultDuplicatedClaims = claims;

DefaultClaimsIdentity = new ClaimsIdentity(DefaultClaims, Default.AuthenticationType);
DefaultClaimsIdentity = new CaseSensitiveClaimsIdentity(DefaultClaims, Default.AuthenticationType);
DefaultClaimsIdentity.Label = Default.ClaimsIdentityLabel;
DefaultClaimsIdentityClaimsDuplicated = new ClaimsIdentity(DefaultDuplicatedClaims, Default.AuthenticationType);
DefaultClaimsIdentityClaimsDuplicated = new CaseSensitiveClaimsIdentity(DefaultDuplicatedClaims, Default.AuthenticationType);
DefaultClaimsIdentityClaimsDuplicated.Label = Default.ClaimsIdentityLabelDup;
ClaimsIdentityDerivedClaims = new ClaimsIdentity(DerivedClaims, Default.AuthenticationType);
DerivedClaimsIdentityDefaultClaims = new ClaimsIdentity(DefaultClaims);
DerivedClaimsIdentityDerivedClaims = new ClaimsIdentity(DerivedClaims);
ClaimsIdentityDerivedClaims = new CaseSensitiveClaimsIdentity(DerivedClaims, Default.AuthenticationType);
DerivedClaimsIdentityDefaultClaims = new CaseSensitiveClaimsIdentity(DefaultClaims);
DerivedClaimsIdentityDerivedClaims = new CaseSensitiveClaimsIdentity(DerivedClaims);
DefaultClaimsPrincipal = new ClaimsPrincipal(DefaultClaimsIdentity);
}

Expand Down
12 changes: 6 additions & 6 deletions test/Microsoft.IdentityModel.TestUtils/Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static List<Claim> Claims

public static ClaimsIdentity ClaimsIdentity
{
get => new ClaimsIdentity(Claims, AuthenticationType);
get => new CaseSensitiveClaimsIdentity(Claims, AuthenticationType);
}

public static string ClaimsIdentityLabel
Expand Down Expand Up @@ -497,7 +497,7 @@ public static Dictionary<string, object> PayloadJsonDictionary

public static ClaimsIdentity PayloadClaimsIdentity
{
get => new ClaimsIdentity(PayloadClaims, "AuthenticationTypes.Federation");
get => new CaseSensitiveClaimsIdentity(PayloadClaims, "AuthenticationTypes.Federation");
}

public static Dictionary<string, object> PayloadDictionary
Expand Down Expand Up @@ -906,7 +906,7 @@ public static List<Claim> SamlClaimsIssuerEqOriginalIssuer

public static ClaimsIdentity SamlClaimsIdentity
{
get => new ClaimsIdentity(SamlClaims, AuthenticationType);
get => new CaseSensitiveClaimsIdentity(SamlClaims, AuthenticationType);
}

public static SamlConditions SamlConditionsSingleCondition
Expand Down Expand Up @@ -958,7 +958,7 @@ public static SecurityTokenDescriptor SecurityTokenDescriptor(
IssuedAt = DateTime.UtcNow,
NotBefore = DateTime.UtcNow,
SigningCredentials = signingCredentials,
Subject = claims == null ? ClaimsIdentity : new ClaimsIdentity(claims)
Subject = claims == null ? ClaimsIdentity : new CaseSensitiveClaimsIdentity(claims)
};
}

Expand All @@ -973,7 +973,7 @@ public static SecurityTokenDescriptor SecurityTokenDescriptor(SigningCredentials
IssuedAt = DateTime.UtcNow,
NotBefore = DateTime.UtcNow,
SigningCredentials = signingCredentials,
Subject = claims == null ? ClaimsIdentity : new ClaimsIdentity(claims),
Subject = claims == null ? ClaimsIdentity : new CaseSensitiveClaimsIdentity(claims),
};

if (securityTokenDescriptor.Claims == null)
Expand All @@ -998,7 +998,7 @@ public static SecurityTokenDescriptor X509SecurityTokenDescriptor(
IssuedAt = DateTime.UtcNow,
NotBefore = DateTime.UtcNow,
SigningCredentials = signingCredentials,
Subject = claims == null ? ClaimsIdentity : new ClaimsIdentity(claims)
Subject = claims == null ? ClaimsIdentity : new CaseSensitiveClaimsIdentity(claims)
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.IdentityModel.TestUtils/NotDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static ClaimsIdentity CaimsIdentity
{
get
{
return new ClaimsIdentity(Claims, AuthenticationType, NameClaimType, RoleClaimType)
return new CaseSensitiveClaimsIdentity(Claims, AuthenticationType, NameClaimType, RoleClaimType)
{
Label = ClaimsIdentityLabel
};
Expand Down
6 changes: 3 additions & 3 deletions test/Microsoft.IdentityModel.TestUtils/ReferenceSaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ public static SamlTokenTestSet TokenClaimsIdentitiesSameSubject
string name = ClaimTypes.Country.Substring(index + 1);
var statement = new SamlAttributeStatement(ReferenceSaml.SamlSubject, new SamlAttribute(ns, name, Default.Country));

var identity = new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
var identity = new CaseSensitiveClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
identity.AddClaim(claim);
identity.AddClaim(claim);
return new SamlTokenTestSet
Expand All @@ -1312,12 +1312,12 @@ public static SamlTokenTestSet TokenClaimsIdentitiesDifferentSubjects
string name = ClaimTypes.Country.Substring(index + 1);
var attrStatement1 = new SamlAttribute(ns, name, Default.Country);
var statement1 = new SamlAttributeStatement(ReferenceSaml.SamlSubject, attrStatement1);
var identity1 = new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
var identity1 = new CaseSensitiveClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
identity1.AddClaim(claim1);

// statement2 has different subject with statement1
var statement2 = new SamlAttributeStatement(new SamlSubject(Default.NameIdentifierFormat, Default.NameQualifier, Default.AttributeName), attrStatement1);
var identity2 = new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
var identity2 = new CaseSensitiveClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
identity2.AddClaim(claim1);

var claim2 = new Claim(ClaimTypes.NameIdentifier, Default.AttributeName, ClaimValueTypes.String, Default.Issuer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public static TheoryData<Saml2TheoryData> WriteTokenTheoryData
Expires = Default.Expires,
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
Subject = new ClaimsIdentity(Default.SamlClaims),
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims),
};

var validationParameters = new TokenValidationParameters
Expand Down Expand Up @@ -487,7 +487,7 @@ public void SetDefaultTimesOnTokenCreation()
Issuer = Default.Issuer,
Audience = Default.Audience,
SigningCredentials = Default.AsymmetricSigningCredentials,
Subject = new ClaimsIdentity()
Subject = new CaseSensitiveClaimsIdentity()
};

var token = tokenHandler.CreateToken(descriptorNoTimeValues);
Expand Down Expand Up @@ -1153,7 +1153,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSaml2TokenUsingTokenDescri
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
Saml2SecurityTokenHandler = new Saml2SecurityTokenHandler(),
ValidationParameters = validationParametersWithAudiences,
Expand All @@ -1170,7 +1170,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSaml2TokenUsingTokenDescri
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
Saml2SecurityTokenHandler = new Saml2SecurityTokenHandler(),
ValidationParameters = validationParametersWithAudiences,
Expand All @@ -1187,7 +1187,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSaml2TokenUsingTokenDescri
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
Saml2SecurityTokenHandler = new Saml2SecurityTokenHandler(),
ValidationParameters = validationParametersWithAudiences,
Expand All @@ -1204,7 +1204,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSaml2TokenUsingTokenDescri
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
Saml2SecurityTokenHandler = new Saml2SecurityTokenHandler(),
ValidationParameters = validationParametersWithAudiences,
Expand Down Expand Up @@ -1241,7 +1241,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSaml2TokenUsingTokenDescri
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
Saml2SecurityTokenHandler = new Saml2SecurityTokenHandler(),
ValidationParameters = validationParameters
Expand All @@ -1258,7 +1258,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSaml2TokenUsingTokenDescri
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Claims = Default.SamlClaimsDictionary,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
Saml2SecurityTokenHandler = new Saml2SecurityTokenHandler(),
ValidationParameters = validationParameters
Expand Down Expand Up @@ -1305,7 +1305,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSaml2TokenUsingTokenDescri
{ ClaimTypes.GivenName, "Bob" },
{ ClaimTypes.Role, "HR" }
},
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
Saml2SecurityTokenHandler = new Saml2SecurityTokenHandler(),
ValidationParameters = validationParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ public static TheoryData<SamlTheoryData> WriteTokenTheoryData
Expires = Default.Expires,
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
Subject = new ClaimsIdentity(Default.SamlClaims),
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims),
};

var validationParameters = new TokenValidationParameters
Expand Down Expand Up @@ -1241,7 +1241,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSamlTokenUsingTokenDescrip
Issuer = Default.Issuer,
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
SamlSecurityTokenHandler = new SamlSecurityTokenHandler(),
ValidationParameters = validationParameters
Expand All @@ -1258,7 +1258,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSamlTokenUsingTokenDescrip
SigningCredentials = new SigningCredentials(KeyingMaterial.X509SecurityKeySelfSigned2048_SHA256, SecurityAlgorithms.RsaSha256Signature, SecurityAlgorithms.Sha256Digest),
EncryptingCredentials = null,
Claims = Default.SamlClaimsDictionary,
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
SamlSecurityTokenHandler = new SamlSecurityTokenHandler(),
ValidationParameters = validationParameters
Expand Down Expand Up @@ -1305,7 +1305,7 @@ public static TheoryData<CreateTokenTheoryData> CreateSamlTokenUsingTokenDescrip
{ ClaimTypes.GivenName, "Bob" },
{ ClaimTypes.Role, "HR" }
},
Subject = new ClaimsIdentity(Default.SamlClaims)
Subject = new CaseSensitiveClaimsIdentity(Default.SamlClaims)
},
SamlSecurityTokenHandler = new SamlSecurityTokenHandler(),
ValidationParameters = validationParameters
Expand Down
Loading

0 comments on commit b19d572

Please sign in to comment.