oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "amadan.net/oficina/equipo/internal/wire"
5 "strings"
6 "testing"
7 "time"
8)
9
10func TestPreviewWrapperPinsOriginAndSandbox(t *testing.T) {
11 policy, page, err := previewWrapper("https://eq-tk1.dev.example/", false)
12 if err != nil {
13 t.Fatal(err)
14 }
15 if !strings.Contains(policy, "frame-src https://eq-tk1.dev.example;") || !strings.Contains(policy, "default-src 'none'") {
16 t.Fatal(policy)
17 }
18 if !strings.Contains(page, `sandbox="allow-scripts allow-same-origin"`) || strings.Contains(page, "allow-top-navigation") || strings.Contains(page, "allow-popups") {
19 t.Fatal(page)
20 }
21 for _, bad := range []string{"https://evil.test/path", "javascript:alert(1)", "https://good.test/; frame-src *", "https://user@host.test/", "https://*.host.test/"} {
22 if _, _, err := previewWrapper(bad, false); err == nil {
23 t.Fatal("unsafe origin accepted", bad)
24 }
25 }
26}
27
28func TestPreviewLabelsAndRepublish(t *testing.T) {
29 task := wire.Task{ID: "tk1", Stage: wire.StageInReview, Steps: []wire.Step{{Specialist: wire.SpecialistPreview, State: wire.StepDone, Preview: &wire.PreviewResult{Outcome: wire.PreviewDeployed, URL: "https://eq-tk1.dev.example/", App: "eq-tk1"}}}}
30 target, label := previewCard(task, time.Now())
31 if target != "/tasks/tk1/preview" || strings.Contains(label, "https://") || !strings.Contains(label, "eq-tk1.dev.example") {
32 t.Fatalf("preview link %q %q", target, label)
33 }
34 items := timelineOf(task, taskLine{})
35 found := false
36 for _, it := range items {
37 if strings.Contains(it.Markdown, "/tasks/tk1/preview") {
38 found = true
39 if strings.Contains(it.Markdown, "https://") {
40 t.Fatal(it.Markdown)
41 }
42 }
43 }
44 if !found {
45 t.Fatal("preview timeline link missing")
46 }
47 task.Steps[0].State, task.Steps[0].Reason = wire.StepRunning, "preview_header_missing"
48 if target, _ := previewCard(task, time.Now()); target != "" {
49 t.Fatalf("republishing still offers confirmation: %s", target)
50 }
51}
52
53func TestBaseFailureHeadline(t *testing.T) {
54 if got := checksHeadline(wire.ChecksFailed, "base_checks_failed"); got != "The base version's checks failed." {
55 t.Fatal(got)
56 }
57}
58
59func TestDirectionPreviewLabelUsesHost(t *testing.T) {
60 for _, raw := range []string{"https://eq-tk1.dev.example/", "https://tmp-tk1.oncarlos.com/"} {
61 task := wire.Task{ID: "tk1", NeedsYou: wire.NeedsDirection, Direction: &wire.TaskDirection{PreviewURL: raw}}
62 d := decisionOf(task, taskLine{})
63 if d == nil || d.Link != "/tasks/tk1/preview" || strings.Contains(d.LinkLabel, "https://") {
64 t.Fatalf("direction bypass label: %+v", d)
65 }
66 }
67}
68