test: build test program in nixos config
All checks were successful
Test / Create distribution (push) Successful in 26s
Test / Fpkg (push) Successful in 34s
Test / Data race detector (push) Successful in 3m18s
Test / Fortify (push) Successful in 1m53s
Test / Flake checks (push) Successful in 57s

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-03-29 19:33:17 +09:00
parent 72c59f9229
commit 8b62e08b44
3 changed files with 37 additions and 37 deletions

View File

@@ -1,14 +1,5 @@
pkgs: version:
lib: testProgram:
let
inherit (pkgs)
lib
writeText
buildGoModule
pkg-config
util-linux
foot
;
fs = mode: dir: data: {
mode = lib.fromHexString mode;
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 =
path:
let
@@ -67,12 +38,12 @@ let
name = "check-sandbox-${tc.name}";
verbose = true;
inherit (tc) tty mapRealUid;
share = foot;
share = testProgram;
packages = [ ];
path = "${checkSandbox}/bin/fortify-test";
path = "${testProgram}/bin/fortify-test";
args = [
"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
@@ -80,6 +51,4 @@ in
preset = callTestCase ./preset.nix;
tty = callTestCase ./tty.nix;
mapuid = callTestCase ./mapuid.nix;
_testProgram = checkSandbox;
}

View File

@@ -1,39 +0,0 @@
package main
import (
"log"
"os"
"strconv"
"strings"
"git.gensokyo.uk/security/fortify/test/sandbox"
)
func main() {
log.SetFlags(0)
log.SetPrefix("test: ")
if len(os.Args) < 2 {
log.Fatal("invalid argument")
}
switch os.Args[1] {
case "filter":
if len(os.Args) != 4 {
log.Fatal("invalid argument")
}
if pid, err := strconv.Atoi(strings.TrimSpace(os.Args[2])); err != nil {
log.Fatalf("%s", err)
} else if pid < 1 {
log.Fatalf("%d out of range", pid)
} else {
sandbox.MustCheckFilter(pid, os.Args[3])
return
}
default:
(&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(os.Args[1], "/tmp/sandbox-ok")
return
}
}