1#- 2# Copyright (c) 2022-2025 Baptiste Daroussin <bapt@FreeBSD.org> 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6 7export NUAGE_FAKE_ROOTDIR="$PWD" 8 9atf_test_case sethostname 10atf_test_case addsshkey 11atf_test_case adduser 12atf_test_case adduser_passwd 13atf_test_case addgroup 14atf_test_case addfile 15 16sethostname_body() 17{ 18 atf_check /usr/libexec/flua $(atf_get_srcdir)/sethostname.lua 19 if [ ! -f etc/rc.conf.d/hostname ]; then 20 atf_fail "hostname not written" 21 fi 22 atf_check -o inline:"hostname=\"myhostname\"\n" cat etc/rc.conf.d/hostname 23} 24 25addsshkey_body() 26{ 27 atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua 28 if [ ! -f .ssh/authorized_keys ]; then 29 atf_fail "ssh key not added" 30 fi 31 atf_check -o inline:"40700\n" stat -f %p .ssh 32 atf_check -o inline:"100600\n" stat -f %p .ssh/authorized_keys 33 atf_check -o inline:"mykey\n" cat .ssh/authorized_keys 34 atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua 35 atf_check -o inline:"mykey\nmykey\n" cat .ssh/authorized_keys 36} 37 38adduser_head() 39{ 40 atf_set "require.user" root 41} 42adduser_body() 43{ 44 mkdir etc 45 printf "root:*:0:0::0:0:Charlie &:/root:/bin/sh\n" > etc/master.passwd 46 pwd_mkdb -d etc etc/master.passwd 47 printf "wheel:*:0:root\n" > etc/group 48 atf_check -e inline:"nuageinit: Argument should be a table\nnuageinit: Argument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/adduser.lua 49 test -d home/impossible_username || atf_fail "home not created" 50 atf_check -o inline:"impossible_username::1001:1001::0:0:impossible_username User:/home/impossible_username:/bin/sh\n" grep impossible_username etc/master.passwd 51} 52 53adduser_passwd_body() 54{ 55 mkdir etc 56 printf "root:*:0:0::0:0:Charlie &:/root:/bin/sh\n" > etc/master.passwd 57 pwd_mkdb -d etc etc/master.passwd 58 printf "wheel:*:0:root\n" > etc/group 59 atf_check /usr/libexec/flua $(atf_get_srcdir)/adduser_passwd.lua 60 test -d home/foo || atf_fail "home not created" 61 passhash=`awk -F ':' '/^foo:/ {print $2}' etc/master.passwd` 62 atf_check -s exit:0 -o inline:$passhash \ 63 $(atf_get_srcdir)/crypt $passhash "bar" 64 passhash=`awk -F ':' '/^foocrypted:/ {print $2}' etc/master.passwd` 65 atf_check -s exit:0 -o inline:$passhash \ 66 $(atf_get_srcdir)/crypt $passhash "barcrypted" 67} 68 69addgroup_body() 70{ 71 mkdir etc 72 printf "wheel:*:0:root\n" > etc/group 73 atf_check -e inline:"nuageinit: Argument should be a table\nnuageinit: Argument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/addgroup.lua 74 atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group 75} 76 77addfile_body() 78{ 79 mkdir tmp 80 atf_check /usr/libexec/flua $(atf_get_srcdir)/addfile.lua 81} 82 83atf_init_test_cases() 84{ 85 atf_add_test_case sethostname 86 atf_add_test_case addsshkey 87 atf_add_test_case adduser 88 atf_add_test_case adduser_passwd 89 atf_add_test_case addgroup 90 atf_add_test_case addfile 91} 92