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]>
65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package oidc
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/iam/pkg/pkce"
|
|
)
|
|
|
|
// The RFC 7636 Appendix B vector is pinned where the derivation lives, in
|
|
// pkg/pkce. These tests cover what is this package's own: the verification
|
|
// policy around it.
|
|
|
|
func TestVerifyPKCE_HappyPath(t *testing.T) {
|
|
verifier := "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
|
|
challenge := pkce.Challenge(verifier)
|
|
if err := VerifyPKCE(verifier, challenge, "S256"); err != nil {
|
|
t.Fatalf("valid verifier rejected: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestVerifyPKCE_WrongVerifierRejected(t *testing.T) {
|
|
challenge := pkce.Challenge("the-real-verifier-value-0000000000000000000")
|
|
err := VerifyPKCE("a-different-verifier-value-000000000000000000", challenge, "S256")
|
|
if !errors.Is(err, ErrPKCEMismatch) {
|
|
t.Fatalf("wrong verifier: got %v, want ErrPKCEMismatch", err)
|
|
}
|
|
}
|
|
|
|
func TestVerifyPKCE_PlainRejected(t *testing.T) {
|
|
// Even if the "plain" value would match, the method must be refused.
|
|
v := "plain-verifier-equals-challenge-under-plain-000"
|
|
for _, method := range []string{"plain", "PLAIN", "", "s256", "S384"} {
|
|
if err := VerifyPKCE(v, v, method); !errors.Is(err, ErrPKCEPlainRejected) {
|
|
t.Fatalf("method %q: got %v, want ErrPKCEPlainRejected", method, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestVerifyPKCE_MissingVerifier(t *testing.T) {
|
|
challenge := pkce.Challenge("some-verifier-0000000000000000000000000000000")
|
|
if err := VerifyPKCE("", challenge, "S256"); !errors.Is(err, ErrPKCEMissing) {
|
|
t.Fatalf("empty verifier with a stored challenge: got %v, want ErrPKCEMissing", err)
|
|
}
|
|
}
|
|
|
|
func TestVerifyPKCE_VerifierWithNoChallengeFailsClosed(t *testing.T) {
|
|
// A verifier presented when the code was minted with no challenge is a
|
|
// protocol error and must NOT be treated as a match.
|
|
if err := VerifyPKCE("unexpected-verifier", "", "S256"); !errors.Is(err, ErrPKCEMissing) {
|
|
t.Fatalf("verifier with empty challenge: got %v, want ErrPKCEMissing", err)
|
|
}
|
|
}
|
|
|
|
func TestVerifyPKCE_NoPKCEEitherSide(t *testing.T) {
|
|
// No challenge and no verifier: not an error here — the caller enforces
|
|
// whether a public client is allowed to skip PKCE.
|
|
if err := VerifyPKCE("", "", ""); err != nil {
|
|
t.Fatalf("no PKCE on either side should be nil, got %v", err)
|
|
}
|
|
}
|