Beispiel #1
0
        public async Task SupportsReloadOnAdd()
        {
            int numOfTokensFired = 0;

            var client = new MockKeyVaultClient();

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

            // Act & Assert
            using (var provider = new ReloadControlKeyVaultProvider(client, VaultUri, new DefaultKeyVaultSecretManager(), reloadPollDelay: NoReloadDelay))
            {
                ChangeToken.OnChange(
                    () => provider.GetReloadToken(),
                    () => {
                    numOfTokensFired++;
                });

                provider.Load();

                Assert.Equal("Value1", provider.Get("Secret1"));

                await provider.Wait();

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

                provider.Release();

                await provider.Wait();

                Assert.Equal("Value1", provider.Get("Secret1"));
                Assert.Equal("Value2", provider.Get("Secret2"));
                Assert.Equal(1, numOfTokensFired);
            }
        }
        public async Task SupportsReloadOnEnabledChange()
        {
            int numOfTokensFired = 0;

            var client = new MockKeyVaultClient();

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

            // Act & Assert
            using (var provider = new ReloadControlKeyVaultProvider(client, VaultUri, new DefaultKeyVaultSecretManager(), reloadPollDelay: TimeSpan.Zero))
            {
                ChangeToken.OnChange(
                    () => provider.GetReloadToken(),
                    () => {
                    numOfTokensFired++;
                });

                provider.Load();

                Assert.Equal("Value1", provider.Get("Secret1"));

                await provider.Wait();

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

                provider.Release();

                await provider.Wait();

                Assert.Throws <InvalidOperationException>(() => provider.Get("Secret2"));
                Assert.Equal(1, numOfTokensFired);
            }
        }
Beispiel #3
0
        public async Task SupportsAutoReload()
        {
            var updated          = DateTime.Now;
            int numOfTokensFired = 0;

            var client = new MockKeyVaultClient();

            client.SetPages(
                new []
            {
                CreateSecret("Secret1", "Value1", () => new SecretAttributes(enabled: true, updated: updated))
            }
                );

            // Act & Assert
            using (var provider = new ReloadControlKeyVaultProvider(client, VaultUri, new DefaultKeyVaultSecretManager(), reloadPollDelay: NoReloadDelay))
            {
                ChangeToken.OnChange(
                    () => provider.GetReloadToken(),
                    () => {
                    numOfTokensFired++;
                });

                provider.Load();

                Assert.Equal("Value1", provider.Get("Secret1"));

                await provider.Wait();

                client.SetPages(
                    new []
                {
                    CreateSecret("Secret1", "Value2", () => new SecretAttributes(enabled: true, updated: updated.AddSeconds(1)))
                }
                    );

                provider.Release();

                await provider.Wait();

                Assert.Equal("Value2", provider.Get("Secret1"));
                Assert.Equal(1, numOfTokensFired);
            }
        }