Skip to content

Commit

Permalink
update tests for special characters to better capture patterns we exp…
Browse files Browse the repository at this point in the history
…ect to account for in secrets
  • Loading branch information
jeremybumsted committed Mar 23, 2023
1 parent 1b76865 commit 38ab999
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tests/environment-hook.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ load '/usr/local/lib/bats/load.bash'
@test "Load default env file containing secrets with special characters from vault server" {
export BUILDKITE_PLUGIN_VAULT_SECRETS_SERVER=https://vault_svr_url
export BUILDKITE_PLUGIN_VAULT_SECRETS_DUMP_ENV=true
export TESTDATA="MY_SECRET=\"|- : fooblah\""
export TESTDATA="MY_SECRET=\"|- $:fooblah\""
export BUILDKITE_PIPELINE_SLUG=testpipe

stub vault \
Expand All @@ -43,12 +43,34 @@ load '/usr/local/lib/bats/load.bash'
run bash -c "$PWD/hooks/environment && $PWD/hooks/pre-exit"

assert_success
assert_output --partial "MY_SECRET=|- :fooblah"
assert_output --partial "MY_SECRET=|- $:fooblah"
refute_output --partial "ANOTHER_SECRET=baa"

unstub vault
}


@test "Load default env file and convert secrets with \": \" pattern from vault server" {
export BUILDKITE_PLUGIN_VAULT_SECRETS_SERVER=https://vault_svr_url
export BUILDKITE_PLUGIN_VAULT_SECRETS_DUMP_ENV=true
export TESTDATA="MY_SECRET=\"Likes: llamas\""
export BUILDKITE_PIPELINE_SLUG=testpipe

stub vault \
"kv list -address=https://vault_svr_url -format=yaml data/buildkite/testpipe : exit 0" \
"kv list -address=https://vault_svr_url -format=yaml data/buildkite : echo 'env'" \
"kv get -address=https://vault_svr_url -field=data -format=yaml data/buildkite/env : echo ${TESTDATA}"

run bash -c "$PWD/hooks/environment && $PWD/hooks/pre-exit"

assert_success
assert_output --partial "MY_SECRET=Likes=llamas"
refute_output --partial "ANOTHER_SECRET=baa"

unstub vault
}


@test "Load default environment file from vault server" {
export BUILDKITE_PLUGIN_VAULT_SECRETS_SERVER=https://vault_svr_url
export BUILDKITE_PLUGIN_VAULT_SECRETS_DUMP_ENV=true
Expand Down

0 comments on commit 38ab999

Please sign in to comment.