Пример #1
0
        public void FindScopesAsync_CustomScope_SecretStoreCalled()
        {
            // Arrange
            var secretStoreFake = A.Fake <IVaultSecretStore>();
            var scopeStoreFake  = A.Fake <IScopeStore>();

            A.CallTo(() => scopeStoreFake.FindScopesAsync(A <IEnumerable <string> > ._))
            .Returns(Task.FromResult((IEnumerable <Scope>) new List <Scope>
            {
                new Scope {
                    Name = "scope1"
                }
            }));

            A.CallTo(() => secretStoreFake.GetSecrets("scope1"))
            .Returns(Task.FromResult(new[] { "secret1", "secret2" }));

            var store = new ScopeSecretStore(secretStoreFake, scopeStoreFake);

            // Act
            var result = store.FindScopesAsync(new List <string> {
                "scope1"
            })
                         .Result
                         .ToList();

            // Assert
            result.Count.Should().Be(1);
            result[0].Name.Should().Be("scope1");
            result[0].ScopeSecrets.Count.Should().Be(2);
            result[0].ScopeSecrets[0].Value.Should().Be("secret1");
            result[0].ScopeSecrets[0].Type.Should().Be(Constants.VaultSharedSecretType);
            result[0].ScopeSecrets[1].Value.Should().Be("secret2");
            result[0].ScopeSecrets[1].Type.Should().Be(Constants.VaultSharedSecretType);
        }
Пример #2
0
        public void GetScopesAync_CallsUnderlyingScopeStore()
        {
            // Arrange
            var secretStoreFake = A.Fake <IVaultSecretStore>();
            var scopeStoreFake  = A.Fake <IScopeStore>();

            A.CallTo(() => scopeStoreFake.GetScopesAsync(true)).Returns(Task.FromResult((IEnumerable <Scope>) new List <Scope>
            {
                new Scope {
                    Name = "scope1"
                },
                new Scope {
                    Name = "scope2"
                }
            }));

            var store = new ScopeSecretStore(secretStoreFake, scopeStoreFake);

            // Act
            var result = store.GetScopesAsync().Result.ToList();

            // Assert
            result.Count.Should().Be(2);

            result[0].Name.Should().Be("scope1");
            result[1].Name.Should().Be("scope2");
        }
Пример #3
0
        public void FindScopesAsync_StandardScope_SecretStoreNotCalled()
        {
            // Arrange
            var secretStoreFake = A.Fake <IVaultSecretStore>();
            var scopeStoreFake  = A.Fake <IScopeStore>();

            A.CallTo(() => scopeStoreFake.FindScopesAsync(A <IEnumerable <string> > ._))
            .Returns(Task.FromResult((IEnumerable <Scope>) new List <Scope>
            {
                StandardScopes.Email
            }));

            var store = new ScopeSecretStore(secretStoreFake, scopeStoreFake);

            // Act
            var result = store.FindScopesAsync(new List <string> {
                StandardScopes.Email.Name
            })
                         .Result
                         .ToList();

            // Assert
            result.Count.Should().Be(1);
            result[0].Name.Should().Be(StandardScopes.Email.Name);
        }
Пример #4
0
        public void FindScopesAsync_EmptyScopes_ReturnsEmpty()
        {
            // Arrange
            var secretStoreFake = A.Fake <IVaultSecretStore>();
            var scopeStoreFake  = A.Fake <IScopeStore>();

            var store = new ScopeSecretStore(secretStoreFake, scopeStoreFake);

            // Act
            var result = store.FindScopesAsync(new List <string>()).Result;

            // Assert
            result.Should().BeEmpty();
        }
Пример #5
0
        public void FindScopesAsync_EmptyScopeResults_ReturnsEmpty()
        {
            // Arrange
            var secretStoreFake = A.Fake <IVaultSecretStore>();
            var scopeStoreFake  = A.Fake <IScopeStore>();

            A.CallTo(() => scopeStoreFake.FindScopesAsync(A <IEnumerable <string> > ._))
            .Returns(Task.FromResult((IEnumerable <Scope>) new List <Scope>()));

            var store = new ScopeSecretStore(secretStoreFake, scopeStoreFake);

            // Act
            var result = store.FindScopesAsync(new List <string> {
                "scope1"
            }).Result;

            // Assert
            result.Should().BeEmpty();
        }