コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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()));
        }
コード例 #4
0
        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));
        }