mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
A shared application with signup open admitted any existing org a signup named. The tenant gate read ServesAnyOrg, which a shared application passes, so an unauthenticated POST naming acme made the caller a member of acme, and TestSignup_sharedApp_admitsLegitimateTenant asserted that it should. Shared means an application serves many orgs at sign-in, where the person already belongs to one. At signup nobody belongs anywhere yet. A signup now lands in one of three places. It can found an org of its own at an application that founds one for each account. It can join the application's own org when the application serves no other. Or it can join an org whose admin invited it. oidc.Registers states the first two, and the password, provider and wallet doors all ask it, so a shared application that founds nothing no longer files strangers in the operator's org through any of them. The third needed an invitation that something redeems. /v1/iam/invitations has always stored rows, owned by the org and written only for its admin, but no code read them. Signup now takes invitationCode. It finds the named org's invitation that admits the signup: active, a seat left, this application or none, the code (a literal compared in constant time, or a whole-match pattern), and any pinned username, address or number. It spends one seat under a row lock after the address code and before the account exists. An invited account stays in the org it joined, even at a founding application, and records the invitation it came by. A code that redeems nothing is refused rather than read as no code. Every refusal is the one tenant sentence, so a prober learns neither which orgs stand nor which codes exist. The two tests that enshrined the hole now assert refusal. New tests cover each path in, each door's shared case, and each way an invitation fails. Co-authored-by: Hanzo Dev <[email protected]>
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package wallet
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A shared application serves many orgs, and its own is the operator's. A
|
|
// first-seen wallet there, at an application that founds nothing, would be filed
|
|
// in the operator's tenant from nothing more than a key anyone can generate, so it
|
|
// is refused exactly as a closed signup is, and no account is left behind.
|
|
func TestSharedAppDoesNotFileAWalletInItsOrg(t *testing.T) {
|
|
app, db := newServer(t)
|
|
a := seed(t, db, opts{signup: true, shared: true})
|
|
|
|
code, m := signIn(t, app, a)
|
|
errorIs(t, code, m, "sign up is disabled")
|
|
if u := users(t, db); len(u) != 0 {
|
|
t.Fatalf("users = %+v, want none", u)
|
|
}
|
|
if w := wallets(t, db); len(w) != 0 {
|
|
t.Fatalf("wallets = %+v, want none", w)
|
|
}
|
|
}
|
|
|
|
// The same shared application, declared to found an org for each account, lands
|
|
// the wallet in an org of its own — never the operator's.
|
|
func TestSharedFoundingAppGivesAWalletItsOwnOrg(t *testing.T) {
|
|
app, db := newServer(t)
|
|
a := seed(t, db, opts{signup: true, shared: true, orgChoice: "create"})
|
|
|
|
code, m := signIn(t, app, a)
|
|
got := okData(t, code, m)
|
|
if got == "" || strings.HasPrefix(got, "hanzo/") {
|
|
t.Fatalf("signed in as %q, want an account in an org of its own", got)
|
|
}
|
|
}
|