]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-46.sh
Merge pull request #21838 from lnussel/logind-refactor
[thirdparty/systemd.git] / test / units / testsuite-46.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -eux
4 set -o pipefail
5
6 # Check if homectl is installed, and if it isn't bail out early instead of failing
7 if ! test -x /usr/bin/homectl ; then
8 echo "no homed" >/skipped
9 exit 0
10 fi
11
12 inspect() {
13 # As updating disk-size-related attributes can take some time on some
14 # filesystems, let's drop these fields before comparing the outputs to
15 # avoid unexpected fails. To see the full outputs of both homectl &
16 # userdbctl (for debugging purposes) drop the fields just before the
17 # comparison.
18 local USERNAME="${1:?missing argument}"
19 homectl inspect "$USERNAME" | tee /tmp/a
20 userdbctl user "$USERNAME" | tee /tmp/b
21
22 # diff uses the grep BREs for pattern matching
23 diff -I '^\s*Disk \(Size\|Free\|Floor\|Ceiling\):' /tmp/{a,b}
24 rm /tmp/{a,b}
25
26 homectl inspect --json=pretty "$USERNAME"
27 }
28
29 wait_for_state() {
30 for ((i=0;i<10;i++)) ; do
31 homectl inspect "$1" | grep -qF "State: $2" && break
32 sleep .5
33 done
34 }
35
36 systemd-analyze log-level debug
37 systemd-analyze log-target console
38 systemctl service-log-level systemd-homed debug
39
40 # Create a tmpfs to use as backing store for the home dir. That way we can enforce a size limit nicely.
41 mkdir -p /home
42 mount -t tmpfs tmpfs /home -o size=290M
43
44 # we enable --luks-discard= since we run our tests in a tight VM, hence don't
45 # needlessly pressure for storage. We also set the cheapest KDF, since we don't
46 # want to waste CI CPU cycles on it.
47 NEWPASSWORD=xEhErW0ndafV4s homectl create test-user \
48 --disk-size=min \
49 --luks-discard=yes \
50 --image-path=/home/test-user.home \
51 --luks-pbkdf-type=pbkdf2 \
52 --luks-pbkdf-time-cost=1ms
53 inspect test-user
54
55 PASSWORD=xEhErW0ndafV4s homectl authenticate test-user
56
57 PASSWORD=xEhErW0ndafV4s homectl activate test-user
58 inspect test-user
59
60 PASSWORD=xEhErW0ndafV4s homectl update test-user --real-name="Inline test"
61 inspect test-user
62
63 homectl deactivate test-user
64 inspect test-user
65
66 PASSWORD=xEhErW0ndafV4s NEWPASSWORD=yPN4N0fYNKUkOq homectl passwd test-user
67 inspect test-user
68
69 PASSWORD=yPN4N0fYNKUkOq homectl activate test-user
70 inspect test-user
71
72 SYSTEMD_LOG_LEVEL=debug PASSWORD=yPN4N0fYNKUkOq NEWPASSWORD=xEhErW0ndafV4s homectl passwd test-user
73 inspect test-user
74
75 homectl deactivate test-user
76 inspect test-user
77
78 PASSWORD=xEhErW0ndafV4s homectl activate test-user
79 inspect test-user
80
81 homectl deactivate test-user
82 inspect test-user
83
84 PASSWORD=xEhErW0ndafV4s homectl update test-user --real-name="Offline test"
85 inspect test-user
86
87 PASSWORD=xEhErW0ndafV4s homectl activate test-user
88 inspect test-user
89
90 homectl deactivate test-user
91 inspect test-user
92
93 # Do some resize tests, but only if we run on real kernels, as quota inside of containers will fail
94 if ! systemd-detect-virt -cq ; then
95 # grow while inactive
96 PASSWORD=xEhErW0ndafV4s homectl resize test-user 300M
97 inspect test-user
98
99 # minimize while inactive
100 PASSWORD=xEhErW0ndafV4s homectl resize test-user min
101 inspect test-user
102
103 PASSWORD=xEhErW0ndafV4s homectl activate test-user
104 inspect test-user
105
106 # grow while active
107 PASSWORD=xEhErW0ndafV4s homectl resize test-user max
108 inspect test-user
109
110 # minimize while active
111 PASSWORD=xEhErW0ndafV4s homectl resize test-user 0
112 inspect test-user
113
114 # grow while active
115 PASSWORD=xEhErW0ndafV4s homectl resize test-user 300M
116 inspect test-user
117
118 # shrink to original size while active
119 PASSWORD=xEhErW0ndafV4s homectl resize test-user 256M
120 inspect test-user
121
122 # minimize again
123 PASSWORD=xEhErW0ndafV4s homectl resize test-user min
124 inspect test-user
125
126 # Increase space, so that we can reasonably rebalance free space between to home dirs
127 mount /home -o remount,size=800M
128
129 # create second user
130 NEWPASSWORD=uuXoo8ei homectl create test-user2 \
131 --disk-size=min \
132 --luks-discard=yes \
133 --image-path=/home/test-user2.home \
134 --luks-pbkdf-type=pbkdf2 \
135 --luks-pbkdf-time-cost=1ms
136 inspect test-user2
137
138 # activate second user
139 PASSWORD=uuXoo8ei homectl activate test-user2
140 inspect test-user2
141
142 # set second user's rebalance weight to 100
143 PASSWORD=uuXoo8ei homectl update test-user2 --rebalance-weight=100
144 inspect test-user2
145
146 # set first user's rebalance weight to quarter of that of the second
147 PASSWORD=xEhErW0ndafV4s homectl update test-user --rebalance-weight=25
148 inspect test-user
149
150 # synchronously rebalance
151 homectl rebalance
152 inspect test-user
153 inspect test-user2
154 fi
155
156 PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz
157 PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \
158 && { echo 'unexpected success'; exit 1; }
159 PASSWORD=xEhErW0ndafV4s homectl with test-user -- touch /home/test-user/xyz
160 PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz
161 PASSWORD=xEhErW0ndafV4s homectl with test-user -- rm /home/test-user/xyz
162 PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz
163 PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \
164 && { echo 'unexpected success'; exit 1; }
165
166 wait_for_state test-user inactive
167 homectl remove test-user
168
169 if ! systemd-detect-virt -cq ; then
170 wait_for_state test-user2 active
171 homectl deactivate test-user2
172 wait_for_state test-user2 inactive
173 homectl remove test-user2
174 fi
175
176 systemd-analyze log-level info
177
178 echo OK >/testok
179
180 exit 0