Files
zeekayandGitHub cbd259f584 feat(landing): brand-neutral landing/dashboard with per-Host branding (#2)
* ci: add id-token: write to caller permissions

Required for hanzoai/.github/.github/workflows/docker-build.yml@main —
without it the workflow_call dies as startup_failure with no jobs
dispatched. Caller permissions are a CEILING.

* go.mod: bump go directive to 1.26.3 (security advisory)

* deps: luxfi/crypto v1.19.0

* deps: luxfi/crypto v1.19.0; refresh stale checksums

* feat(landing): brand-neutral landing/dashboard with per-Host branding

The MPC binary now resolves its visible brand at request time from the
HTTP Host header, so a single image serves mpc.hanzo.ai as "Hanzo MPC",
mpc.lux.network as "Lux MPC", mpc.zoo.network as "Zoo MPC", and every
other host as a generic brand-free "MPC".

What changed:

- New pkg/landing/ subpackage with:
  - brand.go: Brand{} struct + FromHost(host) helper + brandTable map
    keyed on registered domain (hanzo.ai/lux.network/zoo.network).
    Unknown hosts -> zero Brand -> generic page (no brand prefix, no
    "Sign In with X ID" suffix, no IAM redirect).
  - templates.go: html/template-backed landing/dashboard/auth-callback
    HTML. Every visible brand-specific string flows through
    {{.Brand.TitlePrefix}}, {{.Brand.SignInLabel}}, {{.Brand.IAMURL}},
    {{.Brand.DocsURL}}, {{.Brand.SiteURL}}, {{.Brand.GitHubURL}}.
  - landing.go: http.Handler that intercepts GET /, /dashboard,
    /auth/callback and delegates everything else to the next handler.
    Templates parsed once via sync.Once; per-request execution is
    bytes.Buffer-based.
  - brand_test.go: per-Host title/body assertions for hanzo.ai (Hanzo),
    lux.network (Lux), zoo.network (Zoo), and an unknown host
    (generic). Includes a delegation test that ensures unknown paths
    fall through to next.

- cmd/mpcd/main.go: wrap apiServer.Handler() in landing.Handler() so
  the marketing/dashboard pages render brand-aware while the canonical
  /v1/* API surface (signing, keygen, wallets) is unchanged. Same Base
  mount, same SQLite, same MPC backend wire protocol.

- cmd/mpcd/main.go: add the missing HasSigningQuorum(threshold) shim on
  ConsensusPeerRegistry so the build keeps up with the recent luxfi/mpc
  PeerRegistry interface addition (mirrors the consul registry).

No behavioral change to keygen/signing/reshare. /health, /healthz,
/keys, /backup, /keygen on the internal API port (9800) are untouched.

Verified locally:

  $ go test ./pkg/landing/... -v
  === RUN   TestFromHost                          --- PASS
  === RUN   TestBrandHelpers                      --- PASS
  === RUN   TestHandlerPerHostBranding            --- PASS
  === RUN   TestHandlerDelegatesUnknownPaths      --- PASS
  ok      github.com/hanzoai/mpc/pkg/landing

To onboard a new white-label deployment, add one row to brandTable in
pkg/landing/brand.go and point its DNS at the cluster — no code change
beyond that table.

* docker: self-sufficient build (clone luxfi/mpc inside builder)

Restores compatibility with the canonical reusable workflow
`hanzoai/.github/.github/workflows/docker-build.yml@main`, which does
a single `actions/checkout@v4` at the workspace root with
`context: .`. The previous Dockerfile assumed the historical CI did
two checkouts and built from the parent dir.

The replace `github.com/luxfi/mpc => ../../lux/mpc` directive is now
satisfied inside the build by `git clone --depth=1 --branch=...
https://github.com/luxfi/mpc.git` into `/build/lux/mpc`, parallel to
`/build/hanzo/mpc` (the COPY of the build context).

Pin: `LUXFI_MPC_REF=v1.14.4` (latest released tag at time of write,
known to satisfy the PeerRegistry.HasSigningQuorum interface). Override
via `--build-arg LUXFI_MPC_REF=<tag>` when reproducibility matters.
2026-05-15 14:52:23 -07:00

177 lines
4.9 KiB
Go

package landing
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestFromHost(t *testing.T) {
cases := []struct {
host string
wantName string
wantIAM string
}{
{"mpc.hanzo.ai", "Hanzo", "https://hanzo.id"},
{"mpc.hanzo.ai:443", "Hanzo", "https://hanzo.id"},
{"MPC.HANZO.AI", "Hanzo", "https://hanzo.id"},
{"mpc.lux.network", "Lux", "https://id.lux.network"},
{"mpc.zoo.network", "Zoo", "https://zoo.id"},
{"mpc.example.com", "", ""},
{"localhost", "", ""},
{"", "", ""},
}
for _, tc := range cases {
got := FromHost(tc.host)
if got.Name != tc.wantName {
t.Errorf("FromHost(%q).Name = %q, want %q", tc.host, got.Name, tc.wantName)
}
if got.IAMURL != tc.wantIAM {
t.Errorf("FromHost(%q).IAMURL = %q, want %q", tc.host, got.IAMURL, tc.wantIAM)
}
}
}
func TestBrandHelpers(t *testing.T) {
hanzo := Brand{Name: "Hanzo"}
if hanzo.TitlePrefix() != "Hanzo " {
t.Errorf("TitlePrefix branded = %q, want %q", hanzo.TitlePrefix(), "Hanzo ")
}
if hanzo.SignInLabel() != "Sign In with Hanzo ID" {
t.Errorf("SignInLabel branded = %q, want %q", hanzo.SignInLabel(), "Sign In with Hanzo ID")
}
if !hanzo.HasBrand() {
t.Errorf("HasBrand for non-empty Name should be true")
}
none := Brand{}
if none.TitlePrefix() != "" {
t.Errorf("TitlePrefix unbranded = %q, want empty", none.TitlePrefix())
}
if none.SignInLabel() != "Sign In" {
t.Errorf("SignInLabel unbranded = %q, want %q", none.SignInLabel(), "Sign In")
}
if none.HasBrand() {
t.Errorf("HasBrand for empty Name should be false")
}
}
func TestHandlerPerHostBranding(t *testing.T) {
h := Handler(nil)
type want struct {
titleContains string
titleMustNotHave []string
bodyContains []string
bodyMustNotHave []string
}
cases := []struct {
path string
host string
want want
}{
{
path: "/",
host: "mpc.hanzo.ai",
want: want{
titleContains: "Hanzo MPC — Enterprise Digital Asset Infrastructure",
titleMustNotHave: []string{"Lux MPC", "Zoo MPC"},
bodyContains: []string{"Sign In with Hanzo ID", "https://hanzo.id", "docs.hanzo.ai"},
bodyMustNotHave: []string{"Lux MPC", "Sign In with Lux ID", "id.lux.network", "docs.lux.network"},
},
},
{
path: "/",
host: "mpc.lux.network",
want: want{
titleContains: "Lux MPC — Enterprise Digital Asset Infrastructure",
titleMustNotHave: []string{"Hanzo MPC", "Zoo MPC"},
bodyContains: []string{"Sign In with Lux ID", "https://id.lux.network", "docs.lux.network"},
bodyMustNotHave: []string{"Sign In with Hanzo ID", "hanzo.id"},
},
},
{
path: "/",
host: "mpc.zoo.network",
want: want{
titleContains: "Zoo MPC — Enterprise Digital Asset Infrastructure",
titleMustNotHave: []string{"Lux MPC", "Hanzo MPC"},
bodyContains: []string{"Sign In with Zoo ID", "https://zoo.id", "docs.zoo.ngo"},
bodyMustNotHave: []string{"Sign In with Lux ID", "lux.network"},
},
},
{
path: "/",
host: "mpc.example.com",
want: want{
titleContains: "MPC — Enterprise Digital Asset Infrastructure",
titleMustNotHave: []string{"Hanzo MPC", "Lux MPC", "Zoo MPC"},
bodyContains: []string{},
bodyMustNotHave: []string{"Sign In with Hanzo ID", "Sign In with Lux ID", "Sign In with Zoo ID"},
},
},
{
path: "/dashboard",
host: "mpc.hanzo.ai",
want: want{
titleContains: "Hanzo MPC — Dashboard",
bodyContains: []string{"Hanzo MPC Dashboard"},
bodyMustNotHave: []string{"Lux MPC"},
},
},
}
for _, tc := range cases {
req := httptest.NewRequest(http.MethodGet, tc.path, nil)
req.Host = tc.host
w := httptest.NewRecorder()
h.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("%s host=%s: status=%d, want 200", tc.path, tc.host, w.Code)
continue
}
body := w.Body.String()
if !strings.Contains(body, tc.want.titleContains) {
t.Errorf("%s host=%s: title %q not found in body", tc.path, tc.host, tc.want.titleContains)
}
for _, s := range tc.want.titleMustNotHave {
if strings.Contains(body, "<title>"+s) {
t.Errorf("%s host=%s: unexpected title %q in body", tc.path, tc.host, s)
}
}
for _, s := range tc.want.bodyContains {
if !strings.Contains(body, s) {
t.Errorf("%s host=%s: missing %q in body", tc.path, tc.host, s)
}
}
for _, s := range tc.want.bodyMustNotHave {
if strings.Contains(body, s) {
t.Errorf("%s host=%s: forbidden %q present in body", tc.path, tc.host, s)
}
}
}
}
func TestHandlerDelegatesUnknownPaths(t *testing.T) {
called := false
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called = true
w.WriteHeader(http.StatusTeapot)
})
h := Handler(next)
req := httptest.NewRequest(http.MethodGet, "/v1/wallets", nil)
req.Host = "mpc.hanzo.ai"
w := httptest.NewRecorder()
h.ServeHTTP(w, req)
if !called {
t.Fatalf("next handler not called for /v1/wallets")
}
if w.Code != http.StatusTeapot {
t.Errorf("status=%d, want 418 (delegated)", w.Code)
}
}