Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/libexec/nuageinit/tests/nuage.sh
103755 views
1
#-
2
# Copyright (c) 2022-2025 Baptiste Daroussin <[email protected]>
3
# Copyright (c) 2025 Jesús Daniel Colmenares Oviedo <[email protected]>
4
#
5
# SPDX-License-Identifier: BSD-2-Clause
6
#
7
8
export NUAGE_FAKE_ROOTDIR="$PWD"
9
10
atf_test_case sethostname
11
atf_test_case settimezone
12
atf_test_case addsshkey
13
atf_test_case adduser
14
atf_test_case adduser_passwd
15
atf_test_case addgroup
16
atf_test_case addfile
17
18
settimezone_body()
19
{
20
atf_check /usr/libexec/flua $(atf_get_srcdir)/settimezone.lua
21
if [ ! -f etc/localtime ]; then
22
atf_fail "localtime not written"
23
fi
24
}
25
26
sethostname_body()
27
{
28
atf_check /usr/libexec/flua $(atf_get_srcdir)/sethostname.lua
29
if [ ! -f etc/rc.conf.d/hostname ]; then
30
atf_fail "hostname not written"
31
fi
32
atf_check -o inline:"hostname=\"myhostname\"\n" cat etc/rc.conf.d/hostname
33
}
34
35
addsshkey_body()
36
{
37
atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua
38
if [ ! -f .ssh/authorized_keys ]; then
39
atf_fail "ssh key not added"
40
fi
41
atf_check -o inline:"40700\n" stat -f %p .ssh
42
atf_check -o inline:"100600\n" stat -f %p .ssh/authorized_keys
43
atf_check -o inline:"mykey\n" cat .ssh/authorized_keys
44
atf_check /usr/libexec/flua $(atf_get_srcdir)/addsshkey.lua
45
atf_check -o inline:"mykey\nmykey\n" cat .ssh/authorized_keys
46
}
47
48
adduser_head()
49
{
50
atf_set "require.user" root
51
}
52
adduser_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 -e inline:"nuageinit: Argument should be a table\nnuageinit: Argument should be a table\n" /usr/libexec/flua $(atf_get_srcdir)/adduser.lua
59
test -d home/impossible_username || atf_fail "home not created"
60
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
61
}
62
63
adduser_passwd_body()
64
{
65
mkdir etc
66
printf "root:*:0:0::0:0:Charlie &:/root:/bin/sh\n" > etc/master.passwd
67
pwd_mkdb -d etc etc/master.passwd
68
printf "wheel:*:0:root\n" > etc/group
69
atf_check /usr/libexec/flua $(atf_get_srcdir)/adduser_passwd.lua
70
test -d home/foo || atf_fail "home not created"
71
passhash=`awk -F ':' '/^foo:/ {print $2}' etc/master.passwd`
72
atf_check -s exit:0 -o inline:$passhash \
73
$(atf_get_srcdir)/crypt $passhash "bar"
74
passhash=`awk -F ':' '/^foocrypted:/ {print $2}' etc/master.passwd`
75
atf_check -s exit:0 -o inline:$passhash \
76
$(atf_get_srcdir)/crypt $passhash "barcrypted"
77
}
78
79
addgroup_body()
80
{
81
mkdir etc
82
printf "wheel:*:0:root\n" > etc/group
83
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
84
atf_check -o inline:"impossible_groupname:*:1001:\n" grep impossible_groupname etc/group
85
}
86
87
addfile_body()
88
{
89
mkdir tmp
90
atf_check /usr/libexec/flua $(atf_get_srcdir)/addfile.lua
91
}
92
93
atf_init_test_cases()
94
{
95
atf_add_test_case sethostname
96
atf_add_test_case addsshkey
97
atf_add_test_case adduser
98
atf_add_test_case adduser_passwd
99
atf_add_test_case addgroup
100
atf_add_test_case addfile
101
}
102
103