-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable SQL Workload Identity (#3085)
- Allow use of explicit workload identity for SQL connections - Enable configuring retries for Key Vault credentials
- Loading branch information
Showing
4 changed files
with
139 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ealth.Dicom.SqlServer.UnitTests/Registration/DicomSqlServerRegistrationExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Health.Dicom.Core.Registration; | ||
using Microsoft.Health.Dicom.SqlServer.Registration; | ||
using Microsoft.Health.SqlServer.Configs; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Dicom.SqlServer.UnitTests.Registration; | ||
|
||
public sealed class DicomSqlServerRegistrationExtensionsTests : IDisposable | ||
{ | ||
[Fact] | ||
public void GivenWebServerBuilder_WhenUsingDefaults_ThenUseBuiltInAuthenticationProvider() | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
IDicomServerBuilder builder = Substitute.For<IDicomServerBuilder>(); | ||
builder.Services.Returns(services); | ||
|
||
IConfiguration configuration = new ConfigurationBuilder().Build(); | ||
|
||
builder.AddSqlServer(configuration); | ||
|
||
Assert.IsType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryManagedIdentity)); | ||
Assert.IsType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryMSI)); | ||
} | ||
|
||
[Fact] | ||
public void GivenFunctionsBuilder_WhenUsingDefaults_ThenUseBuiltInAuthenticationProvider() | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
IDicomFunctionsBuilder builder = Substitute.For<IDicomFunctionsBuilder>(); | ||
builder.Services.Returns(services); | ||
|
||
IConfiguration configuration = new ConfigurationBuilder() | ||
.Build(); | ||
|
||
builder.AddSqlServer(configuration.Bind); | ||
|
||
Assert.IsType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryManagedIdentity)); | ||
Assert.IsType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryMSI)); | ||
} | ||
|
||
[Fact] | ||
public void GivenWebServerBuilder_WhenConfiguringWorkloadIdenity_ThenIncludeAuthenticationProvider() | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
IDicomServerBuilder builder = Substitute.For<IDicomServerBuilder>(); | ||
builder.Services.Returns(services); | ||
|
||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(new KeyValuePair<string, string>[] | ||
{ | ||
new KeyValuePair<string, string>($"{SqlServerDataStoreConfiguration.SectionName}:EnableWorkloadIdentity", "true"), | ||
}) | ||
.Build(); | ||
|
||
builder.AddSqlServer(configuration); | ||
|
||
Assert.IsNotType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryManagedIdentity)); | ||
Assert.IsNotType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryMSI)); | ||
} | ||
|
||
[Fact] | ||
public void GivenFunctionBuilder_WhenConfiguringWorkloadIdenity_ThenIncludeAuthenticationProvider() | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
IDicomFunctionsBuilder builder = Substitute.For<IDicomFunctionsBuilder>(); | ||
builder.Services.Returns(services); | ||
|
||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(new KeyValuePair<string, string>[] | ||
{ | ||
new KeyValuePair<string, string>("EnableWorkloadIdentity", "true"), | ||
}) | ||
.Build(); | ||
|
||
builder.AddSqlServer(configuration.Bind); | ||
|
||
Assert.IsNotType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryManagedIdentity)); | ||
Assert.IsNotType<ActiveDirectoryAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryMSI)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
ActiveDirectoryAuthenticationProvider provider = new(); | ||
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryManagedIdentity, provider); | ||
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryMSI, provider); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters