Skip to content

Commit

Permalink
Fix panic on data keys in KV1 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
fishi0x01 authored Jan 27, 2021
1 parent 199741f commit 07bebe5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## Latest

ENHANCEMENTS:

* Allow regex on `grep` operation ([#61](https://github.com/fishi0x01/vsh/pull/61) - Thank you for implementation [mattlqx](https://github.com/mattlqx))
* Allow quotes and escapes in input ([#61](https://github.com/fishi0x01/vsh/pull/61) - Thank you for implementation [mattlqx](https://github.com/mattlqx))

BUG FIXES:

* Fix panic on `data` keys in KV1 ([#63](https://github.com/fishi0x01/vsh/pull/63) - Thank you for issue submission [tommartensen](https://github.com/tommartensen))

## v0.7.2 (October 4, 2020)

BUG FIXES:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ get-bats: ## Download bats dependencies to test directory
curl -sL https://github.com/bats-core/bats-file/archive/v0.2.0.tar.gz | tar xvz --strip 1 -C test/bin/plugins/bats-file

integration-tests: ## Run integration test suites (requires bats - see get-bats)
test/run.sh
test/run-all-tests.sh

single-test: ## Run a single test suite, e.g., make single-test KV_BACKEND=KV2 VAULT_VERSION=1.6.1 TEST_SUITE=commands/cp
KV_BACKEND=$(KV_BACKEND) VAULT_VERSION=$(VAULT_VERSION) TEST_SUITE=$(TEST_SUITE) test/run-single-test.sh

local-vault-test-instance: ## Start a local vault container with integration test provisioning
bash -c ". test/util/util.bash && setup"
Expand Down
2 changes: 1 addition & 1 deletion client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (client *Client) isTopLevelPath(absolutePath string) bool {
}

func isValidKV2Data(secret *api.Secret) bool {
_, exists := secret.Data["data"]
_, exists := secret.Data["data"].(map[string]interface{})
return exists
}

Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions test/run-single-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e # required to fail test suite when a single test fails

VAULT_VERSION=${VAULT_VERSION:-"1.6.1"}
KV_BACKEND=${KV_BACKEND:-"KV2"}
TEST_SUITE=${TEST_SUITE:-"commands/cp"}

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
export DIR
BATS="${DIR}/bin/core/bin/bats"

VAULT_VERSION=${VAULT_VERSION} KV_BACKEND="${KV_BACKEND}" ${BATS} "${DIR}/suites/${TEST_SUITE}.bats"
21 changes: 21 additions & 0 deletions test/suites/commands/cp.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ load ../../bin/plugins/bats-assert/load
assert_success
assert_output "test"

#########################################
echo "==== case: copy single files with 'data' key ===="
run ${APP_BIN} -c "cp ${KV_BACKEND}/src/data/1 ${KV_BACKEND}/dest/data/1"
assert_success

echo "ensure the file got copied to destination"
run get_vault_value "data" "${KV_BACKEND}/dest/data/1"
assert_success
assert_output "1"

run ${APP_BIN} -c "cp ${KV_BACKEND}/src/data/2 ${KV_BACKEND}/dest/data/2"
assert_success

echo "ensure the file got copied to destination"
run get_vault_value "data" "${KV_BACKEND}/dest/data/2"
assert_success
assert_output "2"
run get_vault_value "value" "${KV_BACKEND}/dest/data/2"
assert_success
assert_output "1"

#######################################
echo "==== case: copy non-existing file ===="
run ${APP_BIN} -c "cp ${KV_BACKEND}/src/does/not/exist ${KV_BACKEND}/dest/a"
Expand Down
4 changes: 3 additions & 1 deletion test/util/util.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

export VAULT_VERSION=${VAULT_VERSION:-"1.5.3"}
export VAULT_VERSION=${VAULT_VERSION:-"1.6.1"}
export VAULT_CONTAINER_NAME="vsh-integration-test-vault"
export VAULT_HOST_PORT=${VAULT_HOST_PORT:-"8888"}

Expand Down Expand Up @@ -39,6 +39,8 @@ setup() {
vault_exec "vault secrets enable -version=2 -path=KV2 kv"
for kv_backend in "${KV_BACKENDS[@]}"
do
vault_exec "vault kv put ${kv_backend}/src/data/1 data=1"
vault_exec "vault kv put ${kv_backend}/src/data/2 value=1 data=2"
vault_exec "vault kv put ${kv_backend}/src/dev/1 value=1 fruit=apple"
vault_exec "vault kv put ${kv_backend}/src/dev/2 value=2 fruit=banana"
vault_exec "vault kv put ${kv_backend}/src/dev/3 value=3 fruit=berry"
Expand Down

0 comments on commit 07bebe5

Please sign in to comment.