Пример #1
0
        public void TestReadStringSuccess()
        {
            var    client = new SecretHub.Client();
            string secret = client.ReadString("secrethub/xgo/dotnet/test/test-secret");

            Assert.Equal("super_secret_value", secret);
        }
Пример #2
0
        public void TestResolveEnvSuccess(string secretValue, string envVarName)
        {
            var client = new SecretHub.Client();

            System.Collections.Generic.IDictionary <string, string> res = client.ResolveEnv();
            Assert.Equal(secretValue, res[envVarName]);
        }
Пример #3
0
        public void TestResolveEnvFail()
        {
            var   client             = new SecretHub.Client();
            var   ex                 = Assert.Throws <ApplicationException>(() => client.ResolveEnv());
            Regex expectedErrorRegex = new Regex(@"^.*\(server\.secret_not_found\) $");

            Assert.True(expectedErrorRegex.IsMatch(ex.Message), "error should end in the (server.secret_not_found) error code");
        }
Пример #4
0
        public void TestReadStringFail()
        {
            var   client             = new SecretHub.Client();
            Regex expectedErrorRegex = new Regex(@"^.*\(server\.secret_not_found\) $");
            var   ex = Assert.Throws <ApplicationException>(() => client.ReadString("secrethub/xgo/dotnet/test/not-this-one"));

            Assert.True(expectedErrorRegex.IsMatch(ex.Message), "error should end in the (server.secret_not_found) error code");
        }
Пример #5
0
        public void TestExistsException()
        {
            var   client             = new SecretHub.Client();
            Regex expectedErrorRegex = new Regex(@"^.*\(api\.invalid_secret_path\) $");
            var   ex = Assert.Throws <ApplicationException>(() => client.Exists("not-a-path"));

            Assert.True(expectedErrorRegex.IsMatch(ex.Message), "error should end in the (api.invalid_secret_path) error code");
        }
Пример #6
0
        public void TestRemoveSuccess()
        {
            var client = new SecretHub.Client();

            client.Write("secrethub/xgo/dotnet/test/delete-secret", "delete_secret_value");
            Assert.True(client.Exists("secrethub/xgo/dotnet/test/delete-secret"));
            client.Remove("secrethub/xgo/dotnet/test/delete-secret");
            Assert.False(client.Exists("secrethub/xgo/dotnet/test/delete-secret"));
        }
Пример #7
0
        public void TestWriteSuccess()
        {
            var client = new SecretHub.Client();

            client.Write("secrethub/xgo/dotnet/test/new-secret", "new_secret_value");
            String secret = client.ReadString("secrethub/xgo/dotnet/test/new-secret");

            Assert.Equal("new_secret_value", secret);
            client.Remove("secrethub/xgo/dotnet/test/new-secret");
        }
Пример #8
0
        public void TestReadSuccess()
        {
            var client = new SecretHub.Client();

            SecretHub.SecretVersion secret = client.Read("secrethub/xgo/dotnet/test/test-secret:3");
            Assert.Equal(new Guid("529beaaf-9934-432f-a6b0-c5cb7e847458"), secret.SecretVersionID);
            Assert.Equal(new Guid("c37ec233-e168-436d-8b06-48c52aa22d5e"), secret.Secret.SecretID);
            Assert.Equal(3, secret.Version);
            Assert.Equal("super_secret_value", secret.Data);
            Assert.Equal(DateTime.Parse("10/1/2020 2:22:08 PM",
                                        System.Globalization.CultureInfo.InvariantCulture), secret.CreatedAt);
            Assert.Equal(DateTime.Parse("10/1/2020 10:49:33 AM",
                                        System.Globalization.CultureInfo.InvariantCulture), secret.Secret.CreatedAt);
            Assert.Equal("ok", secret.Status);
        }
Пример #9
0
 public static string response()
 {
     try
     {
         var    secrets  = new SecretHub.Client().ResolveEnv();
         string username = secrets["DEMO_USERNAME"];
         string password = secrets["DEMO_PASSWORD"];
         return("Hello, " + username + "!");
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return("Your username, password or SecretHub credential have not been set correctly.");
     }
 }
Пример #10
0
        public void TestExportEnv()
        {
            System.Environment.SetEnvironmentVariable("key1", "value1");
            System.Environment.SetEnvironmentVariable("key2", "value1");
            var client = new SecretHub.Client();

            client.ExportEnv(new System.Collections.Generic.Dictionary <string, string>
            {
                { "key1", "value2" },
                { "key3", "value3" }
            }
                             );
            Assert.Equal("value2", System.Environment.GetEnvironmentVariable("key1")); // old environment variable is overwritten
            Assert.Equal("value1", System.Environment.GetEnvironmentVariable("key2")); // old environment variable is preserved
            Assert.Equal("value3", System.Environment.GetEnvironmentVariable("key3")); // new environment variable is added
        }
Пример #11
0
        public void TestResolveSuccess()
        {
            var client = new SecretHub.Client();

            Assert.Equal("super_secret_value", client.Resolve("secrethub://secrethub/xgo/dotnet/test/test-secret"));
        }
Пример #12
0
        public void TestExists(string path, bool expectedTestResult)
        {
            var client = new SecretHub.Client();

            Assert.Equal(expectedTestResult, client.Exists(path));
        }