diff --git a/test/sandbox/assert.go b/test/sandbox/assert.go index 3cf81ff..3a34c73 100644 --- a/test/sandbox/assert.go +++ b/test/sandbox/assert.go @@ -23,6 +23,7 @@ func printf(format string, v ...any) { printfFunc(format, v...) } func fatalf(format string, v ...any) { fatalfFunc(format, v...) } type TestCase struct { + Env []string `json:"env"` FS *FS `json:"fs"` Mount []*MountinfoEntry `json:"mount"` Seccomp bool `json:"seccomp"` @@ -44,6 +45,36 @@ func (t *T) MustCheckFile(wantFilePath, markerPath string) { } func (t *T) MustCheck(want *TestCase) { + if want.Env != nil { + var ( + fail bool + i int + got string + ) + for i, got = range os.Environ() { + if i == len(want.Env) { + fatalf("got more than %d environment variables", len(want.Env)) + } + if got != want.Env[i] { + fail = true + printf("[FAIL] %s", got) + } else { + printf("[ OK ] %s", got) + } + } + + i++ + if i != len(want.Env) { + fatalf("got %d environment variables, want %d", i, len(want.Env)) + } + + if fail { + fatalf("[FAIL] some environment variables did not match") + } + } else { + printf("[SKIP] skipping environ check") + } + if want.FS != nil && t.FS != nil { if err := want.FS.Compare(".", t.FS); err != nil { fatalf("%v", err) diff --git a/test/sandbox/case/mapuid.nix b/test/sandbox/case/mapuid.nix index eb042e8..bf9837d 100644 --- a/test/sandbox/case/mapuid.nix +++ b/test/sandbox/case/mapuid.nix @@ -9,6 +9,19 @@ mapRealUid = true; want = { + env = [ + "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus" + "HOME=/var/lib/fortify/u0/a3" + "PULSE_SERVER=unix:/run/user/1000/pulse/native" + "SHELL=/run/current-system/sw/bin/bash" + "TERM=linux" + "USER=u0_a3" + "WAYLAND_DISPLAY=wayland-0" + "XDG_RUNTIME_DIR=/run/user/1000" + "XDG_SESSION_CLASS=user" + "XDG_SESSION_TYPE=tty" + ]; + fs = fs "dead" { ".fortify" = fs "800001ed" { etc = fs "800001ed" null null; diff --git a/test/sandbox/case/preset.nix b/test/sandbox/case/preset.nix index b31ec3d..cedd9d7 100644 --- a/test/sandbox/case/preset.nix +++ b/test/sandbox/case/preset.nix @@ -9,6 +9,19 @@ mapRealUid = false; want = { + env = [ + "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/65534/bus" + "HOME=/var/lib/fortify/u0/a1" + "PULSE_SERVER=unix:/run/user/65534/pulse/native" + "SHELL=/run/current-system/sw/bin/bash" + "TERM=linux" + "USER=u0_a1" + "WAYLAND_DISPLAY=wayland-0" + "XDG_RUNTIME_DIR=/run/user/65534" + "XDG_SESSION_CLASS=user" + "XDG_SESSION_TYPE=tty" + ]; + fs = fs "dead" { ".fortify" = fs "800001ed" { etc = fs "800001ed" null null; diff --git a/test/sandbox/case/tty.nix b/test/sandbox/case/tty.nix index 2a3de55..f295b92 100644 --- a/test/sandbox/case/tty.nix +++ b/test/sandbox/case/tty.nix @@ -9,6 +9,19 @@ mapRealUid = false; want = { + env = [ + "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/65534/bus" + "HOME=/var/lib/fortify/u0/a2" + "PULSE_SERVER=unix:/run/user/65534/pulse/native" + "SHELL=/run/current-system/sw/bin/bash" + "TERM=linux" + "USER=u0_a2" + "WAYLAND_DISPLAY=wayland-0" + "XDG_RUNTIME_DIR=/run/user/65534" + "XDG_SESSION_CLASS=user" + "XDG_SESSION_TYPE=tty" + ]; + fs = fs "dead" { ".fortify" = fs "800001ed" { etc = fs "800001ed" null null;