Ejemplo n.º 1
0
        public void DoesNotLoadFilteredItems()
        {
            var client = new MockKeyVaultClient();

            client.SetPages(
                new []
            {
                CreateSecret("Secret1", "Value1")
            },
                new []
            {
                CreateSecret("Secret2", "Value2")
            }
                );

            // Act
            using (var provider = new AzureKeyVaultConfigurationProvider(client, VaultUri, new EndsWithOneKeyVaultSecretManager()))
            {
                provider.Load();

                // Assert
                var childKeys = provider.GetChildKeys(Enumerable.Empty <string>(), null).ToArray();
                Assert.Equal(new[] { "Secret1" }, childKeys);
                Assert.Equal("Value1", provider.Get("Secret1"));
            }
        }
Ejemplo n.º 2
0
        public void LoadsAllSecretsFromVault()
        {
            var client = new MockKeyVaultClient();

            client.SetPages(
                new []
            {
                CreateSecret("Secret1", "Value1")
            },
                new []
            {
                CreateSecret("Secret2", "Value2")
            }
                );

            // Act
            using (var provider = new AzureKeyVaultConfigurationProvider(client, VaultUri, new DefaultKeyVaultSecretManager()))
            {
                provider.Load();

                var childKeys = provider.GetChildKeys(Enumerable.Empty <string>(), null).ToArray();
                Assert.Equal(new[] { "Secret1", "Secret2" }, childKeys);
                Assert.Equal("Value1", provider.Get("Secret1"));
                Assert.Equal("Value2", provider.Get("Secret2"));
            }
        }
        public void DoesNotLoadFilteredItems()
        {
            var client    = new Mock <IKeyVaultClient>(MockBehavior.Strict);
            var secret1Id = GetSecretId("Secret1");
            var secret2Id = GetSecretId("Secret2");

            client.Setup(c => c.GetSecretsAsync(VaultUri)).ReturnsAsync(new PageMock()
            {
                Value = new[] { new SecretItem {
                                    Id = secret1Id
                                }, new SecretItem {
                                    Id = secret2Id
                                } }
            });

            client.Setup(c => c.GetSecretAsync(secret1Id)).ReturnsAsync(new SecretBundle()
            {
                Value = "Value1", Id = secret1Id
            });

            // Act
            var provider = new AzureKeyVaultConfigurationProvider(client.Object, VaultUri, new EndsWithOneKeyVaultSecretManager());

            provider.Load();

            // Assert
            client.VerifyAll();

            var childKeys = provider.GetChildKeys(Enumerable.Empty <string>(), null).ToArray();

            Assert.Equal(new[] { "Secret1" }, childKeys);
            Assert.Equal("Value1", provider.Get("Secret1"));
        }
Ejemplo n.º 4
0
        public void DoesNotLoadDisabledItems()
        {
            var client = new MockKeyVaultClient();

            client.SetPages(
                new []
            {
                CreateSecret("Secret1", "Value1")
            },
                new []
            {
                CreateSecret("Secret2", "Value2", () => new SecretAttributes(enabled: false)),
                CreateSecret("Secret3", "Value3", () => new SecretAttributes(enabled: null)),
            }
                );

            // Act
            using (var provider = new AzureKeyVaultConfigurationProvider(client, VaultUri, new DefaultKeyVaultSecretManager()))
            {
                provider.Load();

                // Assert
                var childKeys = provider.GetChildKeys(Enumerable.Empty <string>(), null).ToArray();
                Assert.Equal(new[] { "Secret1" }, childKeys);
                Assert.Equal("Value1", provider.Get("Secret1"));
                Assert.Throws <InvalidOperationException>(() => provider.Get("Secret2"));
                Assert.Throws <InvalidOperationException>(() => provider.Get("Secret3"));
            }
        }
        public void DoesNotLoadDisabledItems()
        {
            var client    = new Mock <IKeyVaultClient>(MockBehavior.Strict);
            var secret1Id = GetSecretId("Secret1");
            var secret2Id = GetSecretId("Secret2");
            var secret3Id = GetSecretId("Secret3");
            var secret4Id = GetSecretId("Secret4");

            client.Setup(c => c.GetSecretsAsync(VaultUri)).ReturnsAsync(new PageMock()
            {
                NextPageLink = "next",
                Value        = new[] { new SecretItem {
                                           Id = secret1Id, Attributes = new SecretAttributes {
                                               Enabled = true
                                           }
                                       } }
            });

            client.Setup(c => c.GetSecretsNextAsync("next")).ReturnsAsync(new PageMock()
            {
                Value = new[]
                {
                    new SecretItem {
                        Id = secret2Id, Attributes = new SecretAttributes {
                            Enabled = false
                        }
                    },
                    new SecretItem {
                        Id = secret3Id, Attributes = new SecretAttributes {
                            Enabled = null
                        }
                    },
                    new SecretItem {
                        Id = secret4Id, Attributes = null
                    },
                }
            });

            client.Setup(c => c.GetSecretAsync(secret1Id)).ReturnsAsync(new SecretBundle()
            {
                Value = "Value1", Id = secret1Id
            });

            // Act
            var provider = new AzureKeyVaultConfigurationProvider(client.Object, VaultUri, new DefaultKeyVaultSecretManager());

            provider.Load();

            // Assert
            client.VerifyAll();

            var childKeys = provider.GetChildKeys(Enumerable.Empty <string>(), null).ToArray();

            Assert.Equal(new[] { "Secret1" }, childKeys);
            Assert.Equal("Value1", provider.Get("Secret1"));
            Assert.Throws <InvalidOperationException>(() => provider.Get("Secret2"));
            Assert.Throws <InvalidOperationException>(() => provider.Get("Secret3"));
            Assert.Throws <InvalidOperationException>(() => provider.Get("Secret4"));
        }