Exemple #1
0
        public async void TestSuccess_AddKVSecret()
        {
            var moqHandler = NewMoqHttpHandler(HttpStatusCode.OK);

            // Make the method call
            var      httpClient = new HttpClient(moqHandler.Object);
            VaultCom vcom       = new VaultCom("http://test.com", "vault_token", "vault_path", httpClient);
            bool     callResult = await vcom.AddKVSecret("test-secret", correctSecretData);

            // Verify returned result
            Assert.IsType <bool>(callResult);
            Assert.True(callResult);

            // Verify the call to the API
            Uri expectedUri = new Uri("http://test.com/v1/vault_path/data/test-secret");

            moqHandler.Protected().Verify(
                "SendAsync",
                Times.Once(),
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Post &&
                                               req.RequestUri == expectedUri &&
                                               req.Headers.Contains("X-Vault-Token") &&
                                               new List <string>(req.Headers.GetValues("X-Vault-Token")).Contains("vault_token")
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );
        }
Exemple #2
0
        ///<summary>
        /// Test ListKVSecret() with a successfull response form Vault API
        ///</summary>

        public async void TestSuccess_ListKVSecrets()
        {
            var moqHandler = NewMoqHttpHandler(HttpStatusCode.OK);

            // Make the method call
            var      httpClient = new HttpClient(moqHandler.Object);
            VaultCom vcom       = new VaultCom("http://test.com", "vault_token", "vault_path", httpClient);
            var      callResult = await vcom.ListKVSecrets();

            // Verify returned result
            Assert.NotNull(callResult);
            Assert.Equal(expSecretsList, callResult);

            // Verify HttpClient.SendAsync() call
            Uri expReqUrl = new Uri("http://test.com/v1/vault_path/metadata");

            moqHandler.Protected().Verify(
                "SendAsync",
                Times.Once(),
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == new HttpMethod("LIST") &&
                                               req.RequestUri == expReqUrl &&
                                               req.Headers.Contains("X-Vault-Token") &&
                                               new List <string>(req.Headers.GetValues("X-Vault-Token")).Contains("vault_token")
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );
        }
Exemple #3
0
 /// <summary>
 /// Constructor that initializes new VaultCom instance for vaultCommunicator
 /// </summary>
 public ConsoleUI()
 {
     vaultCommunicator = InitVaultCom();
     if (vaultCommunicator == null)
     {
         throw new ApplicationException("Error initializing vault communicator!");
     }
     this.userInput = new GetUserInput();
 }
Exemple #4
0
        ///<summary>
        /// Test ListKVSecret() with a failure response form Vault API
        ///</summary>

        public async void TestFailure_ListKVSecrets()
        {
            var moqHandler = NewMoqHttpHandler(HttpStatusCode.BadRequest);

            // Make the method call
            var      httpClient = new HttpClient(moqHandler.Object);
            VaultCom vcom       = new VaultCom("http://test.com", "vault_token", "vault_path", httpClient);
            var      callResult = await vcom.ListKVSecrets();

            // Verify returned result
            Assert.Null(callResult);
        }
Exemple #5
0
        public async void TestFailure_AddKVSecret()
        {
            var moqHandler = NewMoqHttpHandler(HttpStatusCode.BadRequest);

            // Make the method call
            var      httpClient = new HttpClient(moqHandler.Object);
            VaultCom vcom       = new VaultCom("http://test.com", "vault_token", "vault_path", httpClient);
            bool     callResult = await vcom.AddKVSecret("test-secret", correctSecretData);

            // Verify returned result
            Assert.IsType <bool>(callResult);
            Assert.False(callResult);
        }
Exemple #6
0
 /// <summary>
 /// Constructor that uses the provided VaultCom and IUserInput objects.
 /// </summary>
 /// <param name="vaultComunicator"></param>
 public ConsoleUI(VaultCom vaultComunicator, IUserInput userInput)
 {
     this.userInput         = userInput;
     this.vaultCommunicator = vaultComunicator;
 }