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