mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-21 02:59:42 +00:00
Comments and published descriptions here explained several controls by
recounting the state of the service before them — a date, the credential
involved, the tenants probed, the record counts returned, the endpoint that
answered ok when nothing was sent, the named app that shipped broken. A reader
who wants to know what the code does has to reconstruct it from that; a reader
who wants somewhere to push learns where. This repository is public, and several
of these were served as API documentation: the OpenAPI description, the MCP tool
list and every generated client and CLI carried them.
Each now states the property the control holds, which is the durable half and
the half a reader needs. Genuine design rationale ("it used to do X, now Y")
stays where it carries no incident specifics. Source comments and generated docs
only; the executable tree is untouched.
zipdoc is regenerated from the corrected sources. internal/mfa carried a
committed zipdoc_gen.go but no //go:generate directive, so the check loop skipped
it and its published MFA-enable description would have drifted unseen; the
directive is added here, alongside the mfa comment fix it belongs with, so the
package is regenerated and checked like every other.
Covers the reads and writes whose comments recounted an incident: the
organization listing and its agent-door reach, ScopeRead's membership clause, the
entity-noun fold, the token endpoint's one named error, refresh and revoke for a
public client, wallet and signup tenant isolation, the seed reconcile and its
passkey convergence, the per-org OIDC callback, the machine-bearer principal, the
update-application secret preserve, the one-key-per-member mint, the MFA enable
gate, the passkey list scope, both logout routes, the service-account credential
home, the new-application signing cert, and the no-org-choice tenant confinement.
Co-authored-by: Hanzo Dev <[email protected]>
59 lines
2.3 KiB
Go
59 lines
2.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package schema
|
|
|
|
import "testing"
|
|
|
|
// ServesAnyOrg is tenant isolation's ONE exemption, so the table is exhaustive
|
|
// over the vocabulary rather than over the cases someone remembered.
|
|
//
|
|
// "None" is the case that matters and the reason this file exists: it is the
|
|
// admin console's spelling of "offer no org picker", identical in meaning to the
|
|
// empty string a never-edited application carries. Four hand-written copies of
|
|
// this rule all tested `OrgChoiceMode == ""`, so an application carrying the
|
|
// canonical value read as UNCONFINED and accepted a session from any org.
|
|
func TestServesAnyOrg(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
app Application
|
|
expect bool
|
|
}{
|
|
// Confined: no picker offered, whichever way that is spelled.
|
|
{"unset", Application{}, false},
|
|
{"none", Application{OrgChoiceMode: "None"}, false},
|
|
|
|
// Unconfined: the app genuinely lets a user name an org.
|
|
{"select", Application{OrgChoiceMode: "Select"}, true},
|
|
{"input", Application{OrgChoiceMode: "Input"}, true},
|
|
{"create", Application{OrgChoiceMode: "create"}, true},
|
|
|
|
// Shared is an explicit, deliberate flag and stands alone.
|
|
{"shared", Application{IsShared: true}, true},
|
|
{"shared and none", Application{IsShared: true, OrgChoiceMode: "None"}, true},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := tc.app.ServesAnyOrg(); got != tc.expect {
|
|
t.Fatalf("ServesAnyOrg() = %v, want %v (isShared=%v orgChoiceMode=%q)",
|
|
got, tc.expect, tc.app.IsShared, tc.app.OrgChoiceMode)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// An application offering no org choice ("None") must stay confined to its OWN
|
|
// org: a session belonging to another org must not mint a code against it.
|
|
// ServesAnyOrg is what the callers read, so it is tested the way they read it.
|
|
func TestNoneConfinesToItsOwnOrg(t *testing.T) {
|
|
zooConsole := &Application{Organization: "zoo", OrgChoiceMode: "None"}
|
|
|
|
if zooConsole.ServesAnyOrg() {
|
|
t.Fatal(`an application offering no org choice must stay confined to its own org`)
|
|
}
|
|
// Spelled as mint/token/signup spell it, so this fails if the callers' shape
|
|
// drifts away from the predicate.
|
|
if foreign := "hanzo"; !(foreign != zooConsole.Organization && !zooConsole.ServesAnyOrg()) {
|
|
t.Fatal("a foreign-org principal must be refused by an unconfigured app")
|
|
}
|
|
}
|