Repository navigation
Expand file tree
/
Copy pathrun_integration_tests.sh
More file actions
475 lines (367 loc) · 14.1 KB
/
Copy pathrun_integration_tests.sh
File metadata and controls
475 lines (367 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#!/bin/bash
# run_integration_tests.sh - part of the DebianInstaller project
# Copyright (C) 2026, Scott Wyman, development@scottwyman.me
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
PRETTY_OUTPUT_LIBRARY=./DebianInstaller/pretty_output_library.sh
GLOBAL_PARTITION_VARIABLES_FILE=./DebianInstaller/integration_tests_global_partition_variables
INSTALL_CONSTANTS_FILE=./DebianInstaller/install_constants
BACKUP_INSTALL_CONSTANTS_FILE=./DebianInstaller/install_constants.bak
SAFELY_CLOSE_SYSTEM_SCRIPT=./DebianInstaller/safely_close_system.sh
COMPLETION_FILE=./integration_tests_completion.txt
START_INSTALL_COMPLETION_FILE=./start_install_completion.txt
START_INSTALL_SCRIPT=./DebianInstaller/start_install.sh
if ! source $GLOBAL_PARTITION_VARIABLES_FILE &>/dev/null
then
printf "\n\n\e[31m%s %s\e[0m\n\n" \
"[!] Couldn't source the integration_tests_global_partition_variables" \
"file. Make sure to run \`bash ./DebianInstaller/start_install.sh\`"
exit 1
fi
if ! source $PRETTY_OUTPUT_LIBRARY &>/dev/null
then
printf "\n\n\e[31m%s %s\e[0m\n\n" \
"[!] Couldn't source the pretty output library. Make sure" \
"to run \`bash ./DebianInstaller/start_install.sh\`"
exit 1
fi
STDOUT_LOG_PATH="/tmp/integration_tests_stdout.log"
STDERR_LOG_PATH="/tmp/integration_tests_stderr.log"
check_global_partition_variables()
{
if [[ -n "$DISK" ]]
then
if ! [[ -b "$DISK" ]]
then
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"No disk '$DISK' exists on the system."
return 1
fi
else
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"The '\$DISK' variable must be set in '$GLOBAL_PARTITION_VARIABLES_FILE'"
return 1
fi
if [[ -n "$EFI_PARTITION" ]]
then
if ! [[ -b "$EFI_PARTITION" ]]
then
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"No partition '$EFI_PARTITION' exists on the system."
return 1
fi
else
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"The '\$EFI_PARTITION' variable must be set in '$GLOBAL_PARTITION_VARIABLES_FILE'"
return 1
fi
if [[ -n "$BOOT_PARTITION" ]]
then
if ! [[ -b "$BOOT_PARTITION" ]]
then
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"No partition '$BOOT_PARTITION' exists on the system."
return 1
fi
else
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"The '\$BOOT_PARTITION' variable must be set in '$GLOBAL_PARTITION_VARIABLES_FILE'"
return 1
fi
if [[ -n "$ROOT_PARTITION" ]]
then
if ! [[ -b "$ROOT_PARTITION" ]]
then
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"No partition '$ROOT_PARTITION' exists on the system."
return 1
fi
else
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"The '\$ROOT_PARTITION' variable must be set in '$GLOBAL_PARTITION_VARIABLES_FILE'"
return 1
fi
if [[ -n "$HOME_PARTITION" ]]
then
if ! [[ -b "$HOME_PARTITION" ]]
then
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"No partition '$HOME_PARTITION' exists on the system."
return 1
fi
else
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"The '\$HOME_PARTITION' variable must be set in '$GLOBAL_PARTITION_VARIABLES_FILE'"
return 1
fi
if [[ -n "$LUKS_KEYFILE_PARTITION" ]]
then
if ! [[ -b "$LUKS_KEYFILE_PARTITION" ]]
then
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"No disk '$LUKS_KEYFILE_PARTITION' exists on the system."
return 1
fi
else
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"The '\$LUKS_KEYFILE_PARTITION' variable must be set in '$GLOBAL_PARTITION_VARIABLES_FILE'"
return 1
fi
return 0
}
check_global_partition_variables || exit $?
backup_the_install_constants_file()
{
if ! [[ -f "$BACKUP_INSTALL_CONSTANTS_FILE" ]]
then
cp $INSTALL_CONSTANTS_FILE $BACKUP_INSTALL_CONSTANTS_FILE \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" \
"Backup the original install_constants file"
[[ $? -ne 0 ]] && return 1
fi
return 0
}
pre_test_preparations()
{
bash $SAFELY_CLOSE_SYSTEM_SCRIPT || return 1
cp $BACKUP_INSTALL_CONSTANTS_FILE $INSTALL_CONSTANTS_FILE \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" \
"Restore the original install_contants file from the backup for test"
[[ $? -ne 0 ]] && return 1
if [[ -f "$START_INSTALL_COMPLETION_FILE" ]]
then
rm "$START_INSTALL_COMPLETION_FILE" >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" \
"remove file: $START_INSTALL_COMPLETION_FILE"
[[ $? -ne 0 ]] && return 1
fi
return 0
}
post_test_cleanup()
{
bash $SAFELY_CLOSE_SYSTEM_SCRIPT || return 1
return 0
}
restore_the_install_constants_file()
{
mv $BACKUP_INSTALL_CONSTANTS_FILE $INSTALL_CONSTANTS_FILE \
>>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" \
"Restore the original install_contants file from the backup"
[[ $? -ne 0 ]] && return 1
return 0
}
set_variable() {
local TEST_NAME="$1"
local VARIABLE_NAME="$2"
local VARIABLE_VALUE="${@:3}"
# Thank you chatgpt for: `\(# \?\)\?`
# * In my own words, there are two `\` for escaping `(` and `)`, then the
# `# \?` inside means `#` is mandator and the space after is optional,
# and finally the `\?` outside the `()` means the whole thing is optional
# effectively allow a comment with a space or just a comment before any
# of the variables
if ! grep "^\(# \?\)\?$VARIABLE_NAME=" "$INSTALL_CONSTANTS_FILE" &>/dev/null
then
printf "\n\e[31m%s %s\e[0m\n" "[FATAL ERROR]" \
"Test '$TEST_NAME' failed trying to set non-existant variable '$VARIABLE_NAME'"
# Exception for exiting from function to keep code clean
exit 1
fi
# Thank you Lumo AI for the sed help
#
# LUMO COMMENT: Escape &, backslash, and your comma delimiter
local SAFE_VALUE=$(printf '%s' "$VARIABLE_VALUE" | sed 's/[&\\,]/\\&/g')
sed -i "s,^\(# \?\)\?${VARIABLE_NAME}=.*,${VARIABLE_NAME}=${SAFE_VALUE}," \
"$INSTALL_CONSTANTS_FILE" >>"$STDOUT_LOG_PATH" 2>>"$STDERR_LOG_PATH" &
task_output $! "$STDERR_LOG_PATH" \
"TEST ['$TEST_NAME']: Set $VARIABLE_NAME='$SAFE_VALUE'"
# Exception for exiting from function to keep code clean
[[ $? -ne 0 ]] && exit 1
return 0
}
replace_install_constants_partition_variables()
{
set_variable "set_partitions" "DISK" "$DISK"
set_variable "set_partitions" "EFI_PARTITION" "$EFI_PARTITION"
set_variable "set_partitions" "BOOT_PARTITION" "$BOOT_PARTITION"
set_variable "set_partitions" "ROOT_PARTITION" "$ROOT_PARTITION"
set_variable "set_partitions" "HOME_PARTITION" "$HOME_PARTITION"
return 0
}
introduce_test()
{
local TEST_NAME="$1"
local TEST_DESCRIPTION="${@:2}"
if [[ -z "$TEST_NAME" ]]
then
printf "\n\e[31m%s %s\e[0m\n" "[ERROR]" \
"No test name passed to the introduce_test function. Stopping."
exit 1
fi
printf "\n\n\e[36m%s %s %s \n\n %s\e[0m\n\n" \
"--------" "TEST: $TEST_NAME" "--------" \
"Description: $TEST_DESCRIPTION"
return 0
}
# The create_ function below should only be ran during system creation
# and not during every test run as it installs and configures the full suite
# of packages to setup the system, while all other tests just configure the
# system from these existing packages
create_fresh_luks_system()
{
local TEST_NAME="create_fresh_luks_system"
local TEST_DESCRIPTION="Setup initial system, installing all packages. Luks Encrypted."
if ! grep "^${TEST_NAME}$" $COMPLETION_FILE &>/dev/null
then
introduce_test "$TEST_NAME" "$TEST_DESCRIPTION"
pre_test_preparations
set_variable "$TEST_NAME" "OVERWRITE_HOME_PARTITION" "'y'"
set_variable "$TEST_NAME" "SKIP_INSTALLING_PACKAGES" "'n'"
set_variable "$TEST_NAME" "LUKS_KEYFILE_PARTITION" "''"
set_variable "$TEST_NAME" "LUKS_PASSWORD" "'test'"
set_variable "$TEST_NAME" "USE_KEYFILE_AT_BOOT" "'n'"
bash $START_INSTALL_SCRIPT || return $?
echo "$TEST_NAME" >> $COMPLETION_FILE
post_test_cleanup
fi
return 0
}
# All the tests below are not built to be ran on an unencrypted system, so
# if you need to run this test, run it alone.
create_fresh_no_luks_system()
{
local TEST_NAME="create_fresh_no_luks_system"
local TEST_DESCRIPTION="Setup initial system, installing all packages. No luks."
if ! grep "^${TEST_NAME}$" $COMPLETION_FILE &>/dev/null
then
introduce_test "$TEST_NAME" "$TEST_DESCRIPTION"
pre_test_preparations
set_variable "$TEST_NAME" "OVERWRITE_HOME_PARTITION" "'y'"
set_variable "$TEST_NAME" "SKIP_INSTALLING_PACKAGES" "'n'"
set_variable "$TEST_NAME" "LUKS_KEYFILE_PARTITION" "''"
set_variable "$TEST_NAME" "LUKS_PASSWORD" "''"
set_variable "$TEST_NAME" "USE_KEYFILE_AT_BOOT" "''"
bash $START_INSTALL_SCRIPT || return $?
echo "$TEST_NAME" >> $COMPLETION_FILE
post_test_cleanup
fi
return 0
}
test_1()
{
local TEST_NAME="test_1"
local TEST_DESCRIPTION="Test adding keyfile to existing LUKS system encrypted with password"
if ! grep "^${TEST_NAME}$" $COMPLETION_FILE &>/dev/null
then
introduce_test "$TEST_NAME" "$TEST_DESCRIPTION"
pre_test_preparations
set_variable "$TEST_NAME" "OVERWRITE_HOME_PARTITION" "'n'"
set_variable "$TEST_NAME" "SKIP_INSTALLING_PACKAGES" "'y'"
set_variable "$TEST_NAME" "LUKS_KEYFILE_PARTITION" "'$LUKS_KEYFILE_PARTITION'"
set_variable "$TEST_NAME" "LUKS_PASSWORD" "'test'"
set_variable "$TEST_NAME" "USE_KEYFILE_AT_BOOT" "'y'"
bash $START_INSTALL_SCRIPT || return $?
echo "$TEST_NAME" >> $COMPLETION_FILE
post_test_cleanup
fi
return 0
}
test_2()
{
local TEST_NAME="test_2"
local TEST_DESCRIPTION="Test changing the existing LUKS password using the keyfile"
if ! grep "^${TEST_NAME}$" $COMPLETION_FILE &>/dev/null
then
introduce_test "$TEST_NAME" "$TEST_DESCRIPTION"
pre_test_preparations
set_variable "$TEST_NAME" "OVERWRITE_HOME_PARTITION" "'n'"
set_variable "$TEST_NAME" "SKIP_INSTALLING_PACKAGES" "'y'"
set_variable "$TEST_NAME" "LUKS_KEYFILE_PARTITION" "'$LUKS_KEYFILE_PARTITION'"
set_variable "$TEST_NAME" "LUKS_PASSWORD" "'test2'"
set_variable "$TEST_NAME" "USE_KEYFILE_AT_BOOT" "'n'"
bash $START_INSTALL_SCRIPT || return $?
echo "$TEST_NAME" >> $COMPLETION_FILE
post_test_cleanup
fi
return 0
}
test_3()
{
local TEST_NAME="test_3"
local TEST_DESCRIPTION="Test changing the primary boot method to use keyfile at boot"
if ! grep "^${TEST_NAME}$" $COMPLETION_FILE &>/dev/null
then
introduce_test "$TEST_NAME" "$TEST_DESCRIPTION"
pre_test_preparations
set_variable "$TEST_NAME" "OVERWRITE_HOME_PARTITION" "'n'"
set_variable "$TEST_NAME" "SKIP_INSTALLING_PACKAGES" "'y'"
set_variable "$TEST_NAME" "LUKS_KEYFILE_PARTITION" "'$LUKS_KEYFILE_PARTITION'"
set_variable "$TEST_NAME" "LUKS_PASSWORD" "'test2'"
set_variable "$TEST_NAME" "USE_KEYFILE_AT_BOOT" "'y'"
bash $START_INSTALL_SCRIPT || return $?
echo "$TEST_NAME" >> $COMPLETION_FILE
post_test_cleanup
fi
return 0
}
test_4()
{
local TEST_NAME="test_4"
local TEST_DESCRIPTION="Test replacing the home partition with a raid 1 array"
if ! grep "^${TEST_NAME}$" $COMPLETION_FILE &>/dev/null
then
introduce_test "$TEST_NAME" "$TEST_DESCRIPTION"
pre_test_preparations
set_variable "$TEST_NAME" "OVERWRITE_HOME_PARTITION" "'y'"
set_variable "$TEST_NAME" "SKIP_INSTALLING_PACKAGES" "'n'"
set_variable "$TEST_NAME" "RAID_ARRAY_DEVICE" "'/dev/md0'"
set_variable "$TEST_NAME" "RAID_LEVEL" "'1'"
set_variable "$TEST_NAME" "RAID_PARTITIONS" "(${RAID_PARTITIONS[*]})"
set_variable "$TEST_NAME" "LUKS_KEYFILE_PARTITION" "'$LUKS_KEYFILE_PARTITION'"
set_variable "$TEST_NAME" "LUKS_PASSWORD" "'test4'"
set_variable "$TEST_NAME" "USE_KEYFILE_AT_BOOT" "'y'"
bash $START_INSTALL_SCRIPT || return $?
echo "$TEST_NAME" >> $COMPLETION_FILE
post_test_cleanup
fi
return 0
}
# All tests only change their required variables, meaning they all depend on
# the original install_constants file before running
backup_the_install_constants_file
replace_install_constants_partition_variables
# -- SETUP --
# All tests work on a LUKS encrypted system, despite not LUKS encrypting it
# being an option during real installation... because it's a bit unnecessary
# to retest all the same functionality in a much simpler setup. However I may
# eat those words some day.
create_fresh_luks_system || exit $?
# Tests do not have unique names because it would be a waste of time when you
# can just read the correlating function if one of the tests fail to see exactly
# what it's doing. With so many tests, the names would be crazy long as well.
#
# Test must be ran in order
#
# -- TESTS --
test_1 || exit $?
test_2 || exit $?
test_3 || exit $?
test_4 || exit $?
# -- TESTS FINISHED --
post_test_cleanup
restore_the_install_constants_file
exit 0