oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package render
2
3import (
4 "encoding/json"
5 "os"
6 "slices"
7 "strings"
8 "testing"
9
10 "amadan.net/oficina/equipo/internal/testci"
11)
12
13// The resolver rule is the one the spec asks for, in one place: every
14// host but the site server's own address is not found.
15func TestHostResolverRules(t *testing.T) {
16 if HostResolverRules != "MAP * ~NOTFOUND, EXCLUDE 127.0.0.1" {
17 t.Fatalf("rules %q", HostResolverRules)
18 }
19 if !slices.Contains(browserArgs(), "--host-resolver-rules="+HostResolverRules) {
20 t.Fatalf("browser args %q lack the resolver rules", browserArgs())
21 }
22}
23
24// The browser is driven over its pipe, never a port, and its own sandbox
25// is never turned off.
26func TestBrowserArgsKeepTheSandbox(t *testing.T) {
27 args := browserArgs()
28 if !slices.Contains(args, "--remote-debugging-pipe") {
29 t.Fatalf("args %q", args)
30 }
31 for _, a := range args {
32 if forbiddenBrowserFlag(a) {
33 t.Errorf("browser flag %q", a)
34 }
35 }
36}
37
38// forbiddenBrowserFlag is a flag that would weaken the browser's sandbox
39// or open another way in.
40func forbiddenBrowserFlag(a string) bool {
41 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"} {
42 if a == f || strings.HasPrefix(a, f+"=") {
43 return true
44 }
45 }
46 return false
47}
48
49// BrowserPath is the pinned tree's program, seen at the root.
50func TestBrowserPathIsThePinnedProgram(t *testing.T) {
51 testci.Files(t, "../../release/renderer.json")
52 raw, err := os.ReadFile("../../release/renderer.json")
53 if err != nil {
54 t.Fatal(err)
55 }
56 var pin struct {
57 Program string `json:"program"`
58 }
59 if err = json.Unmarshal(raw, &pin); err != nil {
60 t.Fatal(err)
61 }
62 if "/"+pin.Program != BrowserPath {
63 t.Fatalf("renderer.json program %q, BrowserPath %q", pin.Program, BrowserPath)
64 }
65}
66