key-cape/src/internal/server/oidc/assurance_time_test.go

55 lines
2.1 KiB
Go
Raw Normal View History

Answer the approver-client questions, and fix what checking them turned up informed-decision and approval-engine both asked to hear problems with the human approver registration now rather than at handover. Checking their requested shape against the source rather than agreeing it on paper turned up three things. Scope gap, accepted: [openid, approval:approve] cannot render a decision, since GET /v1/approvals/{id} and /claim both need approval:read -- the surface could submit an entry it was never able to display. Published [openid, approval:read, approval:approve]. Reading through a service identity was the alternative and is worse: it weakens the evidence-of-what-this-person-saw claim the component exists to make. approval:consume stays excluded. Assurance shape, published and a defect fixed. Both asked for a documented shape and KeyCape already emitted one, so it is written down rather than renegotiated. Writing it down surfaced that `at` was the token mint time rather than the authentication time. Those differ by hours whenever a browser session is reused, and approval-engine persists this object verbatim as the only downstream record that MFA happened -- so a stored approval could have evidenced MFA at a moment the person proved nothing. PKCESession.AuthTime now carries the original login instant through session reuse, with mint time as the fallback. Blocker found before anyone built on it: a human token cannot carry tenant:platform. effectiveTenant resolves the human tenant from the directory user, no adapter populates User.Tenant, and the per-client tenant field is read only on the client_credentials path -- so every human token defaults to tenant:coulomb, which approval-engine refuses by exact string equality. It would have presented as a failed approval rather than a registration defect. Two resolutions sent to the owners and neither implemented here: the choice decides whether a human's tenant is a property of the person or of the registration, and that is not KeyCape's alone to make. Also recorded ops-warden's answers to KEY-WP-0014-T04, including their finding that `warden plan` returns `autonomous` for a need containing generate and CAS-write, because it has no read-versus-mutate intent. Their standing instruction -- treat a warden plan verdict on any write, rotate or provision need as unreliable until WARDEN-WP-0038 lands -- is recorded in the workplan rather than left in an inbox. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016uV8zoCKpA1WRAxsKRYbdH Assistant: claude-code Assistant-Model: opus Assistant-Process: 1182213@bnt-lap001 Assistant-Session: 966597b9-ae61-46a4-8b9e-1594ab3ec4ad
2026-09-09 14:25:38 +02:00
package oidc
import (
"testing"
"time"
)
// approval-engine persists the assurance object verbatim and it is the only
// downstream evidence that MFA happened (KEY-WP-0013-T05). A reused browser
// session can be hours old, so reporting mint time would overstate how
// recently the person actually proved anything.
func TestAssuranceReportsAuthenticationTimeNotMintTime(t *testing.T) {
authenticated := time.Now().Add(-4 * time.Hour)
minted := time.Now()
claim := assuranceClaim(true, authenticated, minted)
if got := claim["at"].(int64); got != authenticated.Unix() {
t.Errorf("assurance.at = %d, want the authentication time %d", got, authenticated.Unix())
}
if claim["level"] != "aal2" || claim["mfa"] != true {
t.Errorf("MFA-verified authorization did not report aal2: %v", claim)
}
}
// A session stored before AuthTime existed has a zero value; falling back to
// mint time keeps the claim present rather than emitting a 1970 timestamp.
func TestAssuranceFallsBackToMintTimeWhenAuthTimeIsUnset(t *testing.T) {
minted := time.Now()
claim := assuranceClaim(false, time.Time{}, minted)
if got := claim["at"].(int64); got != minted.Unix() {
t.Errorf("assurance.at = %d, want the mint-time fallback %d", got, minted.Unix())
}
if claim["level"] != "aal1" || claim["mfa"] != false {
t.Errorf("unverified authorization did not report aal1: %v", claim)
}
}
// The shape approval-engine and informed-decision consume. A missing key here
// breaks a downstream record that cannot be reconstructed later.
func TestAssuranceCarriesTheDocumentedShape(t *testing.T) {
claim := assuranceClaim(true, time.Now(), time.Now())
for _, key := range []string{"level", "methods", "mfa", "source", "at"} {
if _, ok := claim[key]; !ok {
t.Errorf("assurance object is missing %q: %v", key, claim)
}
}
methods, ok := claim["methods"].([]string)
if !ok || len(methods) != 2 || methods[0] != "pwd" || methods[1] != "otp" {
t.Errorf("aal2 methods = %v, want [pwd otp]", claim["methods"])
}
if claim["source"] != "key-cape" {
t.Errorf("source = %v, want key-cape", claim["source"])
}
}