diff --git a/plugins/plugin/internal-functions b/plugins/plugin/internal-functions index 67098e819e8..08e2ead4d06 100755 --- a/plugins/plugin/internal-functions +++ b/plugins/plugin/internal-functions @@ -33,3 +33,33 @@ plugin_prime_bash_completion() { dokku_log_info1_quiet "Priming bash-completion cache" dokku --quiet help --all | awk '/^ /{ print $1 }' | sort >"/var/cache/dokku-completion" } + +fn-is-core-plugin() { + declare PLUGIN_NAME="$1" + + if [[ -L "$PLUGIN_CORE_ENABLED_PATH/$PLUGIN_NAME" ]]; then + return 0 + fi + + return 1 +} + +fn-is-valid-plugin() { + declare PLUGIN_NAME="$1" + + if [[ "$PLUGIN_NAME" =~ ^[0-9a-zA-Z_-]+$ ]]; then + return 0 + fi + + return 1 +} + +fn-plugin-enabled() { + declare PLUGIN_NAME="$1" + + if [[ -L "$PLUGIN_ENABLED_PATH/$PLUGIN_NAME" ]]; then + return 0 + fi + + return 1 +} diff --git a/plugins/plugin/subcommands/install b/plugins/plugin/subcommands/install index 64351ad0927..ab3db3354af 100755 --- a/plugins/plugin/subcommands/install +++ b/plugins/plugin/subcommands/install @@ -21,6 +21,12 @@ cmd-plugin-install() { plugn trigger install ;; *) + if [[ -n "$FLAG" ]]; then + dokku_log_warn "First argument must be --core or url to plugin" + dokku_log_warn "Valid prefixes: https:, git:, ssh:, file:" + dokku_log_warn "Valid suffixes: .tar.gz, .tgz" + dokku_log_fail "Please retry with valid arguments" + fi plugn trigger install ;; esac diff --git a/plugins/plugin/subcommands/update b/plugins/plugin/subcommands/update index 366b09bb615..6f8be432141 100755 --- a/plugins/plugin/subcommands/update +++ b/plugins/plugin/subcommands/update @@ -10,8 +10,21 @@ cmd-plugin-update() { declare PLUGIN="$1" PLUGIN_COMMITTISH="$2" if [[ -n "$PLUGIN" ]]; then + if ! fn-is-valid-plugin "$PLUGIN"; then + dokku_log_fail "Invalid plugin name specified" + fi + + if ! fn-plugin-enabled "$PLUGIN"; then + dokku_log_fail "Specified plugin not enabled or installed" + fi + + if fn-is-core-plugin "$PLUGIN"; then + dokku_log_fail "Cannot trigger plugin:update against core plugin, please update Dokku instead" + fi + plugn update "$PLUGIN" "$PLUGIN_COMMITTISH" fi + plugn trigger update plugin_prime_bash_completion } diff --git a/tests/unit/plugin.bats b/tests/unit/plugin.bats index 25f226dfbac..10761acf84f 100644 --- a/tests/unit/plugin.bats +++ b/tests/unit/plugin.bats @@ -42,7 +42,7 @@ teardown() { run /bin/bash -c "dokku plugin:installed $TEST_PLUGIN_NAME" echo "output: $output" echo "status: $status" - assert_failure + assert_failure run /bin/bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO --name $TEST_PLUGIN_NAME" echo "output: $output" @@ -52,7 +52,7 @@ teardown() { run /bin/bash -c "dokku plugin:installed $TEST_PLUGIN_NAME" echo "output: $output" echo "status: $status" - assert_success + assert_success run /bin/bash -c "dokku plugin:update $TEST_PLUGIN_NAME" echo "output: $output" @@ -214,6 +214,80 @@ teardown() { assert_output_contains "dokku" "3" } +@test "(plugin) plugin:install [errors]" { + run /bin/bash -c "dokku plugin:install YABBA_DABBA_DOO XXXX YYYY" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Please retry with valid arguments" + + run /bin/bash -c "dokku plugin:install ZXZX --random-flag" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Please retry with valid arguments" + + run /bin/bash -c "dokku plugin:install http://www.example.com/ --random-flag" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Please retry with valid arguments" + + run /bin/bash -c "dokku plugin:install http://www.example.com/gives-a-404" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Please retry with valid arguments" + + run /bin/bash -c "dokku plugin:install http://xxxx/ --random-flag" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Please retry with valid arguments" + + run /bin/bash -c "dokku plugin:install /path/to/nonexistent/dir" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Please retry with valid arguments" +} + +@test "(plugin) plugin:update [errors]" { + 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 plugin:disable $TEST_PLUGIN_NAME" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku plugin:update $TEST_PLUGIN_NAME" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Specified plugin not enabled or installed" + + run /bin/bash -c "dokku plugin:update invalid" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Specified plugin not enabled or installed" + + run /bin/bash -c "dokku plugin:update $TEST_PLUGIN_GIT_REPO" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "Invalid plugin name specified" + + run /bin/bash -c "dokku plugin:update app-json" + echo "output: $output" + echo "status: $status" + assert_failure + assert_output_contains "please update Dokku instead" +} + @test "(plugin) plugin:update permissions set properly" { run /bin/bash -c "ls -lah /var/lib/dokku/core-plugins/available/git/commands" echo "output: $output"