xref: /freebsd/libexec/nuageinit/tests/nuage.sh (revision 783d3ff6)
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:"mykey\n" cat .ssh/authorized_keys
21	atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua
22	atf_check -o inline:"mykey\nmykey\n" cat .ssh/authorized_keys
23}
24
25adduser_body() {
26	export NUAGE_FAKE_ROOTDIR="$(pwd)"
27	if [ $(id -u) -ne 0 ]; then
28		atf_skip "root required"
29	fi
30	mkdir etc
31	printf "root:*:0:0::0:0:Charlie &:/root:/bin/csh\n" > etc/master.passwd
32	pwd_mkdb -d etc etc/master.passwd
33	printf "wheel:*:0:root\n" > etc/group
34	atf_check -e inline:"Argument should be a table\nArgument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/adduser.lua
35	test -d home/impossible_username || atf_fail "home not created"
36	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
37}
38
39addgroup_body() {
40	export NUAGE_FAKE_ROOTDIR="$(pwd)"
41	mkdir etc
42	printf "wheel:*:0:root\n" > etc/group
43	atf_check -e inline:"Argument should be a table\nArgument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/addgroup.lua
44	atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group
45}
46
47atf_init_test_cases() {
48	atf_add_test_case sethostname
49	atf_add_test_case addsshkey
50	atf_add_test_case adduser
51	atf_add_test_case addgroup
52}
53