Skip to content

Commit ea9b037

Browse files
keegan-carusoKeegan Caruso
andauthored
Fix AT POP tests (#2972)
Use existing pattern in cache extensions test in MsAuth10AtPopTests Co-authored-by: Keegan Caruso <[email protected]>
1 parent ecd28dd commit ea9b037

File tree

3 files changed

+4
-25
lines changed

3 files changed

+4
-25
lines changed

tests/Microsoft.Identity.Web.Test.Common/Mocks/MockHttpClientFactory.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,6 @@ namespace Microsoft.Identity.Web.Test.Common.Mocks
1717
/// </summary>
1818
public class MockHttpClientFactory : IMsalHttpClientFactory, IDisposable
1919
{
20-
// MSAL will statically cache instance discovery, so we need to add
21-
private static bool s_instanceDiscoveryAdded = false;
22-
private static object s_instanceDiscoveryLock = new object();
23-
24-
public MockHttpClientFactory()
25-
{
26-
// Auto-add instance discovery call, but only once per process
27-
if (!s_instanceDiscoveryAdded)
28-
{
29-
lock (s_instanceDiscoveryLock)
30-
{
31-
if (!s_instanceDiscoveryAdded)
32-
{
33-
_httpMessageHandlerQueue.Enqueue(MockHttpCreator.CreateInstanceDiscoveryMockHandler());
34-
s_instanceDiscoveryAdded = true;
35-
}
36-
}
37-
}
38-
}
39-
4020
/// <inheritdoc />
4121
public void Dispose()
4222
{
@@ -66,8 +46,6 @@ public MockHttpMessageHandler AddMockHandler(MockHttpMessageHandler handler)
6646

6747
public HttpClient GetHttpClient()
6848
{
69-
70-
7149
HttpMessageHandler messageHandler;
7250

7351
Assert.NotEmpty(_httpMessageHandlerQueue);

tests/Microsoft.Identity.Web.Test.Common/Mocks/MockHttpMessageHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ public class MockHttpMessageHandler : HttpMessageHandler
1515
{
1616
public Func<MockHttpMessageHandler, MockHttpMessageHandler> ReplaceMockHttpMessageHandler;
1717

18-
private readonly bool _ignoreInstanceDiscovery;
19-
2018
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
2119
public MockHttpMessageHandler()
2220
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
2321
{
2422
}
23+
2524
public HttpResponseMessage ResponseMessage { get; set; }
2625

2726
public string ExpectedUrl { get; set; }

tests/Microsoft.Identity.Web.Test/MsAuth10AtPopTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public async Task MsAuth10AtPop_WithAtPop_ShouldPopulateBuilderWithProofOfPosess
2626
//mockHttpClientFactory.AddMockHandler(MockHttpCreator.CreateInstanceDiscoveryMockHandler());
2727
mockHttpClientFactory.AddMockHandler(httpTokenRequest);
2828

29+
//Enables the mock handler to requeue requests that have been intercepted for instance discovery for example
30+
httpTokenRequest.ReplaceMockHttpMessageHandler = mockHttpClientFactory.AddMockHandler;
31+
2932
var certificateDescription = CertificateDescription.FromBase64Encoded(
3033
TestConstants.CertificateX5cWithPrivateKey,
3134
TestConstants.CertificateX5cWithPrivateKeyPassword);
@@ -40,7 +43,6 @@ public async Task MsAuth10AtPop_WithAtPop_ShouldPopulateBuilderWithProofOfPosess
4043
.WithHttpClientFactory(mockHttpClientFactory)
4144
.Build();
4245

43-
4446
var popPublicKey = "pop_key";
4547
var jwkClaim = "jwk_claim";
4648

0 commit comments

Comments
 (0)