public void Should_FetchSecrets_When_LoadIsCalled() { _target.Load(); foreach (var secret in _testSecrets) { _target.TryGet(secret.SecretName.SecretId, out string value); Assert.Equal($"{secret.SecretName.SecretId}-Value", value); } }
public void ShouldInstantiateConfigurationProvider() { var mockGrpcClient = new Mock <SecretManagerServiceClient>(); mockGrpcClient .Setup(e => e.ListSecretsAsync(new ProjectName(PROJECT_NAME), null, null, null)) .Returns(new MockPagedEnumerable()); var secretResponse = new AccessSecretVersionResponse() { Payload = new SecretPayload { Data = ByteString.FromBase64(System.Convert.ToBase64String(Encoding.UTF8.GetBytes("value"))) } }; mockGrpcClient .Setup(e => e.AccessSecretVersionAsync(new SecretVersionName(PROJECT_NAME, "param1", "latest"), null)) .Returns(Task.FromResult(secretResponse)); var configurationOptions = new SecretManagerConfigurationOptions { ProjectName = PROJECT_NAME }; var configurationSource = new SecretManagerConfigurationSource(configurationOptions); var provider = new SecretManagerConfigurationProvider(mockGrpcClient.Object, configurationSource); provider.Load(); Assert.True(provider.TryGet("param1", out var value)); Assert.Equal("value", value); }
public void Should_CallLoaderGetKey() { var mockLoader = new Mock <ISecretManagerConfigurationLoader>(); mockLoader.Setup(m => m.GetKey(It.IsAny <Secret>())) .Returns((Secret secret) => secret.SecretName.SecretId); mockLoader.Setup(m => m.Load(It.IsAny <Secret>())).Returns(true); var target = new SecretManagerConfigurationProvider(_mockClient.Object, new ProjectName(_projectName), mockLoader.Object); target.Load(); mockLoader.Verify(m => m.GetKey(It.IsAny <Secret>()), Times.Exactly(_testSecrets.Count())); }
public void Should_NotLoadAllSecrets() { var mockLoader = new Mock <ISecretManagerConfigurationLoader>(); mockLoader.Setup(m => m.GetKey(It.IsAny <Secret>())) .Returns((Secret secret) => secret.SecretName.SecretId); mockLoader.Setup(m => m.Load(It.IsAny <Secret>())).Returns((Secret secret) => secret.SecretName.SecretId != _testSecrets.First().SecretName.SecretId); var target = new SecretManagerConfigurationProvider(_mockClient.Object, new ProjectName(_projectName), mockLoader.Object); target.Load(); Assert.False(target.TryGet("SecretId1", out var configValue1)); Assert.True(target.TryGet("SecretId2", out var configValue2)); Assert.True(target.TryGet("SecretId3", out var configValue3)); Assert.True(target.TryGet("SecretId4", out var configValue4)); }