mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
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]>
68 lines
2.7 KiB
Go
68 lines
2.7 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package bootstrap_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/iam/pkg/schema"
|
|
"github.com/hanzoai/iam/pkg/store"
|
|
)
|
|
|
|
// Token lifetimes are DECLARABLE through the upsert, and an omitted lifetime
|
|
// PRESERVES what the app has. Without the first half there is no declarative way
|
|
// to say a refresh token must outlive its access token, and oidc.refreshTTL
|
|
// clamps the refresh lifetime to the access lifetime — the registration
|
|
// advertises a refresh_token grant that can never be exchanged, which is where
|
|
// hanzo-cli's hourly browser re-login came from. Without the second half every
|
|
// steady-state converge would reset the lifetime it just set.
|
|
func TestUpsertApplication_tokenLifetimes(t *testing.T) {
|
|
app, db := boot(t)
|
|
const path = "/v1/iam/admin/applications/upsert"
|
|
get := func() *schema.Application {
|
|
t.Helper()
|
|
a, err := store.GetApplicationByName(context.Background(), db, "admin", "hanzo-cli")
|
|
if err != nil || a == nil {
|
|
t.Fatalf("load hanzo-cli: %v", err)
|
|
}
|
|
return a
|
|
}
|
|
|
|
// Create with a declared refresh lifetime; the access lifetime is unstated
|
|
// and must fall back to the ONE default, not to zero.
|
|
if st, m := post(t, app, path, svcToken,
|
|
`{"organization":"hanzo","name":"hanzo-cli","refreshExpireInHours":720}`); st != 200 || m["action"] != "created" {
|
|
t.Fatalf("create: status=%d body=%v", st, m)
|
|
}
|
|
a := get()
|
|
if a.RefreshExpireInHours != 720 {
|
|
t.Fatalf("refreshExpireInHours = %v, want 720", a.RefreshExpireInHours)
|
|
}
|
|
if a.ExpireInHours != schema.DefaultExpireInHours {
|
|
t.Fatalf("expireInHours = %v, want the default %v", a.ExpireInHours, schema.DefaultExpireInHours)
|
|
}
|
|
if a.RefreshExpireInHours <= a.ExpireInHours {
|
|
t.Fatal("the refresh lifetime must outlive the access lifetime")
|
|
}
|
|
|
|
// A converge that says nothing about lifetimes preserves both.
|
|
if st, _ := post(t, app, path, svcToken, `{"organization":"hanzo","name":"hanzo-cli"}`); st != 200 {
|
|
t.Fatalf("re-upsert failed: %d", st)
|
|
}
|
|
if a := get(); a.RefreshExpireInHours != 720 || a.ExpireInHours != schema.DefaultExpireInHours {
|
|
t.Fatalf("an omitted lifetime was not preserved: expire=%v refresh=%v", a.ExpireInHours, a.RefreshExpireInHours)
|
|
}
|
|
|
|
// A stated lifetime moves it — including an explicit 0, the way a document
|
|
// says "back to the default".
|
|
if st, _ := post(t, app, path, svcToken,
|
|
`{"organization":"hanzo","name":"hanzo-cli","expireInHours":8,"refreshExpireInHours":0}`); st != 200 {
|
|
t.Fatalf("update failed: %d", st)
|
|
}
|
|
if a := get(); a.ExpireInHours != 8 || a.RefreshExpireInHours != 0 {
|
|
t.Fatalf("stated lifetimes not applied: expire=%v refresh=%v", a.ExpireInHours, a.RefreshExpireInHours)
|
|
}
|
|
}
|