| 1 | package thin |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "runtime" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | "time" |
| 9 | |
| 10 | "amadan.net/oficina/equipo/internal/toolproxy" |
| 11 | ) |
| 12 | |
| 13 | // The Linux tool proxy still speaks the recorded transcript, so the |
| 14 | // oracle the Mac endpoint is held to is what Linux does today. With |
| 15 | // EQUIPO_RECORD_TOOL_TRANSCRIPT=1 it records the transcript again, with |
| 16 | // today's date and this machine in its header. |
| 17 | func TestLinuxToolProxyTranscript(t *testing.T) { |
| 18 | got := playTranscript(t, toolproxy.Serve) |
| 19 | if os.Getenv("EQUIPO_RECORD_TOOL_TRANSCRIPT") == "1" { |
| 20 | host, err := os.Hostname() |
| 21 | if err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | header := "# The tool proxy transcript: what a CLI sends through a tool proxy to a\n" + |
| 25 | "# step's tool socket (>) and each reply (<), one tool socket per session.\n" + |
| 26 | "# Recorded " + time.Now().UTC().Format("2006-01-02") + " on " + strings.ToLower(host) + " (" + runtime.GOOS + "/" + runtime.GOARCH + ") from the Linux tool proxy\n" + |
| 27 | "# (internal/toolproxy.Serve) by TestLinuxToolProxyTranscript, and the\n" + |
| 28 | "# oracle for TestDarwinToolProxySpeaksTheProtocol. Record it again with\n" + |
| 29 | "# EQUIPO_RECORD_TOOL_TRANSCRIPT=1 go test ./internal/runner/thin -run TestLinuxToolProxyTranscript\n" |
| 30 | if err := os.WriteFile(transcriptFile, []byte(header+got), 0644); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | } |
| 34 | _, want := readTranscript(t) |
| 35 | sameTranscript(t, got, want) |
| 36 | // The oracle holds both answers: a permission allowed and one denied. |
| 37 | if !strings.Contains(want, `\"behavior\":\"allow\"`) || !strings.Contains(want, `\"behavior\":\"deny\"`) { |
| 38 | t.Fatal("the transcript records no allowed and denied permission") |
| 39 | } |
| 40 | } |
| 41 | |