Skip to content

Commit

Permalink
Added tests for context vault patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed May 27, 2023
1 parent 65c53c2 commit 6d8a490
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class VaultContextResolverTest : FunSpec({
val ext = TestContainerExtension(container)
install(ext)

test("placeholder should be detected and used") {
test("prefix pattern should be detected and used") {

val props = Properties()
props["foo"] = "vault://secret/testing secret1"
Expand All @@ -50,6 +50,28 @@ class VaultContextResolverTest : FunSpec({
config.bar.shouldBe("bottomsecret!")
}

test("context pattern should be detected and used") {

val props = Properties()
props["foo"] = "hello \${{ vault:secret/testing secret1}} world"
props["bar"] = "world \${{ vault:secret/testing/nested secret2 }} hello"

val endpoint = VaultEndpoint.create(container.host, container.firstMappedPort)
endpoint.scheme = "http" // test container doesn't use https

val template = VaultTemplate(endpoint, TokenAuthentication("my-token"))

val config = ConfigLoaderBuilder.default()
.removePreprocessors()
.addResolver(VaultContextResolver({ template }))
.addPropertySource(PropsPropertySource(props))
.build()
.loadConfigOrThrow<ConfigHolder>()

config.foo.shouldBe("hello topsecret! world")
config.bar.shouldBe("world bottomsecret! hello")
}

test("invalid vault placeholder error") {

val props = Properties()
Expand Down

0 comments on commit 6d8a490

Please sign in to comment.