From e88c97a5d0ac0681ddd45360f3e14e5f55b6b21a Mon Sep 17 00:00:00 2001 From: jennyf19 Date: Tue, 8 Oct 2024 11:13:38 -0700 Subject: [PATCH] return CaseSensitiveClaimsIdentity in clone (#2879) * return CaseSensitiveClaimsIdentity in clone * update public API --- .../CaseSensitiveClaimsIdentity.cs | 8 ++++++++ .../PublicAPI.Unshipped.txt | 1 + .../CaseSensitiveClaimsIdentityTests.cs | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/src/Microsoft.IdentityModel.Tokens/CaseSensitiveClaimsIdentity.cs b/src/Microsoft.IdentityModel.Tokens/CaseSensitiveClaimsIdentity.cs index 09c6deff98..a7c85b94ed 100644 --- a/src/Microsoft.IdentityModel.Tokens/CaseSensitiveClaimsIdentity.cs +++ b/src/Microsoft.IdentityModel.Tokens/CaseSensitiveClaimsIdentity.cs @@ -121,6 +121,14 @@ public override bool HasClaim(string type, string value) return base.HasClaim(claim => claim?.Type.Equals(type, StringComparison.Ordinal) == true && claim?.Value.Equals(value, StringComparison.Ordinal) == true); } + + /// + public override ClaimsIdentity Clone() + { + CaseSensitiveClaimsIdentity claimsIdentity = new(this); + + return claimsIdentity; + } } #pragma warning disable RS0030 // Do not use banned APIs diff --git a/src/Microsoft.IdentityModel.Tokens/PublicAPI.Unshipped.txt b/src/Microsoft.IdentityModel.Tokens/PublicAPI.Unshipped.txt index 0b563a0b97..07051df175 100644 --- a/src/Microsoft.IdentityModel.Tokens/PublicAPI.Unshipped.txt +++ b/src/Microsoft.IdentityModel.Tokens/PublicAPI.Unshipped.txt @@ -749,6 +749,7 @@ override Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider.Sign(byte[] override Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider.Sign(byte[] input, int offset, int count) -> byte[] override Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider.Verify(byte[] input, byte[] signature) -> bool override Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider.Verify(byte[] input, int inputOffset, int inputLength, byte[] signature, int signatureOffset, int signatureLength) -> bool +override Microsoft.IdentityModel.Tokens.CaseSensitiveClaimsIdentity.Clone() -> System.Security.Claims.ClaimsIdentity override Microsoft.IdentityModel.Tokens.CaseSensitiveClaimsIdentity.FindAll(string type) -> System.Collections.Generic.IEnumerable override Microsoft.IdentityModel.Tokens.CaseSensitiveClaimsIdentity.FindFirst(string type) -> System.Security.Claims.Claim override Microsoft.IdentityModel.Tokens.CaseSensitiveClaimsIdentity.HasClaim(string type, string value) -> bool diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs index 0270080cff..c171e1f531 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/CaseSensitiveClaimsIdentityTests.cs @@ -139,6 +139,15 @@ public void DefaultProperties_CorrectlySet() Assert.Equal(validationParameters.RoleClaimType, claimsIdentity.RoleClaimType); } + [Fact] + public void Clone_ReturnsCaseSensitiveClaimsIdentity() + { + var claimsIdentity = new CaseSensitiveClaimsIdentity(); + var clone = claimsIdentity.Clone(); + + Assert.True(clone is CaseSensitiveClaimsIdentity); + } + public static TheoryData GetCaseSensitiveClaimsIdentityTheoryData { get