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