aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sandbox/case/default.nix
blob: 01395ff037493fd99084c4d76f6e9ca8efe4dda9 (plain)
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
pkgs: version:
let
  inherit (pkgs)
    lib
    writeText
    buildGoModule
    pkg-config
    util-linux
    foot
    ;

  fs = mode: dir: data: {
    mode = lib.fromHexString mode;
    inherit
      dir
      data
      ;
  };

  ignore = "//ignore";

  ent = root: target: vfs_optstr: fstype: source: fs_optstr: {
    id = -1;
    parent = -1;
    inherit
      root
      target
      vfs_optstr
      fstype
      source
      fs_optstr
      ;
  };

  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
      tc = import path {
        inherit
          fs
          ent
          ignore
          ;
      };
    in
    {
      name = "check-sandbox-${tc.name}";
      verbose = true;
      inherit (tc) tty mapRealUid;
      share = foot;
      packages = [ ];
      path = "${checkSandbox}/bin/fortify-test";
      args = [
        "test"
        (toString (writeText "fortify-${tc.name}-want.json" (builtins.toJSON tc.want)))
      ];
    };
in
{
  preset = callTestCase ./preset.nix;
  tty = callTestCase ./tty.nix;
  mapuid = callTestCase ./mapuid.nix;

  _testProgram = checkSandbox;
}