Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
terencefan committed Nov 22, 2024
1 parent 2dc662f commit caedd29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal sealed class AccessKeySynchronizer : IAccessKeySynchronizer, IDisposabl

private readonly TimerAwaitable _timer = new TimerAwaitable(TimeSpan.Zero, TimeSpan.FromMinutes(1));

internal IEnumerable<MicrosoftEntraAccessKey> AvailableKeyList => _keyMap.Select(x => x.Key).Where(x => x.Available);
internal IEnumerable<MicrosoftEntraAccessKey> AvailableKeyList => _keyMap.Select(x => x.Key).Where(x => x.LoadedTask.IsCompleted);

public AccessKeySynchronizer(ILoggerFactory loggerFactory) : this(loggerFactory, true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.Identity;
using Microsoft.Azure.SignalR;
using Microsoft.Azure.SignalR.Tests.Common;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;

namespace Microsoft.Azure.SignalR.Common;
namespace Microsoft.Azure.SignalR.Common.Tests.Auth;

public class AccessKeySynchronizerFacts
{
Expand All @@ -26,6 +28,7 @@ public void AddAndRemoveServiceEndpointsTest()
synchronizer.UpdateServiceEndpoints([endpoint1]);
Assert.Equal(1, synchronizer.Count());
synchronizer.UpdateServiceEndpoints([endpoint1, endpoint2]);
Assert.Empty(synchronizer.AvailableKeyList);

Assert.Equal(2, synchronizer.Count());
Assert.True(synchronizer.ContainsKey(endpoint1));
Expand All @@ -35,6 +38,7 @@ public void AddAndRemoveServiceEndpointsTest()
Assert.Equal(1, synchronizer.Count());
synchronizer.UpdateServiceEndpoints([]);
Assert.Equal(0, synchronizer.Count());
Assert.Empty(synchronizer.AvailableKeyList);
}

[Fact]
Expand All @@ -51,6 +55,7 @@ public async Task GenerateAccessTokenTriggerLoadedTaskTest()

var key = Assert.IsType<MicrosoftEntraAccessKey>(endpoint.AccessKey);
Assert.False(key.LoadedTask.IsCompleted);
Assert.Empty(synchronizer.AvailableKeyList);

await Assert.ThrowsAsync<TaskCanceledException>(
async () => await key.GenerateAccessTokenAsync("https://localhost", [], TimeSpan.FromSeconds(1), AccessTokenAlgorithm.HS256, source.Token)
Expand All @@ -59,6 +64,7 @@ await Assert.ThrowsAsync<TaskCanceledException>(

await initializeTask;
Assert.False(key.Available);
Assert.Single(synchronizer.AvailableKeyList);

await Assert.ThrowsAsync<AzureSignalRAccessTokenNotAuthorizedException>(
async () => await key.GenerateAccessTokenAsync("https://localhost", [], TimeSpan.FromSeconds(1), AccessTokenAlgorithm.HS256)
Expand Down

0 comments on commit caedd29

Please sign in to comment.