This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update KeyVault to use Managed Identities (#334)
- Loading branch information
1 parent
3ba073d
commit 6c8037e
Showing
7 changed files
with
202 additions
and
21 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
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
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
111 changes: 111 additions & 0 deletions
111
tests/NuGet.Services.Configuration.Tests/ConfigurationRootSecretReaderFactoryFacts.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,111 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Configuration; | ||
using Xunit; | ||
|
||
namespace NuGet.Services.Configuration.Tests | ||
{ | ||
public class ConfigurationRootSecretReaderFactoryFacts | ||
{ | ||
[Fact] | ||
public void ConstructorThrowsWhenKeyConfigIsNull() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => new ConfigurationRootSecretReaderFactory(null)); | ||
} | ||
|
||
public static IEnumerable<object[]> InvalidConfigs | ||
{ | ||
get | ||
{ | ||
yield return new object[] { | ||
new Dictionary<string, string> { | ||
{ Constants.KeyVaultVaultNameKey, "KeyVaultName" }, | ||
{ Constants.KeyVaultUseManagedIdentity, "true" }, | ||
{ Constants.KeyVaultClientIdKey, "KeyVaultClientId" }, | ||
{ Constants.KeyVaultCertificateThumbprintKey, "KeyVaultThumbprint" }, | ||
{ Constants.KeyVaultStoreNameKey, "StoreName"}, | ||
{ Constants.KeyVaultStoreLocationKey, "StoreLocation" }, | ||
{ Constants.KeyVaultValidateCertificateKey, "true" }, | ||
{ Constants.KeyVaultSendX5c, "false" } | ||
} | ||
}; | ||
} | ||
} | ||
|
||
public static IEnumerable<object[]> ValidConfigs | ||
{ | ||
get | ||
{ | ||
yield return new object[] { | ||
new Dictionary<string, string> { | ||
{ Constants.KeyVaultVaultNameKey, "KeyVaultName" }, | ||
{ Constants.KeyVaultUseManagedIdentity, "true" }, | ||
} | ||
}; | ||
|
||
yield return new object[] { | ||
new Dictionary<string, string> { | ||
{ Constants.KeyVaultClientIdKey, "KeyVaultClientId" }, | ||
{ Constants.KeyVaultCertificateThumbprintKey, "KeyVaultThumbprint" }, | ||
{ Constants.KeyVaultStoreNameKey, "StoreName"}, | ||
{ Constants.KeyVaultStoreLocationKey, "StoreLocation" }, | ||
{ Constants.KeyVaultValidateCertificateKey, "true" }, | ||
{ Constants.KeyVaultSendX5c, "false" } | ||
} | ||
}; | ||
|
||
yield return new object[] { | ||
new Dictionary<string, string> { | ||
{ Constants.KeyVaultVaultNameKey, "KeyVaultName" }, | ||
{ Constants.KeyVaultUseManagedIdentity, "false" }, | ||
{ Constants.KeyVaultClientIdKey, "KeyVaultClientId" }, | ||
{ Constants.KeyVaultCertificateThumbprintKey, "KeyVaultThumbprint" }, | ||
{ Constants.KeyVaultStoreNameKey, "StoreName"}, | ||
{ Constants.KeyVaultStoreLocationKey, "StoreLocation" }, | ||
{ Constants.KeyVaultValidateCertificateKey, "true" }, | ||
{ Constants.KeyVaultSendX5c, "false" } | ||
} | ||
}; | ||
|
||
yield return new object[] { | ||
new Dictionary<string, string> { | ||
{ Constants.KeyVaultVaultNameKey, "KeyVaultName" }, | ||
{ Constants.KeyVaultUseManagedIdentity, "false" }, | ||
{ Constants.KeyVaultClientIdKey, "" }, | ||
{ Constants.KeyVaultCertificateThumbprintKey, "" }, | ||
{ Constants.KeyVaultStoreNameKey, ""}, | ||
{ Constants.KeyVaultStoreLocationKey, "" }, | ||
{ Constants.KeyVaultValidateCertificateKey, "" }, | ||
{ Constants.KeyVaultSendX5c, "" } | ||
} | ||
}; | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(InvalidConfigs))] | ||
public void ConstructorThrowsWhenKeyVaultConfigSpecifiesManagedIdentityAndCertificate(IDictionary<string, string> config) | ||
{ | ||
Assert.Throws<ArgumentException>(() => new ConfigurationRootSecretReaderFactory(CreateTestConfiguration(config))); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(ValidConfigs))] | ||
public void CreatesSecretReaderFactoryForValidConfiguration(IDictionary<string, string> config) | ||
{ | ||
var secretReaderFacotry = new ConfigurationRootSecretReaderFactory(CreateTestConfiguration(config)); | ||
Assert.NotNull(secretReaderFacotry); | ||
} | ||
|
||
|
||
private IConfigurationRoot CreateTestConfiguration(IDictionary<string, string> config) | ||
{ | ||
return new ConfigurationBuilder() | ||
.AddInMemoryCollection(config) | ||
.Build(); | ||
} | ||
} | ||
} |
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