public async void WriteAribtraryBytes() { using (var client = new VaultClient(TestVaultAddress)) { client.VaultToken = TestRootToken; var bytes = new byte[] { 0, 1, 2, 3, 4, 5 }; var ex = await Assert.ThrowsAsync <VaultClientException>( async() => await client.WriteAsync("secret/secret-o-bytes", bytes)); Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode); } }
public async void WriteSecretWithoutAuth() { using (var client = new VaultClient(TestVaultAddress)) { var ex = await Assert.ThrowsAsync <VaultClientException>(async() => await client.WriteAsync("secret/any-place-we-choose", new { a = 1, B = 2, })); Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode); Assert.Equal("missing client token", ex.Errors?.Errors?.FirstOrDefault()); } }
public async void WriteSecret() { using (var client = new VaultClient(TestVaultAddress) { VaultToken = TestRootToken, }) { await client.WriteAsync("secret/foo2", new { a = 1, B = "Two", c = DateTime.Now, DDD = Encoding.UTF8.GetBytes("Hello World!!!"), }); } }
public async void WriteSecretWithBadAuth() { using (var client = new VaultClient(TestVaultAddress) { VaultToken = "bad-token", }) { var ex = await Assert.ThrowsAsync <VaultClientException>(async() => await client.WriteAsync("secret/any-place-we-choose", new { a = 1, B = 2, })); Assert.Equal(HttpStatusCode.Forbidden, ex.StatusCode); Assert.Equal("permission denied", ex.Errors?.Errors?.FirstOrDefault()); } }
public async void LongestMountWins() { using (var client = new VaultClient(TestVaultAddress)) { client.VaultToken = TestRootToken; var mounts = await client.ListMountedBackendsAsync(); Assert.DoesNotContain("a/", mounts.Data.Keys); Assert.DoesNotContain("a/b/", mounts.Data.Keys); Assert.DoesNotContain("a/b/c/", mounts.Data.Keys); Assert.DoesNotContain("a/b/c/d/", mounts.Data.Keys); Assert.DoesNotContain("a/b/c/d/e/", mounts.Data.Keys); Assert.DoesNotContain("a/b/c/d/e/f/", mounts.Data.Keys); try { await client.MountBackendAsync("a/b/c/d/", "generic"); mounts = await client.ListMountedBackendsAsync(); Assert.Contains("a/b/c/d/", mounts.Data.Keys); await client.WriteAsync("a/b/c/d/e/f", new TestClass1 { Key1 = "val1" }); var read = await client.ReadAsync <ReadResponse <TestClass1> >("a/b/c/d/e/f"); Assert.Equal("val1", read.Data.Key1); await client.MountBackendAsync("a/b", "generic"); mounts = await client.ListMountedBackendsAsync(); Assert.Contains("a/b/", mounts.Data.Keys); await client.WriteAsync("a/b/c/d/e/f", new TestClass1 { Key1 = "val1" }); read = await client.ReadAsync <ReadResponse <TestClass1> >("a/b/c/d/e/f"); Assert.Equal("val1", read.Data.Key1); await client.UnmountBackendAsync("a/b/c/d"); mounts = await client.ListMountedBackendsAsync(); Assert.DoesNotContain("a/b/c/d/", mounts.Data.Keys); var ex = await Assert.ThrowsAsync <VaultClientException>(async() => read = await client.ReadAsync <ReadResponse <TestClass1> >("a/b/c/d/e/f")); Assert.Equal(HttpStatusCode.NotFound, ex.StatusCode); await client.WriteAsync("a/b/c/d/e/f", new TestClass1 { Key1 = "VAL2" }); read = await client.ReadAsync <ReadResponse <TestClass1> >("a/b/c/d/e/f"); Assert.Equal("VAL2", read.Data.Key1); } finally { await client.UnmountBackendAsync("a/b/c/d"); await client.UnmountBackendAsync("a/b"); } mounts = await client.ListMountedBackendsAsync(); Assert.DoesNotContain("a/b/c/d/", mounts.Data.Keys); Assert.DoesNotContain("a/b/", mounts.Data.Keys); } }