xref: /freebsd/libexec/nuageinit/tests/nuage.sh (revision 8edd6c07c8dafcc5828bceb5fea0684c7d0d0775)
1atf_test_case sethostname
2atf_test_case addsshkey
3atf_test_case adduser
4atf_test_case addgroup
5
6sethostname_body() {
7	export NUAGE_FAKE_ROOTDIR="$(pwd)"
8	atf_check /usr/libexec/flua $(atf_get_srcdir)/sethostname.lua
9	if [ ! -f etc/rc.conf.d/hostname ]; then
10		atf_fail "hostname not written"
11	fi
12	atf_check -o inline:"hostname=\"myhostname\"\n" cat etc/rc.conf.d/hostname
13}
14
15addsshkey_body() {
16	atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua
17	if [ ! -f .ssh/authorized_keys ]; then
18		atf_fail "ssh key not added"
19	fi
20	atf_check -o inline:"40700\n" stat -f %p .ssh
21	atf_check -o inline:"100600\n" stat -f %p .ssh/authorized_keys
22	atf_check -o inline:"mykey\n" cat .ssh/authorized_keys
23	atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua
24	atf_check -o inline:"mykey\nmykey\n" cat .ssh/authorized_keys
25}
26
27adduser_body() {
28	export NUAGE_FAKE_ROOTDIR="$(pwd)"
29	if [ $(id -u) -ne 0 ]; then
30		atf_skip "root required"
31	fi
32	mkdir etc
33	printf "root:*:0:0::0:0:Charlie &:/root:/bin/csh\n" > etc/master.passwd
34	pwd_mkdb -d etc etc/master.passwd
35	printf "wheel:*:0:root\n" > etc/group
36	atf_check -e inline:"Argument should be a table\nArgument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/adduser.lua
37	test -d home/impossible_username || atf_fail "home not created"
38	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
39}
40
41addgroup_body() {
42	export NUAGE_FAKE_ROOTDIR="$(pwd)"
43	mkdir etc
44	printf "wheel:*:0:root\n" > etc/group
45	atf_check -e inline:"Argument should be a table\nArgument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/addgroup.lua
46	atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group
47}
48
49atf_init_test_cases() {
50	atf_add_test_case sethostname
51	atf_add_test_case addsshkey
52	atf_add_test_case adduser
53	atf_add_test_case addgroup
54}
55