diff --git a/contrib/dokku_client.sh b/contrib/dokku_client.sh index 590d3d0dc8c..d2c7c4f047a 100755 --- a/contrib/dokku_client.sh +++ b/contrib/dokku_client.sh @@ -188,9 +188,14 @@ main() { [[ " storage:ensure-directory " == *" $CMD "* ]] && unset APP [[ "$CMD" =~ events*|plugin*|ssh-keys* ]] && unset APP [[ -n "$APP_ARG" ]] && [[ "$APP_ARG" == "--global" ]] && unset APP - [[ -n "$@" ]] && [[ -n "$APP" ]] && app_arg="--app $APP" + if [[ -n "$@" ]] && [[ -n "$APP" ]]; then + set -- "$APP" "$@" + set -- "--app" "$@" + fi # echo "ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_REMOTE_HOST -- $app_arg $@" - ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_REMOTE_HOST -- $app_arg $@ || { + local ssh_args=("-o" "LogLevel=QUIET" "-p" "$DOKKU_PORT" "-t" "dokku@$DOKKU_REMOTE_HOST" "--") + ssh_args+=("$@") + ssh "${ssh_args[@]}" || { ssh_exit_code="$?" echo " ! Failed to execute dokku command over ssh: exit code $?" 1>&2 echo " ! If there was no output from Dokku, ensure your configured SSH Key can connect to the remote server" 1>&2 diff --git a/dokku b/dokku index 46f8d6f9297..755e652e6d7 100755 --- a/dokku +++ b/dokku @@ -106,15 +106,20 @@ fi if [[ -n "$SSH_ORIGINAL_COMMAND" ]]; then export -n SSH_ORIGINAL_COMMAND - if [[ $1 =~ config-* ]] || [[ $1 =~ docker-options* ]]; then - xargs $0 <<<$SSH_ORIGINAL_COMMAND - exit $? - else + exit_code=0 + if [[ $1 =~ git-* ]] || [[ $1 =~ git:* ]]; then set -f $0 $SSH_ORIGINAL_COMMAND + exit_code=$? + set +f + else + readarray -t -O "${#ssh_arg_array[@]}" ssh_arg_array < <(printf '%s' "$SSH_ORIGINAL_COMMAND" | xargs -n 1) + set -f + $0 "${ssh_arg_array[@]}" + exit_code=$? set +f - exit $? fi + exit $exit_code fi if ! dokku_auth "$@"; then diff --git a/tests/unit/client.bats b/tests/unit/client.bats index bfb51a64d90..0c0610ea934 100644 --- a/tests/unit/client.bats +++ b/tests/unit/client.bats @@ -6,9 +6,11 @@ setup() { global_setup export "DOKKU_HOST=${DOKKU_DOMAIN}" create_app + clone_test_plugin } teardown() { + remove_test_plugin || true destroy_app unset DOKKU_HOST global_teardown @@ -311,3 +313,22 @@ teardown() { assert_success assert_output "dokku" } + +@test "(client) test-args" { + run /bin/bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO --name $TEST_PLUGIN_NAME" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku smoke-test-plugin:args bash -c 'echo Hello'" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "triggered smoke-test-plugin:args with args: smoke-test-plugin:args, bash, -c, echo Hello" + + run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh 'smoke-test-plugin:args bash -c \"echo Hello\"'" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "triggered smoke-test-plugin:args with args: smoke-test-plugin:args, bash, -c, echo Hello" +} diff --git a/tests/unit/plugin.bats b/tests/unit/plugin.bats index 10761acf84f..9323bb41748 100644 --- a/tests/unit/plugin.bats +++ b/tests/unit/plugin.bats @@ -1,24 +1,12 @@ #!/usr/bin/env bats load test_helper -TEST_PLUGIN_NAME=smoke-test-plugin -TEST_PLUGIN_GIT_REPO=https://github.com/dokku/${TEST_PLUGIN_NAME}.git -TEST_PLUGIN_LOCAL_REPO="$(mktemp -d)/$TEST_PLUGIN_NAME" - -clone_test_plugin() { - git clone "$TEST_PLUGIN_GIT_REPO" "$TEST_PLUGIN_LOCAL_REPO" -} setup() { global_setup clone_test_plugin } -remove_test_plugin() { - rm -rf $PLUGIN_ENABLED_PATH/$TEST_PLUGIN_NAME $PLUGIN_AVAILABLE_PATH/$TEST_PLUGIN_NAME - rm -rf $TEST_PLUGIN_LOCAL_REPO -} - teardown() { remove_test_plugin || true global_teardown diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 56dba8a8714..cb5af752b1f 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -15,6 +15,9 @@ UUID=$(uuidgen) TEST_APP="rdmtestapp-${UUID}" TEST_NETWORK="test-network-${UUID}" SKIPPED_TEST_ERR_MSG="previous test failed! skipping remaining tests..." +TEST_PLUGIN_NAME=smoke-test-plugin +TEST_PLUGIN_GIT_REPO=https://github.com/dokku/${TEST_PLUGIN_NAME}.git +TEST_PLUGIN_LOCAL_REPO="$(mktemp -d)/$TEST_PLUGIN_NAME" # global setup() and teardown() # skips remaining tests on first failure @@ -45,6 +48,15 @@ cleanup_containers() { fi } +clone_test_plugin() { + git clone "$TEST_PLUGIN_GIT_REPO" "$TEST_PLUGIN_LOCAL_REPO" +} + +remove_test_plugin() { + rm -rf "${PLUGIN_ENABLED_PATH:?}/$TEST_PLUGIN_NAME" "${PLUGIN_AVAILABLE_PATH:?}/$TEST_PLUGIN_NAME" + rm -rf "$TEST_PLUGIN_LOCAL_REPO" +} + # test functions flunk() { {