-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove linq from BaseConfigurationComparer
Fixes #2464
- Loading branch information
Keegan Caruso
committed
Jan 29, 2024
1 parent
b6a5fec
commit 085a4d1
Showing
2 changed files
with
157 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
test/Microsoft.IdentityModel.Tokens.Tests/BaseConfigurationComparerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.IdentityModel.TestUtils; | ||
using Xunit; | ||
|
||
namespace Microsoft.IdentityModel.Tokens.Tests | ||
{ | ||
public class BaseConfigurationComparerTests | ||
{ | ||
[Theory, MemberData(nameof(ComparerTheoryData))] | ||
public void Compare(BaseConfigurationComparerTheoryData theoryData) | ||
{ | ||
var context = TestUtilities.WriteHeader($"{this}.Compare", theoryData); | ||
var comparer = new BaseConfigurationComparer(); | ||
var result = comparer.Equals(theoryData.ConfigurationA, theoryData.ConfigurationB); | ||
Assert.Equal(theoryData.ShouldBeEqual, result); | ||
} | ||
|
||
public static TheoryData<BaseConfigurationComparerTheoryData> ComparerTheoryData() | ||
{ | ||
var jsonWebKey1 = new TestConfiguration | ||
{ | ||
Issuer = "http://example.com/issuer/1", | ||
}; | ||
|
||
jsonWebKey1.SigningKeys.Add(DataSets.JsonWebKey1); | ||
|
||
var jsonWebKey2 = new TestConfiguration | ||
{ | ||
Issuer = "http://example.com/issuer/1", | ||
}; | ||
|
||
jsonWebKey2.SigningKeys.Add(DataSets.JsonWebKey2); | ||
|
||
var bothJsonWebKeys = new TestConfiguration | ||
{ | ||
Issuer = "http://example.com/issuer/1", | ||
}; | ||
|
||
bothJsonWebKeys.SigningKeys.Add(DataSets.JsonWebKey1); | ||
bothJsonWebKeys.SigningKeys.Add(DataSets.JsonWebKey2); | ||
|
||
return new TheoryData<BaseConfigurationComparerTheoryData>() | ||
{ | ||
new() | ||
{ | ||
TestId = "Both null", | ||
ConfigurationA = null, | ||
ConfigurationB = null, | ||
ShouldBeEqual = true, | ||
}, | ||
new() | ||
{ | ||
TestId = "B null", | ||
ConfigurationA = new TestConfiguration(), | ||
ConfigurationB = null, | ||
ShouldBeEqual = false, | ||
}, | ||
new() | ||
{ | ||
TestId = "A null", | ||
ConfigurationA = null, | ||
ConfigurationB = new TestConfiguration(), | ||
ShouldBeEqual = false, | ||
}, | ||
new() | ||
{ | ||
TestId = "Issuer mismatched", | ||
ConfigurationA = new TestConfiguration | ||
{ | ||
Issuer = "http://example.com/issuer/1" | ||
}, | ||
ConfigurationB = new TestConfiguration | ||
{ | ||
Issuer = "http://example.com/issuer/2" | ||
}, | ||
ShouldBeEqual = false, | ||
}, | ||
new() | ||
{ | ||
TestId = "No Keys", | ||
ConfigurationA = new TestConfiguration | ||
{ | ||
Issuer = "http://example.com/issuer/1", | ||
}, | ||
ConfigurationB = new TestConfiguration | ||
{ | ||
Issuer = "http://example.com/issuer/1" | ||
}, | ||
ShouldBeEqual = true, | ||
}, | ||
new() | ||
{ | ||
TestId = "different keys", | ||
ConfigurationA = jsonWebKey1, | ||
ConfigurationB = jsonWebKey2, | ||
ShouldBeEqual = false, | ||
}, | ||
new() | ||
{ | ||
TestId = "same keys", | ||
ConfigurationA = jsonWebKey1, | ||
ConfigurationB = jsonWebKey1, | ||
ShouldBeEqual = true, | ||
}, | ||
new () | ||
{ | ||
TestId = "different number of keys", | ||
ConfigurationA = jsonWebKey1, | ||
ConfigurationB = bothJsonWebKeys, | ||
ShouldBeEqual = false, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
public class BaseConfigurationComparerTheoryData : TheoryDataBase | ||
{ | ||
public BaseConfiguration ConfigurationA { get; set; } | ||
|
||
public BaseConfiguration ConfigurationB { get; set; } | ||
|
||
public bool ShouldBeEqual { get; set; } | ||
} | ||
|
||
public class TestConfiguration : BaseConfiguration | ||
{ | ||
} | ||
} |