13203c2452
Endpoint card + peers table (truncated pubkeys with full-value title attr, bound peers link to /hosts/<id>); Offsite nav link in all 9 page templates; render tests for endpoint/peers, empty, and not-configured states. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PSK5g6qYLknKj8u3QAFEr6
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package web
|
|
|
|
// Group C — the /offsite registry page renders in all three states (S2 Part 3).
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
|
)
|
|
|
|
func renderOffsite(t *testing.T, s *Server) string {
|
|
t.Helper()
|
|
rr := httptest.NewRecorder()
|
|
s.handleOffsite(rr, httptest.NewRequest(http.MethodGet, "/offsite", nil))
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("offsite render = %d", rr.Code)
|
|
}
|
|
return rr.Body.String()
|
|
}
|
|
|
|
func TestOffsite_NoEndpoint(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
html := renderOffsite(t, s)
|
|
if !strings.Contains(html, "Not configured") {
|
|
t.Errorf("no-endpoint state missing: %s", html[:200])
|
|
}
|
|
if !strings.Contains(html, "No WireGuard peers registered") {
|
|
t.Errorf("empty-peers state missing")
|
|
}
|
|
}
|
|
|
|
func TestOffsite_EndpointAndPeers(t *testing.T) {
|
|
s, st := newTestServer(t)
|
|
if err := st.SetWGEndpoint(&store.WGEndpoint{
|
|
DNSName: "ep0.felhom.eu", WGPort: 443,
|
|
ServerPubkey: "CQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQk=",
|
|
TunnelSubnet: "10.77.0.0/24", PBSTunnelIP: "10.77.0.1",
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st.UpsertHost(&store.Host{HostID: "hv1", CustomerID: "c1", APIKey: "k"})
|
|
if _, _, err := st.RegisterWGPeerForHost("hv1", "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE="); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err := st.AddWGPeer("AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI=", "", "unbound-test"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
html := renderOffsite(t, s)
|
|
for _, want := range []string{
|
|
"ep0.felhom.eu:443", // endpoint card
|
|
"10.77.0.0/24", // subnet
|
|
"10.77.0.1:8007", // PBS tunnel addr
|
|
"10.77.0.2/32", // bound peer ip
|
|
"10.77.0.3/32", // unbound peer ip
|
|
`href="/hosts/hv1"`, // bound peer links to its host
|
|
"unbound-test", // note column
|
|
} {
|
|
if !strings.Contains(html, want) {
|
|
t.Errorf("offsite page missing %q", want)
|
|
}
|
|
}
|
|
// Unbound peer renders an em-dash host cell, not a broken link.
|
|
if strings.Contains(html, `href="/hosts/"`) {
|
|
t.Error("unbound peer rendered an empty host link")
|
|
}
|
|
// Full pubkey rides the title attribute (truncated display).
|
|
if !strings.Contains(html, `title="AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE="`) {
|
|
t.Error("full pubkey missing from title attr")
|
|
}
|
|
}
|