mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2025-12-15 11:22:43 +03:00
Add test for ssh-keys in nocloud yaml
This commit is contained in:
parent
0f53f14399
commit
a67cbd37b0
@ -26,7 +26,7 @@ set_ssh_keys() {
|
||||
local user="$CLOUD_USER"
|
||||
local pwent=$(getent passwd "$user")
|
||||
local group=$(echo "$pwent" | cut -d: -f4)
|
||||
local ssh_dir="$(echo "$pwent" | cut -d: -f6)/.ssh"
|
||||
local ssh_dir="${ROOT}$(echo "$pwent" | cut -d: -f6)/.ssh"
|
||||
local keys_file="$ssh_dir/authorized_keys"
|
||||
|
||||
if [ ! -d "$ssh_dir" ]; then
|
||||
@ -36,7 +36,7 @@ set_ssh_keys() {
|
||||
|
||||
touch "$keys_file"
|
||||
chmod 600 "$keys_file"
|
||||
chown -R "$user:$group" "$ssh_dir"
|
||||
$MOCK chown -R "$user:$group" "$ssh_dir"
|
||||
imds @ssh-keys > "$keys_file"
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,8 @@ export MOCK=echo
|
||||
lib="$srcdir"/lib/tiny-cloud/init-main
|
||||
|
||||
init_tests \
|
||||
set_hostname
|
||||
set_hostname \
|
||||
set_ssh_keys
|
||||
|
||||
|
||||
set_nocloud_meta() {
|
||||
@ -51,3 +52,20 @@ set_hostname_body() {
|
||||
fi
|
||||
}
|
||||
|
||||
set_ssh_keys_body() {
|
||||
fake_bin getent <<-EOF
|
||||
#!/bin/sh
|
||||
echo "alpine:x:1000:1000:Linux User,,,:/home/alpine:/bin/sh"
|
||||
EOF
|
||||
set_nocloud_meta user-data <<-EOF
|
||||
public-keys:
|
||||
- openssh-key: ssh-ed25519 keydata
|
||||
- openssh-key: ssh-rsa foobar
|
||||
EOF
|
||||
CLOUD="nocloud" atf_check \
|
||||
-o match:"chown.*/\.ssh" \
|
||||
sh -c ". \"$lib\"; set_ssh_keys"
|
||||
atf_check -o match:"^ssh-ed25519 keydata" \
|
||||
-o match:"^ssh-rsa foobar" \
|
||||
cat home/alpine/.ssh/authorized_keys
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user