1#- 2# Copyright (c) 2022 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 14 15sethostname_body() 16{ 17 atf_check /usr/libexec/flua $(atf_get_srcdir)/sethostname.lua 18 if [ ! -f etc/rc.conf.d/hostname ]; then 19 atf_fail "hostname not written" 20 fi 21 atf_check -o inline:"hostname=\"myhostname\"\n" cat etc/rc.conf.d/hostname 22} 23 24addsshkey_body() 25{ 26 atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua 27 if [ ! -f .ssh/authorized_keys ]; then 28 atf_fail "ssh key not added" 29 fi 30 atf_check -o inline:"40700\n" stat -f %p .ssh 31 atf_check -o inline:"100600\n" stat -f %p .ssh/authorized_keys 32 atf_check -o inline:"mykey\n" cat .ssh/authorized_keys 33 atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua 34 atf_check -o inline:"mykey\nmykey\n" cat .ssh/authorized_keys 35} 36 37adduser_head() 38{ 39 atf_set "require.user" root 40} 41adduser_body() 42{ 43 mkdir etc 44 printf "root:*:0:0::0:0:Charlie &:/root:/bin/sh\n" > etc/master.passwd 45 pwd_mkdb -d etc etc/master.passwd 46 printf "wheel:*:0:root\n" > etc/group 47 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 48 test -d home/impossible_username || atf_fail "home not created" 49 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 50} 51 52adduser_passwd_body() 53{ 54 mkdir etc 55 printf "root:*:0:0::0:0:Charlie &:/root:/bin/sh\n" > etc/master.passwd 56 pwd_mkdb -d etc etc/master.passwd 57 printf "wheel:*:0:root\n" > etc/group 58 atf_check /usr/libexec/flua $(atf_get_srcdir)/adduser_passwd.lua 59 test -d home/foo || atf_fail "home not created" 60 passhash=`awk -F ':' '/^foo:/ {print $2}' etc/master.passwd` 61 atf_check -s exit:0 -o inline:$passhash \ 62 $(atf_get_srcdir)/crypt $passhash "bar" 63 passhash=`awk -F ':' '/^foocrypted:/ {print $2}' etc/master.passwd` 64 atf_check -s exit:0 -o inline:$passhash \ 65 $(atf_get_srcdir)/crypt $passhash "barcrypted" 66} 67 68addgroup_body() 69{ 70 mkdir etc 71 printf "wheel:*:0:root\n" > etc/group 72 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 73 atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group 74} 75 76atf_init_test_cases() 77{ 78 atf_add_test_case sethostname 79 atf_add_test_case addsshkey 80 atf_add_test_case adduser 81 atf_add_test_case adduser_passwd 82 atf_add_test_case addgroup 83} 84