public async Task KeyVaultSecretProvider_StoreSecret_Succeeds() { // Arrange var keyVaultUri = Configuration.GetValue <string>("Arcus:KeyVault:Uri"); var connectionString = Configuration.GetValue <string>("Arcus:MSI:AzureServicesAuth:ConnectionString"); var secretName = $"Test-Secret-{Guid.NewGuid()}"; var secretValue = Guid.NewGuid().ToString(); var keyVaultSecretProvider = new KeyVaultSecretProvider( authentication: new ManagedServiceIdentityAuthentication(), vaultConfiguration: new KeyVaultConfiguration(keyVaultUri)); using (TemporaryEnvironmentVariable.Create(KeyVaultConnectionStringEnvironmentVariable, connectionString)) { // Act Secret secret = await keyVaultSecretProvider.StoreSecretAsync(secretName, secretValue); // Assert Assert.NotNull(secret); Assert.NotNull(secret.Value); Assert.NotNull(secret.Version); Secret fetchedSecret = await keyVaultSecretProvider.GetSecretAsync(secretName); Assert.Equal(secretValue, fetchedSecret.Value); Assert.Equal(secret.Version, fetchedSecret.Version); Assert.Equal(secret.Expires, fetchedSecret.Expires); } }
public async Task KeyVaultSecretProvider_StoreSecretWithIncorrectSecretNameFormat_Throws(string secretName) { // Arrange var secretValue = Guid.NewGuid().ToString(); KeyVaultSecretProvider provider = CreateSecretProviderWithTooManyRequestSimulation("some ignored secret value"); // Act / Assert await Assert.ThrowsAnyAsync <FormatException>(() => provider.StoreSecretAsync(secretName, secretValue)); }