Skip to content

Commit

Permalink
feat: IntegrationTestConfiguration - supply-default-azure-credentials (
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmajgaard authored May 24, 2024
1 parent 9ce6557 commit 6c18eaf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
4 changes: 4 additions & 0 deletions source/TestCommon/documents/release-notes/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# TestCommon Release notes

## Version 5.2.1

- Extended `IntegrationTestConfiguration` with the option to pass in `DefaultAzureCredential` from the outside.

## Version 5.2.0

- Changes to `SqlServerDatabaseManager`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@

namespace Energinet.DataHub.Core.FunctionApp.TestCommon.Tests.Integration.Configuration;

public class IntegrationTestConfigurationTests : IClassFixture<IntegrationTestConfiguration>
public class IntegrationTestConfigurationTests
{
public IntegrationTestConfigurationTests(IntegrationTestConfiguration sut)
{
Sut = sut;
}

public IntegrationTestConfiguration Sut { get; }
private IntegrationTestConfiguration Sut { get; } = new();

[Fact]
public void Given_IdentityHasAccess_When_DatabricksSettings_Then_EachPropertyHasValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ public static class ConfigurationBuilderExtensions
/// </summary>
/// <param name="builder">The configuration builder.</param>
/// <param name="keyVaultUrl">KeyVault URL eg. https://myexamplekeyvault.vault.azure.net/</param>
public static IConfigurationBuilder AddAuthenticatedAzureKeyVault(this IConfigurationBuilder builder, string keyVaultUrl)
/// <param name="defaultAzureCredential"><see cref="DefaultAzureCredential"/> used for key vault authentication, if not supplied, a new <see cref="DefaultAzureCredential"/> will be created and used</param>
public static IConfigurationBuilder AddAuthenticatedAzureKeyVault(this IConfigurationBuilder builder, string keyVaultUrl, DefaultAzureCredential? defaultAzureCredential = null)
{
if (string.IsNullOrEmpty(keyVaultUrl))
{
throw new ArgumentException("Value cannot be null or empty.", nameof(keyVaultUrl));
}

var credential = new DefaultAzureCredential();
var credential = defaultAzureCredential ?? new DefaultAzureCredential();
builder.AddAzureKeyVault(new Uri(keyVaultUrl), credential);

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Identity;
using Microsoft.Extensions.Configuration;

namespace Energinet.DataHub.Core.FunctionApp.TestCommon.Configuration;
Expand All @@ -27,9 +28,9 @@ namespace Energinet.DataHub.Core.FunctionApp.TestCommon.Configuration;
/// </summary>
public class IntegrationTestConfiguration
{
public IntegrationTestConfiguration()
public IntegrationTestConfiguration(DefaultAzureCredential? defaultAzureCredential = null)
{
Configuration = BuildKeyVaultConfigurationRoot();
Configuration = BuildKeyVaultConfigurationRoot(defaultAzureCredential);

#pragma warning disable CS0618 // Type or member is obsolete
ApplicationInsightsInstrumentationKey = Configuration.GetValue("AZURE-APPINSIGHTS-INSTRUMENTATIONKEY");
Expand Down Expand Up @@ -90,7 +91,7 @@ public IntegrationTestConfiguration()
/// </summary>
public DatabricksSettings DatabricksSettings { get; }

private static IConfigurationRoot BuildKeyVaultConfigurationRoot()
private static IConfigurationRoot BuildKeyVaultConfigurationRoot(DefaultAzureCredential? defaultAzureCredential)
{
var integrationtestConfiguration = new ConfigurationBuilder()
.AddJsonFile("integrationtest.local.settings.json", optional: true)
Expand All @@ -101,7 +102,7 @@ private static IConfigurationRoot BuildKeyVaultConfigurationRoot()
GuardKeyVaultUrl(keyVaultUrl);

return new ConfigurationBuilder()
.AddAuthenticatedAzureKeyVault(keyVaultUrl)
.AddAuthenticatedAzureKeyVault(keyVaultUrl, defaultAzureCredential)
.Build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ limitations under the License.

<PropertyGroup>
<PackageId>Energinet.DataHub.Core.FunctionApp.TestCommon</PackageId>
<PackageVersion>5.2.0$(VersionSuffix)</PackageVersion>
<PackageVersion>5.2.1$(VersionSuffix)</PackageVersion>
<Title>FunctionApp TestCommon library</Title>
<Company>Energinet-DataHub</Company>
<Authors>Energinet-DataHub</Authors>
Expand Down
2 changes: 1 addition & 1 deletion source/TestCommon/source/TestCommon/TestCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ limitations under the License.

<PropertyGroup>
<PackageId>Energinet.DataHub.Core.TestCommon</PackageId>
<PackageVersion>5.2.0$(VersionSuffix)</PackageVersion>
<PackageVersion>5.2.1$(VersionSuffix)</PackageVersion>
<Title>TestCommon library</Title>
<Company>Energinet-DataHub</Company>
<Authors>Energinet-DataHub</Authors>
Expand Down

0 comments on commit 6c18eaf

Please sign in to comment.