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