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