package render import ( "encoding/json" "os" "slices" "strings" "testing" "amadan.net/oficina/equipo/internal/testci" ) // The resolver rule is the one the spec asks for, in one place: every // host but the site server's own address is not found. func TestHostResolverRules(t *testing.T) { if HostResolverRules != "MAP * ~NOTFOUND, EXCLUDE 127.0.0.1" { t.Fatalf("rules %q", HostResolverRules) } if !slices.Contains(browserArgs(), "--host-resolver-rules="+HostResolverRules) { t.Fatalf("browser args %q lack the resolver rules", browserArgs()) } } // The browser is driven over its pipe, never a port, and its own sandbox // is never turned off. func TestBrowserArgsKeepTheSandbox(t *testing.T) { args := browserArgs() if !slices.Contains(args, "--remote-debugging-pipe") { t.Fatalf("args %q", args) } for _, a := range args { if forbiddenBrowserFlag(a) { t.Errorf("browser flag %q", a) } } } // forbiddenBrowserFlag is a flag that would weaken the browser's sandbox // or open another way in. func forbiddenBrowserFlag(a string) bool { for _, f := range []string{"--no-sandbox", "--disable-setuid-sandbox", "--no-zygote", "--single-process", "--disable-gpu-sandbox", "--disable-seccomp-filter-sandbox", "--disable-namespace-sandbox", "--remote-debugging-port", "--remote-debugging-address", "--proxy-server", "--proxy-pac-url", "--allow-file-access-from-files"} { if a == f || strings.HasPrefix(a, f+"=") { return true } } return false } // BrowserPath is the pinned tree's program, seen at the root. func TestBrowserPathIsThePinnedProgram(t *testing.T) { testci.Files(t, "../../release/renderer.json") raw, err := os.ReadFile("../../release/renderer.json") if err != nil { t.Fatal(err) } var pin struct { Program string `json:"program"` } if err = json.Unmarshal(raw, &pin); err != nil { t.Fatal(err) } if "/"+pin.Program != BrowserPath { t.Fatalf("renderer.json program %q, BrowserPath %q", pin.Program, BrowserPath) } }