protect/protect_linux_ro_dir_test.go

49 lines
933 B
Go
Raw Normal View History

package protect
import (
"os"
2023-03-21 07:22:37 -06:00
"path"
"runtime"
"testing"
)
func TestLandlockFileWrite(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Not running on Linux... skipping landlock test")
}
2023-03-21 07:22:37 -06:00
dir, err := os.MkdirTemp("", "landlock")
if err != nil {
t.Fatal(err)
}
2023-03-21 07:22:37 -06:00
defer os.RemoveAll(dir)
2023-03-21 07:22:37 -06:00
unveil(dir, "r")
err = unveilBlock()
if err != nil {
t.Fatal(err)
}
2023-03-21 07:22:37 -06:00
f, err := os.OpenFile(path.Join(dir, "deadbeef"), os.O_RDWR|os.O_CREATE, 0600)
if err == nil {
t.Fatalf("should not have been able to create %q, but was able to do so\n", f.Name())
}
}
func TestLandlockRO(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Not running on Linux... skipping landlock test")
}
unveil("/tmp", "r")
err := unveilBlock()
if err != nil {
t.Fatal(err)
}
f, err := os.CreateTemp("", "landlockTest")
if err == nil {
t.Fatalf("should not have been able to create %q, but was able to do so\n", f.Name())
}
}