mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
The seed marks exactly the declared admin-owned applications and clears the rest, and only a SuperAdmin writes or removes a platform row. PlatformBearer refuses act tokens, and a key names an application of its own org only. Strong invitation codes are always compared; weak ones close per org after 100 refusals an hour, at signup and accept, with the plain refusal. Sends are paced per canonical mailbox (3 per org, 20 across orgs a day) under a fixed subject with plain names. A pinned invitation needs a proven code at signup, and the join code has its own wording and is sent from the signing-in platform app's org. Co-authored-by: Hanzo Dev <[email protected]>
48 lines
1.8 KiB
Go
48 lines
1.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package keys
|
|
|
|
// A token minted with a key names the key's application as its client, so a key
|
|
// names an application of its own org only.
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/orm"
|
|
|
|
"github.com/hanzoai/iam/internal/principal"
|
|
"github.com/hanzoai/iam/pkg/schema"
|
|
)
|
|
|
|
func TestKey_namesAnApplicationOfItsOwnOrgOnly(t *testing.T) {
|
|
db := memDB(t)
|
|
for _, a := range []struct{ name, org string }{{"acme-app", "acme"}, {"hanzo-console", "hanzo"}} {
|
|
app := orm.New[schema.Application](db)
|
|
app.Owner, app.Name, app.ClientId, app.Organization = "admin", a.name, a.name, a.org
|
|
app.SetId("admin/" + a.name)
|
|
if err := app.CreateCtx(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
admin := principal.Bind(context.Background(), &principal.Principal{Org: "acme", User: "boss", Admin: true})
|
|
|
|
if _, err := create(db)(admin, &schema.Key{Owner: "acme", Name: "k1", Application: "hanzo-console"}); err == nil {
|
|
t.Fatal("an acme key named hanzo's application")
|
|
}
|
|
if _, err := create(db)(admin, &schema.Key{Owner: "acme", Name: "k2", Application: "nobody"}); err == nil {
|
|
t.Fatal("a key named an application that does not exist")
|
|
}
|
|
if _, err := create(db)(admin, &schema.Key{Owner: "acme", Name: "k3", Application: "acme-app"}); err != nil {
|
|
t.Fatalf("a key naming its own org's application: %v", err)
|
|
}
|
|
if _, err := update(db)(admin, &schema.Key{Owner: "acme", Name: "k3", Application: "hanzo-console"}); err == nil {
|
|
t.Fatal("an update moved a key onto hanzo's application")
|
|
}
|
|
root := principal.Bind(context.Background(), &principal.Principal{Org: "admin", User: "root", Sudo: true})
|
|
if _, err := create(db)(root, &schema.Key{Owner: "acme", Name: "k4", Application: "hanzo-console"}); err != nil {
|
|
t.Fatalf("a SuperAdmin's key: %v", err)
|
|
}
|
|
}
|