Skip to content

Commit 9be30fd

Browse files
authored
Merge pull request #134 from ifd3f/improve-checks
Improve existing checks and add a lot more
2 parents 413422c + 664fd4f commit 9be30fd

File tree

5 files changed

+112
-20
lines changed

5 files changed

+112
-20
lines changed

checks/autoescalate/default.nix

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ nixosTest {
3535
};
3636

3737
testScript = ''
38-
# Set up loop devices
39-
machine.succeed('dd if=/dev/zero of=/tmp/blockfile bs=1M count=1')
40-
machine.succeed('dd if=/dev/urandom of=/tmp/input.iso bs=100K count=1')
41-
machine.succeed('losetup /dev/loop0 /tmp/blockfile')
38+
${builtins.readFile ../common.py}
4239
43-
with subtest("should succeed when run as non-root wheel user"):
44-
machine.succeed('timeout 10 su admin -c "caligula burn /tmp/input.iso --force -o /dev/loop0 --hash skip --compression auto --root always --interactive never"')
40+
try:
41+
# Set up loop devices
42+
machine.succeed('dd if=/dev/zero of=/tmp/blockfile bs=1M count=1')
43+
machine.succeed('dd if=/dev/urandom of=/tmp/input.iso bs=100K count=1')
44+
machine.succeed('losetup /dev/loop0 /tmp/blockfile')
45+
46+
# Sanity check: can we run something without asking for a password?
47+
machine.succeed('timeout 10 su admin -c "${escalationTool} -- echo We are able to escalate without asking for a password"')
48+
49+
with subtest("should succeed when run as non-root wheel user"):
50+
machine.succeed('timeout 10 su admin -c "caligula burn /tmp/input.iso --force -o /dev/loop0 --hash skip --compression auto --root always --interactive never"')
51+
finally:
52+
print_logs(machine)
4553
'';
4654
}

checks/blocksize.nix

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{ lib, nixosTest, imageSize, blockSize, diskSizeMiB }:
2+
let
3+
serial = "awawawawawa";
4+
diskFile = "/tmp/block-file.img";
5+
byDiskPath = "/dev/disk/by-id/usb-QEMU_QEMU_HARDDISK_${serial}-0:0";
6+
in nixosTest {
7+
name = "blocksize-bs${toString blockSize}-image${toString imageSize}-diskMiB${
8+
toString diskSizeMiB
9+
}";
10+
11+
nodes.machine = { pkgs, lib, ... }:
12+
with lib; {
13+
imports = [ ];
14+
15+
users.users = {
16+
admin = {
17+
isNormalUser = true;
18+
extraGroups = [ "wheel" ];
19+
};
20+
};
21+
22+
environment.systemPackages = with pkgs; [ caligula ];
23+
virtualisation.qemu.options =
24+
[ "-drive" "if=none,id=usbstick,format=raw,file=${diskFile}" ]
25+
++ [ "-usb" ] ++ [ "-device" "usb-ehci,id=ehci" ] ++ [
26+
"-device"
27+
"usb-storage,bus=ehci.0,drive=usbstick,serial=${serial},physical_block_size=${
28+
toString blockSize
29+
}"
30+
];
31+
};
32+
33+
testScript = with lib; ''
34+
import os
35+
36+
print("Creating file image at ${diskFile}")
37+
os.system("dd bs=1M count=${
38+
toString diskSizeMiB
39+
} if=/dev/urandom of=${diskFile}")
40+
41+
${readFile ./common.py}
42+
43+
machine.start()
44+
machine.wait_for_unit('default.target')
45+
print(machine.execute('stat $(readlink -f ${byDiskPath})', check_output=True)[1])
46+
try:
47+
machine.succeed('dd if=/dev/urandom of=/tmp/input.iso bs=1 count=${
48+
toString imageSize
49+
}')
50+
with subtest("executes successfully"):
51+
machine.succeed('caligula burn /tmp/input.iso --force -o $(readlink -f ${byDiskPath}) --hash skip --compression auto --interactive never')
52+
53+
with subtest("burns correctly"):
54+
machine.succeed('dd if=${byDiskPath} of=/tmp/written.iso bs=1 count=${
55+
toString imageSize
56+
}')
57+
machine.succeed('diff -s /tmp/input.iso /tmp/written.iso')
58+
59+
finally:
60+
print_logs(machine)
61+
'';
62+
}

checks/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def print_logs(machine):
2+
_, output = machine.execute(
3+
'for x in $(find /tmp/caligula-* -type f); do echo "$x"; cat "$x"; echo; done',
4+
check_output=True,
5+
)
6+
print(output)

checks/default.nix

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,34 @@ let
55
inherit system;
66
overlays = [ self.overlays.default ];
77
};
8-
in {
8+
lib = pkgs.lib;
9+
in with lib;
10+
{
911
headless = pkgs.callPackage ./headless { };
1012
smoke-test-simple = pkgs.callPackage ./smoke-test-simple { };
1113
} //
1214

13-
(if system == "x86_64-linux" then {
14-
autoescalate-doas =
15-
pkgs.callPackage ./autoescalate { escalationTool = "doas"; };
16-
autoescalate-sudo =
17-
pkgs.callPackage ./autoescalate { escalationTool = "sudo"; };
18-
} else
15+
(if system == "x86_64-linux" then
16+
{
17+
autoescalate-doas =
18+
pkgs.callPackage ./autoescalate { escalationTool = "doas"; };
19+
autoescalate-sudo =
20+
pkgs.callPackage ./autoescalate { escalationTool = "sudo"; };
21+
} //
22+
23+
# blocksize alignment tests
24+
(let
25+
MiB = 1048576;
26+
parameters = cartesianProduct {
27+
blockSize = [ 512 1024 2048 4096 8192 ];
28+
imageSize = [ (10 * MiB) (10 * MiB + 51) ];
29+
};
30+
in listToAttrs (map ({ imageSize, blockSize }: rec {
31+
name = value.name;
32+
value = pkgs.callPackage ./blocksize.nix {
33+
inherit lib blockSize imageSize;
34+
diskSizeMiB = 64;
35+
};
36+
}) parameters))
37+
else
1938
{ })

checks/headless/default.nix

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{ lib, caligula, runCommand }:
22
runCommand "caligula-headless-test" {
33
buildInputs = [ caligula ];
4-
isoInnerHash = "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986";
4+
isoInnerHash =
5+
"3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986";
56
meta.timeout = 10;
67
} ''
78
caligula burn ${./input.iso.gz} \
@@ -11,11 +12,7 @@ runCommand "caligula-headless-test" {
1112
--hash-of raw \
1213
--compression auto
1314
14-
for x in $(find /tmp/caligula-* -type f); do
15-
echo "$x"
16-
cat "$x"
17-
echo
18-
done
15+
diff ${./expected.iso} ./out.iso
1916
20-
diff ${./expected.iso} ./out.iso && (echo 1 > $out)
17+
echo 1 > $out
2118
''

0 commit comments

Comments
 (0)