Exemple #1
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 #2
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 #3
0
        ///<summary>
        /// List all available secrets
        ///</summary>
        public void ListSecrets()
        {
            Console.WriteLine();

            // Call Vault API
            List <string> secretsList = vaultCommunicator.ListKVSecrets().Result;

            // Handle output
            if (secretsList != null)
            {
                foreach (string item in secretsList)
                {
                    Console.WriteLine(item);
                }
            }
            else
            {
                Console.Error.WriteLine("Failed getting secrets!");
            }
            Console.WriteLine("\nPress any key to continue...");
            userInput.GetUserInput();
        }