mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
Prepare decoded each unkeyed row as a whole schema.User, so one row this binary could not decode ("isAdmin":"yes") failed every open. It now reads the stored JSON, decodes only the field the key folds, writes nameKey into the document and nothing else (timestamps included), and skips and logs a row whose name it cannot read. A page of 500 is keyed in one transaction that reads each row again first. The indexes are built before the first query (orm Ready), so an open with nothing to key is one indexed read; when there is something to key the kind is walked once in key order (orm After).
Copy sorted by the document's "id" and resumed from the storage key, which a user's document does not carry, so it failed past one page of 5,000. It walks by storage key now, and its hash leaves out the derived nameKey, so a store keyed and one not yet keyed verify the same.
Co-authored-by: Hanzo Dev <[email protected]>
65 lines
2.4 KiB
Go
65 lines
2.4 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/iam/internal/memberships"
|
|
"github.com/hanzoai/iam/pkg/gone"
|
|
"github.com/hanzoai/iam/server"
|
|
)
|
|
|
|
// A path segment names a THING; the HTTP method says what is being done to it.
|
|
// `POST /v1/iam/send-verification-code` says the verb twice and the noun once.
|
|
//
|
|
// This gate reads the WHOLE router — every route the binary actually answers at,
|
|
// not one package's subtree — and fails on any verb-noun segment that neither the
|
|
// retirement table names nor the short list below freezes.
|
|
//
|
|
// A retired address (internal/gone) is exempt because it is a tombstone, not an
|
|
// API: it answers 410 and names its successor, it touches no store, and it is in
|
|
// no published document, SDK or CLI. That table is the ONE list of them; freezing
|
|
// them a second time here would be two lists to keep in agreement.
|
|
//
|
|
// The frozen list only ever shrinks. A new verb-noun address fails here, at the
|
|
// commit that introduces it, instead of surfacing years later as a command name
|
|
// in somebody's terminal.
|
|
func TestNoNewVerbNounAddresses(t *testing.T) {
|
|
frozen := map[string]bool{}
|
|
for _, p := range []string{
|
|
// Revoking a membership. The collection has no spelling for it — a DELETE
|
|
// there would carry the (user, org) pair in a body — so this one has no
|
|
// successor to be retired towards, and is the last verb-noun address the
|
|
// service still serves.
|
|
memberships.PathDelete,
|
|
} {
|
|
frozen[p] = true
|
|
}
|
|
|
|
verbs := map[string]bool{
|
|
"add": true, "get": true, "set": true, "put": true, "delete": true, "update": true,
|
|
"create": true, "remove": true, "list": true, "run": true, "check": true, "send": true,
|
|
"mint": true, "issue": true, "revoke": true, "reset": true, "refresh": true, "sync": true,
|
|
"is": true, "place": true, "pay": true, "commit": true, "query": true, "upload": true,
|
|
"resolve": true, "exit": true, "impersonate": true,
|
|
}
|
|
|
|
db, err := server.OpenSQLite(":memory:")
|
|
if err != nil {
|
|
t.Fatalf("open store: %v", err)
|
|
}
|
|
for _, r := range server.NewApp(db).Fiber().GetRoutes() {
|
|
if frozen[r.Path] || gone.Retired(r.Path) {
|
|
continue
|
|
}
|
|
for _, seg := range strings.Split(r.Path, "/") {
|
|
if head, _, found := strings.Cut(seg, "-"); found && verbs[head] {
|
|
t.Errorf("%s %s: segment %q is a verb-noun — name the thing and let the method say the verb", r.Method, r.Path, seg)
|
|
}
|
|
}
|
|
}
|
|
}
|