Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081package webui
import ( "reflect" "testing")
// parseServeRoot decides whether --tailnet-https may take tailscale's https// root, so a misread entry would replace someone else's config or publish// albedo through Funnel. test/e2e/web_test.py drives the claim end to end.func TestParseServeRoot(t *testing.T) { const ours = `"albedo.example.ts.net:443":{"Handlers":{"/":{"Proxy":"http://127.0.0.1:4317"}}}` for _, test := range []struct { name string status string want serveRoot }{ {name: "nothing published", status: `{}`, want: serveRoot{}}, {name: "already ours", status: `{"TCP":{"443":{"HTTPS":true}},"Web":{` + ours + `}}`, want: serveRoot{ours: "albedo.example.ts.net:443"}}, { name: "ours beside an unknown key", status: `{"Web":{` + ours + `},"SomethingNew":{}}`, want: serveRoot{busy: []string{"SomethingNew", "Web albedo.example.ts.net:443"}}, }, { name: "ours opened to the internet", status: `{"Web":{` + ours + `},"AllowFunnel":{"albedo.example.ts.net:443":true}}`, want: serveRoot{busy: []string{"AllowFunnel albedo.example.ts.net:443", "Web albedo.example.ts.net:443"}}, }, { name: "a port that merely starts the same", status: `{"Web":{"albedo.example.ts.net:443":{"Handlers":{"/":{"Proxy":"http://127.0.0.1:43170"}}}}}`, want: serveRoot{busy: []string{"Web albedo.example.ts.net:443"}}, }, { name: "another port", status: `{"TCP":{"10000":{}},"Web":{"albedo.example.ts.net:8443":{"Handlers":{"/":{"Proxy":"http://127.0.0.1:4317"}}}}}`, want: serveRoot{busy: []string{"TCP 10000", "Web albedo.example.ts.net:8443"}}, }, } { t.Run(test.name, func(t *testing.T) { root, err := parseServeRoot([]byte(test.status), Loopback(4317).String()) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(root, test.want) { t.Errorf("root = %#v, want %#v", root, test.want) } }) } if _, err := parseServeRoot([]byte("No serve config\n"), Loopback(4317).String()); err == nil { t.Error("a text status parsed") }}
// ServeHTTPS must refuse before any serve command when the control server// offers no certificate for the machine (Headscale reports CertDomains null),// and a wildcard covers exactly one label.func TestServeHTTPSNeedsACertificate(t *testing.T) { for _, test := range []struct { name, dnsName, domains string want bool }{ {"exact domain", "Albedo.Example.ts.net.", `["albedo.example.ts.net"]`, true}, {"wildcard domain", "albedo.example.ts.net.", `["*.example.ts.net"]`, true}, {"wildcard covers one label", "a.b.example.ts.net.", `["*.example.ts.net"]`, false}, {"another name", "albedo.example.ts.net.", `["other.example.ts.net"]`, false}, {"no certificates", "albedo.example.ts.net.", `null`, false}, } { t.Run(test.name, func(t *testing.T) { tailnet, ok := parseTailnet([]byte(`{"BackendState":"Running","Self":{"DNSName":"` + test.dnsName + `"},"CertDomains":` + test.domains + `}`)) if !ok { t.Fatal("not a tailnet") } if _, err := tailnet.ServeHTTPS(4317); (err == nil) != test.want { t.Errorf("ServeHTTPS() error = %v, want allowed %t", err, test.want) } }) }}