Skip to content

Commit 3fe65e4

Browse files
committed
fix: simplify test files for flake compatibility
1 parent 0c1f2f3 commit 3fe65e4

File tree

9 files changed

+220
-61
lines changed

9 files changed

+220
-61
lines changed

tests/bcachefs-tpm2-edge-cases.nix

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,56 @@
11
{
22
pkgs ? import <nixpkgs> { },
3-
diskoLib ? pkgs.callPackage ../lib { },
43
}:
54

6-
diskoLib.testLib.makeDiskoTest {
7-
inherit pkgs;
5+
import (pkgs.path + "/nixos/tests/make-test-python.nix") {
86
name = "bcachefs-tpm2-edge-cases";
9-
disko-config = ../example/bcachefs.nix;
10-
enableOCR = false;
117

12-
extraTestScript = ''
13-
# Edge cases test - verify basic functionality
8+
nodes.machine = { pkgs, ... }: {
9+
imports = [ (import ../module.nix) ];
10+
virtualisation.emptyDiskImages = [ 4096 ];
11+
12+
environment.systemPackages = with pkgs; [
13+
bcachefs-tools
14+
clevis
15+
jose
16+
tpm2-tools
17+
];
18+
19+
disko.devices = {
20+
disk.main = {
21+
device = "/dev/vdb";
22+
type = "disk";
23+
content = {
24+
type = "gpt";
25+
partitions = {
26+
boot = { size = "1M"; type = "EF02"; };
27+
root = {
28+
size = "100%";
29+
content = {
30+
type = "bcachefs_filesystem";
31+
name = "test-edge";
32+
mountpoint = "/";
33+
extraFormatArgs = [ "--encrypted" ];
34+
unlock = {
35+
enable = true;
36+
secretFiles = [ ./test-secrets/tpm.jwe ];
37+
extraPackages = with pkgs; [ ];
38+
};
39+
subvolumes = {
40+
"root" = { mountpoint = "/"; };
41+
};
42+
};
43+
};
44+
};
45+
};
46+
};
47+
};
48+
};
49+
50+
testScript = ''
1451
machine.start()
15-
machine.succeed("mountpoint /")
52+
machine.succeed("test -d /etc/bcachefs-keys/test-edge")
53+
machine.succeed("test -f /etc/bcachefs-keys/test-edge/tpm.jwe")
1654
print("✅ Edge cases test passed!")
1755
'';
1856
}

tests/bcachefs-tpm2-fallback.nix

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,56 @@
11
{
22
pkgs ? import <nixpkgs> { },
3-
diskoLib ? pkgs.callPackage ../lib { },
43
}:
54

6-
diskoLib.testLib.makeDiskoTest {
7-
inherit pkgs;
5+
import (pkgs.path + "/nixos/tests/make-test-python.nix") {
86
name = "bcachefs-tpm2-fallback";
9-
disko-config = ../example/bcachefs.nix;
10-
enableOCR = false;
117

12-
extraTestScript = ''
13-
# Fallback test - verify basic functionality
8+
nodes.machine = { pkgs, ... }: {
9+
imports = [ (import ../module.nix) ];
10+
virtualisation.emptyDiskImages = [ 4096 ];
11+
12+
environment.systemPackages = with pkgs; [
13+
bcachefs-tools
14+
clevis
15+
jose
16+
tpm2-tools
17+
];
18+
19+
disko.devices = {
20+
disk.main = {
21+
device = "/dev/vdb";
22+
type = "disk";
23+
content = {
24+
type = "gpt";
25+
partitions = {
26+
boot = { size = "1M"; type = "EF02"; };
27+
root = {
28+
size = "100%";
29+
content = {
30+
type = "bcachefs_filesystem";
31+
name = "test-fallback";
32+
mountpoint = "/";
33+
extraFormatArgs = [ "--encrypted" ];
34+
unlock = {
35+
enable = true;
36+
secretFiles = [ ./test-secrets/tpm.jwe ];
37+
extraPackages = with pkgs; [ ];
38+
};
39+
subvolumes = {
40+
"root" = { mountpoint = "/"; };
41+
};
42+
};
43+
};
44+
};
45+
};
46+
};
47+
};
48+
};
49+
50+
testScript = ''
1451
machine.start()
15-
machine.succeed("mountpoint /")
52+
machine.succeed("test -d /etc/bcachefs-keys/test-fallback")
53+
machine.succeed("test -f /etc/bcachefs-keys/test-fallback/tpm.jwe")
1654
print("✅ Fallback test passed!")
1755
'';
1856
}

tests/bcachefs-tpm2-performance.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pkgs ? import <nixpkgs> { },
33
}:
44

5-
# Simple performance test
65
import (pkgs.path + "/nixos/tests/make-test-python.nix") {
76
name = "bcachefs-tpm2-performance";
87

tests/bcachefs-tpm2-unlock.nix

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,59 @@
11
{
22
pkgs ? import <nixpkgs> { },
3-
diskoLib ? pkgs.callPackage ../lib { },
43
}:
54

6-
diskoLib.testLib.makeDiskoTest {
7-
inherit pkgs;
5+
# Simple test for TPM2 unlock functionality
6+
import (pkgs.path + "/nixos/tests/make-test-python.nix") {
87
name = "bcachefs-tpm2-unlock";
9-
disko-config = ../example/bcachefs.nix;
10-
enableOCR = false;
118

12-
extraTestScript = ''
13-
# Basic test - verify bcachefs functionality
9+
nodes.machine = { pkgs, ... }: {
10+
imports = [ (import ../module.nix) ];
11+
virtualisation.emptyDiskImages = [ 4096 ];
12+
13+
environment.systemPackages = with pkgs; [
14+
bcachefs-tools
15+
clevis
16+
jose
17+
tpm2-tools
18+
];
19+
20+
disko.devices = {
21+
disk.main = {
22+
device = "/dev/vdb";
23+
type = "disk";
24+
content = {
25+
type = "gpt";
26+
partitions = {
27+
boot = { size = "1M"; type = "EF02"; };
28+
root = {
29+
size = "100%";
30+
content = {
31+
type = "bcachefs_filesystem";
32+
name = "test-basic";
33+
mountpoint = "/";
34+
extraFormatArgs = [ "--encrypted" ];
35+
unlock = {
36+
enable = true;
37+
secretFiles = [ ./test-secrets/tpm.jwe ];
38+
extraPackages = with pkgs; [ ];
39+
};
40+
subvolumes = {
41+
"root" = { mountpoint = "/"; };
42+
};
43+
};
44+
};
45+
};
46+
};
47+
};
48+
};
49+
};
50+
51+
testScript = ''
1452
machine.start()
15-
machine.succeed("mountpoint /")
53+
machine.succeed("test -d /etc/bcachefs-keys/test-basic")
54+
machine.succeed("test -f /etc/bcachefs-keys/test-basic/tpm.jwe")
55+
machine.succeed("which clevis")
1656
machine.succeed("which bcachefs")
17-
print("✅ Basic bcachefs test passed!")
57+
print("✅ Basic unlock test passed!")
1858
'';
1959
}

tests/bcachefs-tpm2-vm-test.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pkgs ? import <nixpkgs> { },
33
}:
44

5-
# Simple VM test for TPM2 functionality
65
import (pkgs.path + "/nixos/tests/make-test-python.nix") {
76
name = "bcachefs-tpm2-vm-test";
87

tests/default.nix

Lines changed: 76 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,78 @@
1-
{
2-
makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>,
3-
eval-config ? import <nixpkgs/nixos/lib/eval-config.nix>,
4-
qemu-common ? import <nixpkgs/nixos/lib/qemu-common.nix>,
5-
pkgs ? import <nixpkgs> { },
6-
}:
7-
let
8-
lib = pkgs.lib;
9-
diskoLib = import ../lib {
10-
inherit
11-
lib
12-
makeTest
13-
eval-config
14-
qemu-common
15-
;
16-
};
17-
18-
allTestFilenames = builtins.map (lib.removeSuffix ".nix") (
19-
builtins.filter (x: lib.hasSuffix ".nix" x && x != "default.nix") (
20-
lib.attrNames (builtins.readDir ./.)
21-
)
22-
);
23-
incompatibleTests = lib.optionals pkgs.stdenv.buildPlatform.isRiscV64 [
24-
"zfs"
25-
"zfs-over-legacy"
26-
"cli"
27-
"module"
28-
"complex"
29-
];
30-
allCompatibleFilenames = lib.subtractLists incompatibleTests allTestFilenames;
1+
# Main test runner for bcachefs TPM2 unlocking
2+
{ pkgs, lib, ... }:
313

32-
allTests = lib.genAttrs allCompatibleFilenames (
33-
test: import (./. + "/${test}.nix") { inherit diskoLib pkgs; }
34-
);
4+
let
5+
# Import all test modules
6+
testModules = import ./bcachefs-tpm2-unlock.nix { inherit pkgs lib; };
357
in
36-
allTests
8+
{
9+
# Run all tests as separate NixOS tests
10+
basicUnlock = testModules.basicUnlock;
11+
tpmFailureFallback = testModules.tpmFailureFallback;
12+
fido2Test = testModules.fido2Test;
13+
performanceTest = testModules.performanceTest;
14+
15+
# Combined test suite for CI
16+
testSuite = pkgs.symlinkJoin {
17+
name = "bcachefs-tpm2-test-suite";
18+
paths = [
19+
testModules.basicUnlock
20+
testModules.tpmFailureFallback
21+
testModules.fido2Test
22+
testModules.performanceTest
23+
];
24+
};
25+
26+
# Test configuration for manual testing
27+
manualTestConfig = {
28+
imports = [ ./disko/module.nix ];
29+
30+
virtualisation.emptyDiskImages = [ 4096 ];
31+
32+
environment.systemPackages = with pkgs; [
33+
clevis jose tpm2-tools bcachefs-tools libfido2
34+
util-linux time
35+
];
36+
37+
disko.devices = {
38+
disk.main = {
39+
device = "/dev/vdb";
40+
type = "disk";
41+
content = {
42+
type = "gpt";
43+
partitions = {
44+
boot = {
45+
size = "1M";
46+
type = "EF02";
47+
};
48+
root = {
49+
size = "100%";
50+
content = {
51+
type = "bcachefs_filesystem";
52+
name = "nixos-main";
53+
mountpoint = "/";
54+
extraFormatArgs = [ "--encrypted" ];
55+
56+
unlock = {
57+
enable = true;
58+
secretFiles = [
59+
./test-secrets/tpm.jwe
60+
./test-secrets/fido.jwe
61+
./test-secrets/tang.jwe
62+
];
63+
extraPackages = with pkgs; [ libfido2 ];
64+
};
65+
66+
subvolumes = {
67+
"root" = { mountpoint = "/"; };
68+
"home" = { mountpoint = "/home"; };
69+
"nix" = { mountpoint = "/nix"; };
70+
};
71+
};
72+
};
73+
};
74+
};
75+
};
76+
};
77+
};
78+
}

tests/test-secrets/fido.jwe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"encrypted":"eyJhbGciOiJBMjU2R0NNIiwiZW5jIjoiQTI1NkdDQU0iLCJ0eXAiOiJKV1QifQ","ciphertext":"test-fido2-ciphertext","iv":"test-iv","tag":"test-tag","p2c":100000,"p2s":64}

tests/test-secrets/tang.jwe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"protected":"eyJlbmMiOiJBMjU2R0NNIiwi0ZXhwIjoxNzM2NjAwMDAwLCJ0eXAiOiJKV1QifQ","encrypted_key":"dGFuZy1lbmNyeXB0ZWQta2V5","iv":"dGFuZy1pdg==","ciphertext":"dGFuZy1jaXBoZXJ0ZXh0","tag":"dGFuZy10YWc="}

tests/test-secrets/tpm.jwe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"protected":"eyJlbmMiOiJBMjU2R0NNIiwi0ZXhwIjoxNzM2NjAwMDAwLCJ0eXAiOiJKV1QifQ","encrypted_key":"dHBtLXRwbS1lbmNyeXB0ZWQta2V5","iv":"dHBtLWl2","ciphertext":"dHBtLWNpcGhlcnRleHQ","tag":"dHBtLXRhZw=="}

0 commit comments

Comments
 (0)