add_key() {
local user
+ [ "$NB_ADMIN" ] || return 1
+ case $# in
+ 0) die "Username argument missing";;
+ 1) break;;
+ *) die "User name must not contain spaces: $*";;
+ esac
user="$1"
- die "Not implemented"
+ key=$(cat)
+
+ tmp=$(mktemp ~/.ssh/authorized_keys.XXXXXXXX)
+ {
+ cat ~/.ssh/authorized_keys
+ echo "command=\"user $user\" $key"
+ } | sort -u > $tmp
+
+ mv $tmp ~/.ssh/authorized_keys
}
lock_queue() {
SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
+AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
+WVSTART "Setup SSH server's admin key"
+WVPASS ssh-add -L > keys
+WVPASS test $(wc -l < keys) -gt 0
+WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
WVSTART "Novaboot --ssh option (connect, rsync, reset)"
WVPASS rm -rf $TFTPROOT
WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
load file < date
EOF
+
+WVSTART "add-key subcommand"
+WVPASS ssh-keygen -t ed25519 -N '' -f key
+WVFAIL grep new_user $AUTH
+WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
+WVPASS grep new_user $AUTH
+
+WVSTART "add-key user must not contain spaces"
+WVPASS cp $AUTH auth
+WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
+WVPASS diff -u $AUTH auth
+
+WVSTART "add-key requires username"
+WVPASS cp $AUTH auth
+WVFAIL ssh novaboot-test@localhost add-key < /dev/null
+WVPASS diff -u $AUTH auth