public void TestConstructorForAad() { var key = new AadAccessKey(new AadManagedIdentityOptions()); Assert.IsAssignableFrom <AccessKey>(key); Assert.False(key.Authorized); Assert.Null(key.Id); }
public async Task TestAcquireAccessToken() { var options = new ClientSecretCredential(TestTenantId, TestClientId, TestClientSecret); var key = new AadAccessKey(options, "https://localhost", 8080); var token = await key.GenerateAadTokenAsync(); Assert.NotNull(token); }
internal async Task TestAuthenticateAsync() { var options = new ClientSecretCredential(TestTenantId, TestClientId, TestClientSecret); var key = new AadAccessKey(options, "https://localhost", 8080); await key.UpdateAccessKeyAsync(); Assert.True(key.Authorized); Assert.NotNull(key.Id); Assert.NotNull(key.Value); }
public async Task TestAuthenticateAsync() { var options = new AadApplicationOptions(TestClientId, TestTenantId).WithClientSecret(TestClientSecret); var key = new AadAccessKey(options, TestEndpoint, TestPort); await key.UpdateAccessKeyAsync("serverId"); Assert.True(key.Authorized); Assert.NotNull(key.Id); Assert.NotNull(key.Value); }
public async Task TestAuthenticateAsync() { var options = new AadApplicationOptions(TestClientId, TestTenantId).WithClientSecret(TestClientSecret); var key = new AadAccessKey(options); await key.AuthorizeAsync("http://localhost", 8080, "serverId"); Assert.True(key.Authorized); Assert.NotNull(key.Id); Assert.NotNull(key.Value); }
public async Task TestInitializeFailed() { var credential = new EnvironmentCredential(); var key = new AadAccessKey(new Uri("http://localhost"), credential); var audience = "http://localhost/chat"; var claims = Array.Empty <Claim>(); var lifetime = TimeSpan.FromHours(1); var algorithm = AccessTokenAlgorithm.HS256; var task = Assert.ThrowsAsync <AzureSignalRAccessTokenNotAuthorizedException>( async() => await key.GenerateAccessTokenAsync(audience, claims, lifetime, algorithm) ); await Assert.ThrowsAnyAsync <Exception>( async() => await key.UpdateAccessKeyAsync() ); await task; }
public async Task TestUpdateAccessKey() { var credential = new EnvironmentCredential(); var endpoint = "http://localhost"; var key = new AadAccessKey(new Uri(endpoint), credential); var audience = "http://localhost/chat"; var claims = Array.Empty <Claim>(); var lifetime = TimeSpan.FromHours(1); var algorithm = AccessTokenAlgorithm.HS256; var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1)); await Assert.ThrowsAsync <TaskCanceledException>( async() => await key.GenerateAccessTokenAsync(audience, claims, lifetime, algorithm, cts.Token) ); var(kid, accessKey) = ("foo", SigningKey); key.UpdateAccessKey(kid, accessKey); var token = await key.GenerateAccessTokenAsync(audience, claims, lifetime, algorithm); Assert.NotNull(token); }
public void TestConstructor(string endpoint, string expectedAuthorizeUrl) { var key = new AadAccessKey(new Uri(endpoint), new DefaultAzureCredential()); Assert.Equal(expectedAuthorizeUrl, key.AuthorizeUrl); }