Skip to content

Commit

Permalink
Fix AT POP tests (#2972)
Browse files Browse the repository at this point in the history
Use existing pattern in cache extensions test in
MsAuth10AtPopTests

Co-authored-by: Keegan Caruso <keegancaruso@microsoft.com>
  • Loading branch information
keegan-caruso and Keegan Caruso committed Aug 12, 2024
1 parent ecd28dd commit ea9b037
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@ namespace Microsoft.Identity.Web.Test.Common.Mocks
/// </summary>
public class MockHttpClientFactory : IMsalHttpClientFactory, IDisposable
{
// MSAL will statically cache instance discovery, so we need to add
private static bool s_instanceDiscoveryAdded = false;
private static object s_instanceDiscoveryLock = new object();

public MockHttpClientFactory()
{
// Auto-add instance discovery call, but only once per process
if (!s_instanceDiscoveryAdded)
{
lock (s_instanceDiscoveryLock)
{
if (!s_instanceDiscoveryAdded)
{
_httpMessageHandlerQueue.Enqueue(MockHttpCreator.CreateInstanceDiscoveryMockHandler());
s_instanceDiscoveryAdded = true;
}
}
}
}

/// <inheritdoc />
public void Dispose()
{
Expand Down Expand Up @@ -66,8 +46,6 @@ public MockHttpMessageHandler AddMockHandler(MockHttpMessageHandler handler)

public HttpClient GetHttpClient()
{


HttpMessageHandler messageHandler;

Assert.NotEmpty(_httpMessageHandlerQueue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ public class MockHttpMessageHandler : HttpMessageHandler
{
public Func<MockHttpMessageHandler, MockHttpMessageHandler> ReplaceMockHttpMessageHandler;

private readonly bool _ignoreInstanceDiscovery;

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public MockHttpMessageHandler()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
}

public HttpResponseMessage ResponseMessage { get; set; }

public string ExpectedUrl { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion tests/Microsoft.Identity.Web.Test/MsAuth10AtPopTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public async Task MsAuth10AtPop_WithAtPop_ShouldPopulateBuilderWithProofOfPosess
//mockHttpClientFactory.AddMockHandler(MockHttpCreator.CreateInstanceDiscoveryMockHandler());
mockHttpClientFactory.AddMockHandler(httpTokenRequest);

//Enables the mock handler to requeue requests that have been intercepted for instance discovery for example
httpTokenRequest.ReplaceMockHttpMessageHandler = mockHttpClientFactory.AddMockHandler;

var certificateDescription = CertificateDescription.FromBase64Encoded(
TestConstants.CertificateX5cWithPrivateKey,
TestConstants.CertificateX5cWithPrivateKeyPassword);
Expand All @@ -40,7 +43,6 @@ public async Task MsAuth10AtPop_WithAtPop_ShouldPopulateBuilderWithProofOfPosess
.WithHttpClientFactory(mockHttpClientFactory)
.Build();


var popPublicKey = "pop_key";
var jwkClaim = "jwk_claim";

Expand Down

0 comments on commit ea9b037

Please sign in to comment.