diff --git a/plugins/ssh-keys/subcommands/add b/plugins/ssh-keys/subcommands/add index dd3ba7afc..b6fa76bce 100755 --- a/plugins/ssh-keys/subcommands/add +++ b/plugins/ssh-keys/subcommands/add @@ -29,7 +29,8 @@ add_keys() { fi local count="$(wc -l "$KEY_FILE" | awk '{ print $1; }')" - [[ "$count" -eq 1 ]] || dokku_log_fail "Too many keys provided, set one per invocation of dokku ssh-keys:add " + # Don't check for "-eq 1" as no newlines is also a valid SSH key + [[ "$count" -lt 2 ]] || dokku_log_fail "Too many keys provided, set one per invocation of dokku ssh-keys:add " ssh-keygen -lf "$KEY_FILE" &>/dev/null || dokku_log_fail "Key specified in is not a valid ssh public key" create_ssh_key_file verify_ssh_key_exists diff --git a/tests/unit/30_ssh_keys.bats b/tests/unit/30_ssh_keys.bats index 3b23aefea..b024a9427 100644 --- a/tests/unit/30_ssh_keys.bats +++ b/tests/unit/30_ssh_keys.bats @@ -13,6 +13,9 @@ setup() { # now create key that will be really used create_key + # Test key without a trailing newline + echo -n "$KEY" > /tmp/testkey-no-newline.pub + # the temporary key is useful for adding in the file with two keys # useful for a negative test { cat /tmp/testkey.pub ; echo "$KEY" ; } > /tmp/testkey-double.pub @@ -70,6 +73,10 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + run /bin/bash -c "dokku ssh-keys:add name5 /tmp/testkey-no-newline.pub" + echo "output: $output" + echo "status: $status" + assert_success # leave this as the last test in the sequence! It introduces an error in authorized_keys run /bin/bash -c 'echo invalid >> "${DOKKU_ROOT:-/home/dokku}/.ssh/authorized_keys"'