Skip to content

Commit

Permalink
Merge branch 'AzureAD:dev' into gparametr/JsonWebTokenHandler_CreateT…
Browse files Browse the repository at this point in the history
…oken_dispose_KeyWrapProvider
  • Loading branch information
gparametr authored Jan 10, 2025
2 parents 17383a0 + 6146f1f commit 5becfc1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public override void RequestRefresh()
_isFirstRefreshRequest = false;
if (Interlocked.CompareExchange(ref _configurationRetrieverState, ConfigurationRetrieverRunning, ConfigurationRetrieverIdle) == ConfigurationRetrieverIdle)
{
_ = Task.Run(UpdateCurrentConfiguration, CancellationToken.None);
UpdateCurrentConfiguration();
_lastRequestRefresh = now;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.IdentityModel.Tokens/AsymmetricAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ private void InitializeUsingRsaSecurityKey(RsaSecurityKey rsaSecurityKey, string
{
#if NET472 || NET6_0_OR_GREATER
var rsa = RSA.Create(rsaSecurityKey.Parameters);
#elif NET462
var rsa = new RSACng();
rsa.ImportParameters(rsaSecurityKey.Parameters);
#else
var rsa = RSA.Create();
rsa.ImportParameters(rsaSecurityKey.Parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public async Task VerifyInterlockGuardForRequestRefresh()
// Interlocked guard will block.
// Configuration should be AADCommonV1Config
signalEvent.Reset();
configurationManager.RequestRefresh();
_ = Task.Run(() => configurationManager.RequestRefresh());

// InMemoryDocumentRetrieverWithEvents will signal when it is OK to change the MetadataAddress
// otherwise, it may be the case that the MetadataAddress is changed before the previous Task has finished.
Expand All @@ -239,7 +239,7 @@ public async Task VerifyInterlockGuardForRequestRefresh()
// AADCommonV1Json would have been passed to the the previous retriever, which is blocked on an event.
configurationManager.MetadataAddress = "AADCommonV2Json";
TestUtilities.SetField(configurationManager, "_lastRequestRefresh", DateTimeOffset.MinValue);
configurationManager.RequestRefresh();
_ = Task.Run(() => configurationManager.RequestRefresh());

// Set the event to release the lock and let the previous retriever finish.
waitEvent.Set();
Expand Down Expand Up @@ -658,14 +658,13 @@ public async Task GetConfigurationAsync()
var configuration = await configManager.GetConfigurationAsync(CancellationToken.None);

TestUtilities.SetField(configManager, "_lastRequestRefresh", DateTimeOffset.UtcNow - TimeSpan.FromHours(1));
configManager.RequestRefresh();
configManager.MetadataAddress = "http://127.0.0.1";
configManager.RequestRefresh();
var configuration2 = await configManager.GetConfigurationAsync(CancellationToken.None);
IdentityComparer.AreEqual(configuration, configuration2, context);
if (!object.ReferenceEquals(configuration, configuration2))
context.Diffs.Add("!object.ReferenceEquals(configuration, configuration2)");


// get configuration from http address, should throw
// get configuration with unsuccessful HTTP response status code
TestUtilities.AssertFailIfErrors(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ internal static void AddSignUsingOffsets(byte[] bytes, SecurityKey securityKey,
{
Bytes = bytes,
Count = -1,
ExpectedException = ExpectedException.ArgumentException(),
ExpectedException = prefix == "RSA" ? ExpectedException.ArgumentOutOfRangeException() : ExpectedException.ArgumentException(),
Offset = 0,
SignatureProvider = CreateProvider(securityKey, algorithm)
});
Expand All @@ -1316,7 +1316,7 @@ internal static void AddSignUsingOffsets(byte[] bytes, SecurityKey securityKey,
{
Bytes = bytes,
Count = bytes.Length + 1,
ExpectedException = ExpectedException.ArgumentException(),
ExpectedException = prefix == "RSA" ? ExpectedException.ArgumentOutOfRangeException() : ExpectedException.ArgumentException(),
Offset = 0,
SignatureProvider = CreateProvider(securityKey, algorithm)
});
Expand All @@ -1325,7 +1325,7 @@ internal static void AddSignUsingOffsets(byte[] bytes, SecurityKey securityKey,
{
Bytes = bytes,
Count = 10,
ExpectedException = ExpectedException.ArgumentException(),
ExpectedException = prefix == "RSA" ? ExpectedException.ArgumentOutOfRangeException() : ExpectedException.ArgumentException(),
Offset = bytes.Length - 1,
SignatureProvider = CreateProvider(securityKey, algorithm)
});
Expand Down

0 comments on commit 5becfc1

Please sign in to comment.