Files
iam/pkg/schema/orgref_test.go
zeekayandHanzo Dev 084011934f legal: dual MIT OR Apache-2.0, canonical licence text
This repo is public and its LICENSE called the source "confidential and
proprietary ... All rights reserved". Public visibility contradicts
confidentiality, and HIP-0130 puts `iam` in the OSS core tier. The declaration
now matches both.

LICENSE-APACHE and LICENSE-MIT carry the canonical texts, unedited —
LICENSE-APACHE is byte-identical to apache.org/licenses/LICENSE-2.0.txt
(sha256 cfc7749b…, 11358 bytes, blob d645695). LICENSE declares the pair.
LICENSE-MIT carries the copyright line the notice requires.

249 Go files led with `// Copyright 2026 Hanzo AI, Inc. All rights reserved.`
— the classic proprietary reservation, and a per-file contradiction of the new
grant. Each now carries `// SPDX-License-Identifier: MIT OR Apache-2.0`. The
word "confidential" survives untouched in the OIDC sense (confidential client),
which is protocol vocabulary, not a licence claim.

There is nothing else to declare: `go.mod` has no licence field and this repo
ships no Cargo/npm/PyPI manifest.

Relicensing is ours alone to do. The tree is original work, not a fork:
`fork: false` with no parent, its own root commit, and no Casdoor-lineage tag
is an ancestor of `main`. The retired Casdoor fork is `hanzoai/iam-v1`; the
provenance note in LICENSE names it, restoring the vendor name a clean-room
assertion needs in order to say what it is clean of.

Build, vet and all 29 test packages green.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-04 01:09:51 -07:00

68 lines
2.1 KiB
Go

// Copyright 2026 Hanzo AI, Inc.
// SPDX-License-Identifier: MIT OR Apache-2.0
package schema
import (
"encoding/json"
"testing"
)
// OrgRef is the claim-side value a consumer (cloud) decodes off a v2 token in
// place of the dead iam-v1 type. These tests pin the HTTP contract: the JSON
// tags MUST stay `org` and `role,omitempty` so a token minted by v2 round-trips
// byte-for-byte through a consumer, and the Membership → OrgRef projection is
// the ONE way to build the `orgs` claim.
func TestOrgRef_JSONContract(t *testing.T) {
// role present: both fields emitted.
b, err := json.Marshal(OrgRef{Org: "hanzo", Role: "admin"})
if err != nil {
t.Fatalf("marshal: %v", err)
}
if got, want := string(b), `{"org":"hanzo","role":"admin"}`; got != want {
t.Fatalf("marshal(org+role) = %s, want %s", got, want)
}
// role omitted: role,omitempty drops the empty field (iam-v1 parity).
b, err = json.Marshal(OrgRef{Org: "hanzo"})
if err != nil {
t.Fatalf("marshal: %v", err)
}
if got, want := string(b), `{"org":"hanzo"}`; got != want {
t.Fatalf("marshal(org only) = %s, want %s", got, want)
}
// decode round-trips (a consumer reading the claim).
var back OrgRef
if err := json.Unmarshal([]byte(`{"org":"lux","role":"member"}`), &back); err != nil {
t.Fatalf("unmarshal: %v", err)
}
if back.Org != "lux" || back.Role != "member" {
t.Fatalf("unmarshal = %+v, want {lux member}", back)
}
}
func TestOrgRefsFromMemberships_projection(t *testing.T) {
ms := []*Membership{
{User: "hanzo/alice", Org: "hanzo", Role: "owner"},
{User: "hanzo/alice", Org: "lux", Role: "member"},
nil, // a nil row is skipped, never panics.
}
got := OrgRefsFromMemberships(ms)
want := []OrgRef{{Org: "hanzo", Role: "owner"}, {Org: "lux", Role: "member"}}
if len(got) != len(want) {
t.Fatalf("len = %d, want %d (%+v)", len(got), len(want), got)
}
for i := range want {
if got[i] != want[i] {
t.Fatalf("orgRef[%d] = %+v, want %+v", i, got[i], want[i])
}
}
// an empty set yields a nil slice so the claim is omitted, not emitted empty.
if OrgRefsFromMemberships(nil) != nil {
t.Fatalf("OrgRefsFromMemberships(nil) should be nil")
}
}