fix(membership): register directory route as /directory, not /api/directory
Caddy strips /api via `handle_path /api/*` before forwarding to membershipd, so the SPA's GET /api/directory arrives as GET /directory. The route was registered with the /api prefix, so the stripped request hit no route and returned 404 in production: the directory never resolved and uniweb fell back to short ids. Every other control-plane route is registered without the prefix; this aligns directory with them. The unit test passed despite the bug because it requested /api/directory, the same wrong path as the registration. Corrected the request paths to /directory so the test now exercises the real production path (verified: reverting the registration to /api/directory now makes TestDirectoryGolden fail with 404). Bump 0.15.0 -> 0.15.1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,10 +13,12 @@ import (
|
||||
"github.com/enmanuel/unibus/pkg/frame"
|
||||
)
|
||||
|
||||
// directory signs a GET /api/directory as id and decodes the response envelope.
|
||||
// directory signs a GET /directory as id and decodes the response envelope. The
|
||||
// path has no /api prefix: Caddy strips /api before forwarding to membershipd, so
|
||||
// the route is registered (and hit here) as /directory, matching production.
|
||||
func directory(t *testing.T, h *authHarness, id cs.Identity, n int) (int, directoryResp) {
|
||||
t.Helper()
|
||||
code, body := signedJSON(t, h, "GET", "/api/directory", nil, id, n)
|
||||
code, body := signedJSON(t, h, "GET", "/directory", nil, id, n)
|
||||
var resp directoryResp
|
||||
if code == http.StatusOK {
|
||||
if err := json.Unmarshal([]byte(body), &resp); err != nil {
|
||||
@@ -78,11 +80,11 @@ func TestDirectoryGolden(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestDirectoryUnauthenticatedRejected is the auth contract: under enforce an
|
||||
// unsigned GET /api/directory is rejected with 401 by the middleware, before the
|
||||
// unsigned GET /directory is rejected with 401 by the middleware, before the
|
||||
// handler ever runs — the directory is not public.
|
||||
func TestDirectoryUnauthenticatedRejected(t *testing.T) {
|
||||
h := newAuthHarness(t, AuthEnforce)
|
||||
req, _ := http.NewRequest("GET", h.ts.URL+"/api/directory", nil)
|
||||
req, _ := http.NewRequest("GET", h.ts.URL+"/directory", nil)
|
||||
code, _ := do(t, req)
|
||||
if code != http.StatusUnauthorized {
|
||||
t.Fatalf("unsigned directory request under enforce should be 401, got %d", code)
|
||||
|
||||
Reference in New Issue
Block a user