test: build test program in nixos config
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
72c59f9229
commit
8b62e08b44
@ -5,7 +5,38 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
testCases = import ./sandbox/case pkgs config.environment.fortify.package.version;
|
testProgram =
|
||||||
|
let
|
||||||
|
inherit (pkgs)
|
||||||
|
buildGoModule
|
||||||
|
pkg-config
|
||||||
|
util-linux
|
||||||
|
;
|
||||||
|
in
|
||||||
|
buildGoModule rec {
|
||||||
|
pname = "check-sandbox";
|
||||||
|
inherit (config.environment.fortify.package) version;
|
||||||
|
|
||||||
|
src = builtins.path {
|
||||||
|
name = "${pname}-src";
|
||||||
|
path = lib.cleanSource ./.;
|
||||||
|
filter = path: type: (type == "directory" && lib.hasSuffix "sandbox" path) || (type == "regular" && lib.hasSuffix ".go" path);
|
||||||
|
};
|
||||||
|
vendorHash = null;
|
||||||
|
|
||||||
|
buildInputs = [ util-linux ];
|
||||||
|
nativeBuildInputs = [ pkg-config ];
|
||||||
|
|
||||||
|
preBuild = ''
|
||||||
|
go mod init git.gensokyo.uk/security/fortify/test >& /dev/null
|
||||||
|
'';
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
mv $out/bin/test $out/bin/fortify-test
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
testCases = import ./sandbox/case lib testProgram;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
users.users = {
|
users.users = {
|
||||||
@ -42,7 +73,7 @@ in
|
|||||||
mako
|
mako
|
||||||
|
|
||||||
# For checking seccomp outcome:
|
# For checking seccomp outcome:
|
||||||
testCases._testProgram
|
testProgram
|
||||||
];
|
];
|
||||||
|
|
||||||
variables = {
|
variables = {
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
pkgs: version:
|
lib: testProgram:
|
||||||
let
|
let
|
||||||
inherit (pkgs)
|
|
||||||
lib
|
|
||||||
writeText
|
|
||||||
buildGoModule
|
|
||||||
pkg-config
|
|
||||||
util-linux
|
|
||||||
foot
|
|
||||||
;
|
|
||||||
|
|
||||||
fs = mode: dir: data: {
|
fs = mode: dir: data: {
|
||||||
mode = lib.fromHexString mode;
|
mode = lib.fromHexString mode;
|
||||||
inherit
|
inherit
|
||||||
@ -32,26 +23,6 @@ let
|
|||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
checkSandbox = buildGoModule {
|
|
||||||
pname = "check-sandbox";
|
|
||||||
inherit version;
|
|
||||||
|
|
||||||
src = ../../.;
|
|
||||||
vendorHash = null;
|
|
||||||
|
|
||||||
buildInputs = [ util-linux ];
|
|
||||||
nativeBuildInputs = [ pkg-config ];
|
|
||||||
|
|
||||||
preBuild = ''
|
|
||||||
go mod init git.gensokyo.uk/security/fortify/test >& /dev/null
|
|
||||||
cp ${./main.go} main.go
|
|
||||||
'';
|
|
||||||
|
|
||||||
postInstall = ''
|
|
||||||
mv $out/bin/test $out/bin/fortify-test
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
callTestCase =
|
callTestCase =
|
||||||
path:
|
path:
|
||||||
let
|
let
|
||||||
@ -67,12 +38,12 @@ let
|
|||||||
name = "check-sandbox-${tc.name}";
|
name = "check-sandbox-${tc.name}";
|
||||||
verbose = true;
|
verbose = true;
|
||||||
inherit (tc) tty mapRealUid;
|
inherit (tc) tty mapRealUid;
|
||||||
share = foot;
|
share = testProgram;
|
||||||
packages = [ ];
|
packages = [ ];
|
||||||
path = "${checkSandbox}/bin/fortify-test";
|
path = "${testProgram}/bin/fortify-test";
|
||||||
args = [
|
args = [
|
||||||
"test"
|
"test"
|
||||||
(toString (writeText "fortify-${tc.name}-want.json" (builtins.toJSON tc.want)))
|
(toString (builtins.toFile "fortify-${tc.name}-want.json" (builtins.toJSON tc.want)))
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
@ -80,6 +51,4 @@ in
|
|||||||
preset = callTestCase ./preset.nix;
|
preset = callTestCase ./preset.nix;
|
||||||
tty = callTestCase ./tty.nix;
|
tty = callTestCase ./tty.nix;
|
||||||
mapuid = callTestCase ./mapuid.nix;
|
mapuid = callTestCase ./mapuid.nix;
|
||||||
|
|
||||||
_testProgram = checkSandbox;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user