Files
iam/internal/oidc/federation_session_test.go
zeekay 2838b02d2f a wallet signature is a first factor, and the IdP remembers who signed in
The wallet front door skipped both halves of what every other front door does.

It owed a second factor and paid none: the gate was a stub reporting "not
required", left there when iam had no gate to call. It has one — the password
door calls it, the return from another provider calls it — and a wallet is
attachable to any existing identity, so a 2FA-enrolled account with a linked
wallet signed in on one factor and walked away with the full grant. The stub is
gone and oidc's Gate is called: one policy, not a second copy that drifts. A
signature proves none of the offerable factors, so it passes "" and the person
finishes at /v1/iam/login with the challenge the gate set, the same as a
password.

And it minted no session, so a bare wallet login answered with a user id and no
cookie: the portal sent the person to a page whose bootstrap found nobody signed
in and bounced them back to the credential form. The return from Google or
GitHub had the same hole with a worse blast radius — the relying party got its
code while hanzo.id read the person as anonymous and every other app re-prompted
them. loginGrant already says why this belongs to the front door rather than to
the grant shape; that rule is now sessions.Open and all three doors read it from
there.
2026-08-07 22:51:19 -07:00

45 lines
1.3 KiB
Go

// Copyright 2026 Hanzo AI, Inc.
// SPDX-License-Identifier: MIT OR Apache-2.0
package oidc
import (
"net/http"
"testing"
"github.com/hanzoai/iam/internal/sessions"
)
// What a federated sign-in leaves behind in the browser.
// A federated sign-in leaves the person signed IN to this IdP, not just holding a
// code for the app that sent them. Without it hanzo.id read them as anonymous and
// every other app re-prompted: the relying party got its grant and the IdP forgot
// the human.
func TestFederation_SignInOpensTheSession(t *testing.T) {
app, db := newServer(t)
seedApp(t, db, appOpts{clientID: "webapp", signup: true, redirectURIs: []string{testRedirect}})
m := newMockOIDC(t, fedGoogleCID)
seedOIDCProvider(t, db, "webapp", m)
q, cookie := beginAuthorize(t, app, "webapp", fedProvGoogle)
m.mu.Lock()
m.nonce = q.Get("nonce")
m.mu.Unlock()
resp := callback(t, app, q.Get("state"), "idp-code-1", cookie)
requireRedirect(t, resp, testRedirect)
var session *http.Cookie
for _, ck := range resp.Cookies() {
if ck.Name == sessions.CookieName {
session = ck
}
}
if session == nil {
t.Fatalf("the federation callback set no %s cookie; cookies=%v", sessions.CookieName, resp.Cookies())
}
if session.Value == "" || !session.HttpOnly || !session.Secure {
t.Fatalf("the session must be a live HttpOnly+Secure cookie, got %+v", session)
}
}