Files
iam/server/server_nostore_test.go
zeekay 56a86daf16 a store this host could not open refuses, and does not move the route table
NewApp(nil) used to be undefined behaviour — every handler closed over the nil and
dereferenced it on the first request. So a host with no store could not compose
IAM at all, and cloud expressed that by registering something ELSE: five
`app.All` wildcards answering 503 in place of the App.

That made the published contract depend on the machine. An unmounted volume
replaced 94 typed operations with 15 undescribed catch-alls in cloud's OpenAPI
document, its MCP tool list, every generated SDK and the CLI — one program with
two route tables, chosen at boot by a stat() call, and the degraded one was the
version its own drift gate then refused to describe.

The two facts are different kinds: the route table is fixed by this code, the
store is a property of the machine the code runs on. So a nil store installs a
refusal in FRONT of the routes and nothing else changes. Every address IAM
declares still exists, still documents itself, and answers 503 with a code and a
Retry-After until the store is there — and no handler reaches the nil.

It ANSWERS rather than returning the error for the host to render, because the
host may not render it faithfully: cloud installs an error-flattening filter on
its /v1 group that rewrites any propagated error to 500, which would turn this
503 into an internal error and hide the one fact worth saying.
2026-08-08 04:59:09 -07:00

36 lines
1.3 KiB
Go

package server
import (
"net/http"
"net/http/httptest"
"testing"
)
// A host that could not open a store still serves IAM's whole route table — the
// addresses are what this package declares, and only the ANSWER changes. The
// alternative cloud used to ship registered five wildcards instead, so an unmounted
// volume swapped 94 typed operations for 15 catch-alls in every projection: the
// OpenAPI document, the MCP tool list, the SDKs and the CLI.
func TestNewApp_NilStoreKeepsTheRouteTableAndRefuses(t *testing.T) {
with := NewApp(nil)
if err := with.Build(); err != nil {
t.Fatalf("app with no store does not compose: %v", err)
}
// The document is the same one a live store publishes: same addresses, same count.
live := len(NewApp(nil).Routes())
if live == 0 {
t.Fatal("no routes registered — the nil store took the route table with it")
}
res, err := with.Test(httptest.NewRequest(http.MethodGet, "/v1/iam/.well-known/jwks", nil))
if err != nil {
t.Fatal(err)
}
if res.StatusCode != http.StatusServiceUnavailable {
t.Errorf("status = %d, want 503 — a nil store must refuse, not serve empty keys", res.StatusCode)
}
if got := res.Header.Get("Retry-After"); got == "" {
t.Error("no Retry-After: a missing volume is transient and the caller should be told to come back")
}
}