这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions plugins/plugin/internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions plugins/plugin/subcommands/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions plugins/plugin/subcommands/update
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
78 changes: 76 additions & 2 deletions tests/unit/plugin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down