Harden identity lifecycle and complete consumer verification
19 files changed,
+486
−66
.rastrillo/budgets.txt+1 −1docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+20 −17go.mod+1 −1go.sum+2 −2internal/equipo/config.go+1 −0internal/equipo/kernel/types.go+5 −4internal/equipo/migrations/0082_oficina_id.sql+25 −1internal/equipo/migrations/schema.sql+26 −0internal/equipo/oficinaid/http.go+10 −5internal/equipo/oficinaid/link.go+7 −0internal/equipo/oficinaid/main_test.go+9 −0internal/equipo/oficinaid/signout.go+1 −1internal/equipo/oficinaid/store.go+8 −5internal/equipo/oficinaid/store_test.go+63 −2internal/idtest/deletion_test.go+55 −0internal/idtest/guards_test.go+165 −0internal/idtest/id_browser_test.go+24 −20internal/idtest/id_test.go+54 −7internal/idtest/main_test.go+9 −0
CI cancelled — superseded by a newer push — run details
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 1078e886..c823f3bb 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -14,7 +14,7 @@ perf GET /* skip Unknown private paths render 404; this fallback contains no scr |
| time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial reruns measured 18.079s and 22.031s. Keep migration, recovery, accounting and concurrency assertions; 60s leaves 30 percent headroom above loaded CI. |
| time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage. |
| -size internal/equipo 19707 - Web handlers and runtime copy, including Oficina ID route wiring and reviewed strings. Identity storage and HTTP flow live in internal/equipo/oficinaid. |
| +size internal/equipo 19708 - Web handlers and runtime copy, including Oficina ID route wiring and reviewed strings. Identity storage and HTTP flow live in internal/equipo/oficinaid. |
| size internal/wire 6097 - Protocol 21 Copy dispatch, result, task flags and downgrade fields share Encode. |
| size internal/equipotest - 13400 Task 21 repairs historical migration and conversation fixtures after Plan 3. Measured 13024 test lines; the 300s time ceiling is unchanged. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 095bf076..e6248f14 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -4706,23 +4706,26 @@ All eight entries have individual `COPY REVIEW REQUIRED` markers. The API guide |
| Oficina ID consumer: COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13). |
| -- `id.door`: Sign in with Oficina ID |
| -- `id.title`: Oficina ID |
| -- `id.unlinked`: No Equipo account is linked to this Oficina ID. |
| -- `id.help`: Sign in by email, then link your Oficina ID in Settings. |
| -- `id.link`: Link Oficina ID |
| -- `id.reauth`: Sign in by email again before linking or unlinking your Oficina ID. |
| -- `id.confirm`: Link this Oficina ID to your Equipo account? |
| -- `id.confirm_button`: Confirm link |
| -- `id.unlink`: Unlink Oficina ID |
| -- `id.unlink_confirm`: Unlink your Oficina ID? You can still sign in by email. Your work will stay in Equipo. |
| -- `id.linked_at`: Linked on %s |
| -- `id.not_linked`: You have not linked an Oficina ID. |
| -- `id.failed`: This sign-in could not be completed. Try again or sign in by email. |
| -- `id.email`: Sign in by email |
| -- `id.signed_out`: You are signed out of Equipo. |
| -- `id.home_signout`: Sign out of Oficina ID too |
| -- `copyIDConfig`: Oficina ID configuration is incomplete or invalid. |
| +| Key | Copy | Surface | Review | |
| +| --- | --- | --- | --- | |
| +| `id.door` | Sign in with Oficina ID | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.title` | Oficina ID | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.unlinked` | No Equipo account is linked to this Oficina ID. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.help` | Sign in by email, then link your Oficina ID in Settings. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.link` | Link Oficina ID | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.reauth` | Sign in by email again before linking or unlinking your Oficina ID. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.confirm` | Link this Oficina ID to your Equipo account? | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.confirm_button` | Confirm link | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.unlink` | Unlink Oficina ID | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.unlink_confirm` | Unlink your Oficina ID? You can still sign in by email. Your work will stay in Equipo. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.linked_at` | Linked on %s | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.not_linked` | You have not linked an Oficina ID. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.failed` | This sign-in could not be completed. Try again or sign in by email. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.email` | Sign in by email | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.signed_out` | You are signed out of Equipo. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `id.home_signout` | Sign out of Oficina ID too | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| +| `copyIDConfig` | Oficina ID configuration is incomplete or invalid. | Oficina ID | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13) | |
| + |
| Activity subjects: COPY ACCEPTED BY DELEGATION (Astra, 2026-11-13). Names come from the person’s task records or runner catalog. Long quoted subjects shorten only on screen; the tooltip and accessible label keep the full text. |
diff --git a/go.mod b/go.mod| index 20c62166..89d78a79 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -17,7 +17,7 @@ require github.com/coder/websocket v1.8.15 |
| require ( |
| amadan.net/oficina/home/connect v0.0.0-20261113224411-fe44c43fd256 |
| - amadan.net/oficina/home/handoff v0.0.0-20261113224054-3010b00019e2 |
| + amadan.net/oficina/home/handoff v0.0.0-20261113224411-fe44c43fd256 |
| golang.org/x/crypto v0.53.0 |
| ) |
diff --git a/go.sum b/go.sum| index ba340f69..1cdea6ac 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -2,8 +2,8 @@ amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d h1:p9+01xRdBD7s |
| amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| amadan.net/oficina/home/connect v0.0.0-20261113224411-fe44c43fd256 h1:grzC5lwhUXJw14j/V8axWjBfiBQnQaF7M79BRG5zGA0= |
| amadan.net/oficina/home/connect v0.0.0-20261113224411-fe44c43fd256/go.mod h1:7tsJ//7X4o5QkD068WoUGVDxj/e3ygZ2adF+PHhvBxE= |
| -amadan.net/oficina/home/handoff v0.0.0-20261113224054-3010b00019e2 h1:TNM61Isk73O8sior0TumLPOw2KoPdpKv/kyCCAM0hNk= |
| -amadan.net/oficina/home/handoff v0.0.0-20261113224054-3010b00019e2/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k= |
| +amadan.net/oficina/home/handoff v0.0.0-20261113224411-fe44c43fd256 h1:NjlNWjyRxWS2BI9rtf2Am1qGL31DvOcvJeDLUIDEPvM= |
| +amadan.net/oficina/home/handoff v0.0.0-20261113224411-fe44c43fd256/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k= |
| amadan.net/rastrillo/rastrillo v0.30.1 h1:MleTrteqqnGGeCZBqQSzZAhAfqQ3B0tZahZ+0wXhzXc= |
| amadan.net/rastrillo/rastrillo v0.30.1/go.mod h1:K7Clrt14+25ruVupgRjlIhH2GQp/OdL9VoD8xPmkt0w= |
| amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM= |
diff --git a/internal/equipo/config.go b/internal/equipo/config.go| index 1d23e551..2febd9db 100644 |
| --- a/internal/equipo/config.go |
| +++ b/internal/equipo/config.go |
| @@ -45,6 +45,7 @@ func LoadConfig(getenv func(string) string) (Config, error) { |
| var err error |
| cfg.Home, err = connect.DecodeCredentials(&raw, cfg.Origin) |
| if err != nil { |
| + //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go. |
| return Config{}, errors.New(copyIDConfig) |
| } |
| } |
diff --git a/internal/equipo/kernel/types.go b/internal/equipo/kernel/types.go| index b20d715e..440196eb 100644 |
| --- a/internal/equipo/kernel/types.go |
| +++ b/internal/equipo/kernel/types.go |
| @@ -37,10 +37,11 @@ const ( |
| ) |
| type Member struct { |
| - Address string `gorm:"primaryKey"` |
| - Role Role |
| - Revision int64 |
| - Active bool |
| + IdentityKey string `gorm:"not null;default:'';uniqueIndex:members_identity_key" json:"-"` |
| + Address string `gorm:"primaryKey"` |
| + Role Role |
| + Revision int64 |
| + Active bool |
| // SessionEpoch is the earliest permitted session creation time in Unix seconds. |
| SessionEpoch int64 |
| } |
diff --git a/internal/equipo/migrations/0082_oficina_id.sql b/internal/equipo/migrations/0082_oficina_id.sql| index 657f3411..b1fd9128 100644 |
| --- a/internal/equipo/migrations/0082_oficina_id.sql |
| +++ b/internal/equipo/migrations/0082_oficina_id.sql |
| @@ -1,2 +1,26 @@ |
| -CREATE TABLE equipo_id_accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, binding TEXT NOT NULL UNIQUE, sealed_address BLOB NOT NULL, linked_at INTEGER NOT NULL DEFAULT 0); |
| +ALTER TABLE members ADD COLUMN identity_key text NOT NULL DEFAULT ""; |
| +UPDATE members SET identity_key=lower(hex(randomblob(16))); |
| +CREATE UNIQUE INDEX members_identity_key ON members(identity_key); |
| +CREATE TRIGGER equipo_member_identity AFTER INSERT ON members WHEN NEW.identity_key='' BEGIN |
| + UPDATE members SET identity_key=lower(hex(randomblob(16))) WHERE address=NEW.address; |
| +END; |
| +CREATE TABLE equipo_id_accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, binding TEXT NOT NULL UNIQUE, member_key TEXT NOT NULL UNIQUE, sealed_address BLOB NOT NULL, linked_at INTEGER NOT NULL DEFAULT 0); |
| CREATE TABLE equipo_id_reauth (id_hash TEXT PRIMARY KEY, account_id INTEGER NOT NULL, session_hash TEXT NOT NULL, started INTEGER NOT NULL, expires INTEGER NOT NULL, purpose TEXT NOT NULL, ready INTEGER NOT NULL DEFAULT 0); |
| +CREATE TRIGGER equipo_id_member_delete AFTER DELETE ON members BEGIN |
| + DELETE FROM sessions WHERE method='oficina-id' AND subject IN (SELECT subject FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key)); |
| + DELETE FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key); |
| + DELETE FROM equipo_id_accounts WHERE member_key=OLD.identity_key; |
| + DELETE FROM equipo_id_reauth; |
| + DELETE FROM home_link_flows; |
| + DELETE FROM oficina_handoff_pending; |
| + DELETE FROM oficina_handoff_inbox; |
| +END; |
| +CREATE TRIGGER equipo_id_member_change AFTER UPDATE OF address ON members WHEN OLD.address<>NEW.address BEGIN |
| + DELETE FROM sessions WHERE method='oficina-id' AND subject IN (SELECT subject FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key)); |
| + DELETE FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key); |
| + DELETE FROM equipo_id_accounts WHERE member_key=OLD.identity_key; |
| + DELETE FROM equipo_id_reauth; |
| + DELETE FROM home_link_flows; |
| + DELETE FROM oficina_handoff_pending; |
| + DELETE FROM oficina_handoff_inbox; |
| +END; |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 30afc5cc..7c5da14e 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -678,3 +678,29 @@ CREATE TABLE chat_handoff_turns (handoff_id text, turn_id text PRIMARY KEY); |
| CREATE INDEX chat_handoff_turn_handoff ON chat_handoff_turns(handoff_id); |
| CREATE TABLE chat_handoff_tasks (handoff_id text, task_id text, created numeric, PRIMARY KEY (handoff_id, task_id)); |
| CREATE INDEX chat_handoff_task ON chat_handoff_tasks(task_id); |
| +ALTER TABLE members ADD COLUMN identity_key text NOT NULL DEFAULT ""; |
| +UPDATE members SET identity_key=lower(hex(randomblob(16))); |
| +CREATE UNIQUE INDEX members_identity_key ON members(identity_key); |
| +CREATE TRIGGER equipo_member_identity AFTER INSERT ON members WHEN NEW.identity_key='' BEGIN |
| + UPDATE members SET identity_key=lower(hex(randomblob(16))) WHERE address=NEW.address; |
| +END; |
| +CREATE TABLE equipo_id_accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, binding TEXT NOT NULL UNIQUE, member_key TEXT NOT NULL UNIQUE, sealed_address BLOB NOT NULL, linked_at INTEGER NOT NULL DEFAULT 0); |
| +CREATE TABLE equipo_id_reauth (id_hash TEXT PRIMARY KEY, account_id INTEGER NOT NULL, session_hash TEXT NOT NULL, started INTEGER NOT NULL, expires INTEGER NOT NULL, purpose TEXT NOT NULL, ready INTEGER NOT NULL DEFAULT 0); |
| +CREATE TRIGGER equipo_id_member_delete AFTER DELETE ON members BEGIN |
| + DELETE FROM sessions WHERE method='oficina-id' AND subject IN (SELECT subject FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key)); |
| + DELETE FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key); |
| + DELETE FROM equipo_id_accounts WHERE member_key=OLD.identity_key; |
| + DELETE FROM equipo_id_reauth; |
| + DELETE FROM home_link_flows; |
| + DELETE FROM oficina_handoff_pending; |
| + DELETE FROM oficina_handoff_inbox; |
| +END; |
| +CREATE TRIGGER equipo_id_member_change AFTER UPDATE OF address ON members WHEN OLD.address<>NEW.address BEGIN |
| + DELETE FROM sessions WHERE method='oficina-id' AND subject IN (SELECT subject FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key)); |
| + DELETE FROM home_identity_links WHERE person_id IN (SELECT id FROM equipo_id_accounts WHERE member_key=OLD.identity_key); |
| + DELETE FROM equipo_id_accounts WHERE member_key=OLD.identity_key; |
| + DELETE FROM equipo_id_reauth; |
| + DELETE FROM home_link_flows; |
| + DELETE FROM oficina_handoff_pending; |
| + DELETE FROM oficina_handoff_inbox; |
| +END; |
diff --git a/internal/equipo/oficinaid/http.go b/internal/equipo/oficinaid/http.go| index 3dd0a7b7..9b7a4f94 100644 |
| --- a/internal/equipo/oficinaid/http.go |
| +++ b/internal/equipo/oficinaid/http.go |
| @@ -101,7 +101,7 @@ func (h *HTTP) guard(next http.HandlerFunc) http.HandlerFunc { |
| } |
| func (h *HTTP) Routes(r chi.Router) { |
| r.Get("/auth/home", h.guard(h.Start)) |
| - r.Post("/auth/assertion", h.guard(h.Callback)) |
| + r.Handle("/auth/assertion", h.guard(h.Callback)) |
| r.Get("/auth/finish", h.guard(h.Finish)) |
| r.Get(settingsPath, h.guard(h.Settings)) |
| r.Post("/account/home/reauth", h.guard(h.BeginReauth)) |
| @@ -158,6 +158,11 @@ func (h *HTTP) Start(w http.ResponseWriter, r *http.Request) { |
| http.Redirect(w, r, h.Store.Config.Issuer+"/authorize?"+q.Encode(), http.StatusSeeOther) |
| } |
| func (h *HTTP) Callback(w http.ResponseWriter, r *http.Request) { |
| + if r.Method != http.MethodPost { |
| + w.Header().Set("Allow", http.MethodPost) |
| + h.Render(w, r, View{State: "failed"}, http.StatusMethodNotAllowed) |
| + return |
| + } |
| origins := r.Header.Values("Origin") |
| media, _, e := mime.ParseMediaType(r.Header.Get("Content-Type")) |
| if len(origins) != 1 || origins[0] != h.Store.Config.Issuer || r.URL.RawQuery != "" || e != nil || media != "application/x-www-form-urlencoded" { |
| @@ -236,9 +241,9 @@ func (h *HTTP) CompleteReauth(w http.ResponseWriter, r *http.Request) { |
| if purpose == "link" { |
| set(w, reauthCookie, "", -1) |
| set(w, initCookie, next, 300) |
| - http.Redirect(w, r, "/auth/home", 303) |
| + http.Redirect(w, r, "/auth/home", http.StatusSeeOther) |
| } else { |
| - http.Redirect(w, r, "/account/home/unlink", 303) |
| + http.Redirect(w, r, "/account/home/unlink", http.StatusSeeOther) |
| } |
| } |
| func (h *HTTP) Confirmation(w http.ResponseWriter, r *http.Request) { |
| @@ -254,7 +259,7 @@ func (h *HTTP) Confirm(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| set(w, proofCookie, "", -1) |
| - http.Redirect(w, r, settingsPath, 303) |
| + http.Redirect(w, r, settingsPath, http.StatusSeeOther) |
| } |
| func (h *HTTP) UnlinkPage(w http.ResponseWriter, r *http.Request) { |
| if _, e := h.Store.Session(r.Context(), h.token(r), time.Now()); e != nil { |
| @@ -269,7 +274,7 @@ func (h *HTTP) Unlink(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| set(w, reauthCookie, "", -1) |
| - http.Redirect(w, r, settingsPath, 303) |
| + http.Redirect(w, r, settingsPath, http.StatusSeeOther) |
| } |
| func (h *HTTP) Session(r *http.Request) (auth.Identity, bool) { |
| raw, ok := h.Auth.SessionFrom(r) |
diff --git a/internal/equipo/oficinaid/link.go b/internal/equipo/oficinaid/link.go| index 932ed8a2..81ac51c4 100644 |
| --- a/internal/equipo/oficinaid/link.go |
| +++ b/internal/equipo/oficinaid/link.go |
| @@ -6,6 +6,7 @@ import ( |
| "errors" |
| "time" |
| + "amadan.net/oficina/home/connect/linkstore" |
| "amadan.net/rastrillo/rastrillo/sessions" |
| ) |
| @@ -128,6 +129,12 @@ func (s *Store) Confirm(ctx context.Context, proof, token string, now time.Time) |
| return e |
| } |
| _, e = s.Links.ConfirmOn(ctx, tx, proof, local, now) |
| + if errors.Is(e, linkstore.ErrRefused) { |
| + if commitErr := tx.Commit(); commitErr != nil { |
| + return commitErr |
| + } |
| + return e |
| + } |
| if e != nil { |
| return e |
| } |
diff --git a/internal/equipo/oficinaid/main_test.go b/internal/equipo/oficinaid/main_test.go| new file mode 100644 |
| index 00000000..7298471e |
| --- /dev/null |
| +++ b/internal/equipo/oficinaid/main_test.go |
| @@ -0,0 +1,9 @@ |
| +package oficinaid |
| + |
| +import ( |
| + "amadan.net/rastrillo/rastrillo/budget" |
| + "os" |
| + "testing" |
| +) |
| + |
| +func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } |
diff --git a/internal/equipo/oficinaid/signout.go b/internal/equipo/oficinaid/signout.go| index 96d84858..41e895d1 100644 |
| --- a/internal/equipo/oficinaid/signout.go |
| +++ b/internal/equipo/oficinaid/signout.go |
| @@ -37,7 +37,7 @@ func (h *HTTP) signout(w http.ResponseWriter, r *http.Request) { |
| set(w, logoutCookie, base64.RawURLEncoding.EncodeToString(sealed), 300) |
| } |
| } |
| - http.Redirect(w, r, "/signed-out", 303) |
| + http.Redirect(w, r, "/signed-out", http.StatusSeeOther) |
| } |
| func (h *HTTP) SignedOut(w http.ResponseWriter, r *http.Request) { |
| view := View{State: "signed-out"} |
diff --git a/internal/equipo/oficinaid/store.go b/internal/equipo/oficinaid/store.go| index 2c0c5d89..14e76d2f 100644 |
| --- a/internal/equipo/oficinaid/store.go |
| +++ b/internal/equipo/oficinaid/store.go |
| @@ -23,10 +23,11 @@ const Method = "oficina-id" |
| var ErrRefused = errors.New("oficina identity refused") |
| var ErrUnlinked = errors.New("oficina identity unlinked") |
| -const SchemaSQL = `CREATE TABLE equipo_id_accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, binding TEXT NOT NULL UNIQUE, sealed_address BLOB NOT NULL, linked_at INTEGER NOT NULL DEFAULT 0); |
| +const SchemaSQL = `CREATE TABLE equipo_id_accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, binding TEXT NOT NULL UNIQUE, member_key TEXT NOT NULL UNIQUE, sealed_address BLOB NOT NULL, linked_at INTEGER NOT NULL DEFAULT 0); |
| CREATE TABLE equipo_id_reauth (id_hash TEXT PRIMARY KEY, account_id INTEGER NOT NULL, session_hash TEXT NOT NULL, started INTEGER NOT NULL, expires INTEGER NOT NULL, purpose TEXT NOT NULL, ready INTEGER NOT NULL DEFAULT 0);` |
| type Account struct { |
| + MemberKey string `gorm:"not null;unique"` |
| ID int64 |
| Binding string `gorm:"not null;unique"` |
| SealedAddress []byte `gorm:"not null"` |
| @@ -84,7 +85,8 @@ func (s *Store) binding(address string) string { |
| } |
| func (s *Store) lookup(ctx context.Context, q linkstore.Queryer, id int64) (string, error) { |
| var sealed []byte |
| - if e := q.QueryRowContext(ctx, "SELECT sealed_address FROM equipo_id_accounts WHERE id=?", id).Scan(&sealed); e != nil { |
| + var memberKey string |
| + if e := q.QueryRowContext(ctx, "SELECT sealed_address,member_key FROM equipo_id_accounts WHERE id=?", id).Scan(&sealed, &memberKey); e != nil { |
| return "", e |
| } |
| plain, e := s.seal.Open("account."+strconv.FormatInt(id, 10), sealed) |
| @@ -93,7 +95,7 @@ func (s *Store) lookup(ctx context.Context, q linkstore.Queryer, id int64) (stri |
| } |
| address := string(plain) |
| var active bool |
| - if e = q.QueryRowContext(ctx, "SELECT active FROM members WHERE address=?", address).Scan(&active); e != nil { |
| + if e = q.QueryRowContext(ctx, "SELECT active FROM members WHERE address=? AND identity_key=?", address, memberKey).Scan(&active); e != nil { |
| return "", e |
| } |
| if !active { |
| @@ -103,7 +105,8 @@ func (s *Store) lookup(ctx context.Context, q linkstore.Queryer, id int64) (stri |
| } |
| func (s *Store) account(ctx context.Context, tx *sql.Tx, address string) (int64, error) { |
| var active bool |
| - if e := tx.QueryRowContext(ctx, "SELECT active FROM members WHERE address=?", address).Scan(&active); e != nil || !active { |
| + var memberKey string |
| + if e := tx.QueryRowContext(ctx, "SELECT active,identity_key FROM members WHERE address=?", address).Scan(&active, &memberKey); e != nil || !active || memberKey == "" { |
| return 0, ErrRefused |
| } |
| binding := s.binding(address) |
| @@ -115,7 +118,7 @@ func (s *Store) account(ctx context.Context, tx *sql.Tx, address string) (int64, |
| if !errors.Is(e, sql.ErrNoRows) { |
| return 0, e |
| } |
| - result, e := tx.ExecContext(ctx, "INSERT INTO equipo_id_accounts(binding,sealed_address) VALUES(?,?)", binding, []byte{}) |
| + result, e := tx.ExecContext(ctx, "INSERT INTO equipo_id_accounts(binding,member_key,sealed_address) VALUES(?,?,?)", binding, memberKey, []byte{}) |
| if e != nil { |
| return 0, e |
| } |
diff --git a/internal/equipo/oficinaid/store_test.go b/internal/equipo/oficinaid/store_test.go| index 5f906981..73959c8c 100644 |
| --- a/internal/equipo/oficinaid/store_test.go |
| +++ b/internal/equipo/oficinaid/store_test.go |
| @@ -40,7 +40,7 @@ func fixture(t *testing.T) (*Store, *crypto.Keypair) { |
| } |
| } |
| } |
| - if _, e = db.Exec(`CREATE TABLE audit_events(id INTEGER PRIMARY KEY,actor TEXT,kind TEXT,record_id TEXT,at TEXT); CREATE TABLE members(address TEXT PRIMARY KEY,active INTEGER,session_epoch INTEGER); CREATE TABLE sessions(token_hash TEXT PRIMARY KEY,subject TEXT,method TEXT,auth_time TEXT,created_at TEXT,expires_at TEXT);` + SchemaSQL); e != nil { |
| + if _, e = db.Exec(`CREATE TABLE audit_events(id INTEGER PRIMARY KEY,actor TEXT,kind TEXT,record_id TEXT,at TEXT); CREATE TABLE members(address TEXT PRIMARY KEY,active INTEGER,session_epoch INTEGER,identity_key TEXT DEFAULT 'local-test-member'); CREATE TABLE sessions(token_hash TEXT PRIMARY KEY,subject TEXT,method TEXT,auth_time TEXT,created_at TEXT,expires_at TEXT);` + SchemaSQL); e != nil { |
| t.Fatal(e) |
| } |
| k, e := crypto.Generate() |
| @@ -104,7 +104,7 @@ func TestIDReceiptGuards(t *testing.T) { |
| func seedLocal(t *testing.T, s *Store, address string, now time.Time) string { |
| t.Helper() |
| - if _, e := s.DB.Exec("INSERT OR IGNORE INTO members VALUES(?,1,0)", address); e != nil { |
| + if _, e := s.DB.Exec("INSERT OR IGNORE INTO members(address,active,session_epoch,identity_key) VALUES(?,1,0,?)", address, s.binding(address)); e != nil { |
| t.Fatal(e) |
| } |
| token, hash, e := sessions.NewToken() |
| @@ -354,3 +354,64 @@ func TestIDReauthClockRollback(t *testing.T) { |
| t.Fatal("clock rollback revived reauthentication") |
| } |
| } |
| + |
| +func TestIDConflictingConfirmationBurnsProof(t *testing.T) { |
| + s, k := fixture(t) |
| + now := time.Now().Truncate(time.Second) |
| + establish(t, s, k, now) |
| + token, init := readyLink(t, s, now) |
| + secret, handle := receive(t, s, k, init, token, "pr_bbbbbbbbbbbbbbbbbbbbbbbbbb", now, now) |
| + proof, _, e := s.Finish(context.Background(), secret, handle, token, init, now) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if e = s.Confirm(context.Background(), proof, token, now); e == nil { |
| + t.Fatal("conflicting link overwritten") |
| + } |
| + var n int |
| + if e = s.DB.QueryRow("SELECT count(*) FROM home_link_flows WHERE stage='pending'").Scan(&n); e != nil || n != 0 { |
| + t.Fatal("rejected proof restored", n, e) |
| + } |
| +} |
| + |
| +func TestIDConcurrentUnlinkAndMint(t *testing.T) { |
| + s, k := fixture(t) |
| + now := time.Now().Truncate(time.Second) |
| + local, _ := establish(t, s, k, now) |
| + secret, handle := receive(t, s, k, "", "", "pr_aaaaaaaaaaaaaaaaaaaaaaaaaa", now, now) |
| + proof, e := s.BeginReauth(context.Background(), local, "unlink", now) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + fresh := seedLocal(t, s, "local-canary@example.invalid", now) |
| + if _, _, e = s.CompleteReauth(context.Background(), proof, fresh, now); e != nil { |
| + t.Fatal(e) |
| + } |
| + ready := make(chan struct{}) |
| + type minted struct { |
| + token string |
| + err error |
| + } |
| + result := make(chan minted, 1) |
| + unlinked := make(chan error, 1) |
| + go func() { |
| + <-ready |
| + token, _, err := s.Finish(context.Background(), secret, handle, "", "", now) |
| + result <- minted{token, err} |
| + }() |
| + go func() { <-ready; unlinked <- s.Unlink(context.Background(), proof, fresh, now) }() |
| + close(ready) |
| + got := <-result |
| + if e = <-unlinked; e != nil { |
| + t.Fatal(e) |
| + } |
| + if got.err == nil { |
| + if _, e = s.Session(context.Background(), got.token, now); e == nil { |
| + t.Fatal("concurrent mint survived unlink") |
| + } |
| + } |
| + var n int |
| + if e = s.DB.QueryRow("SELECT count(*) FROM sessions WHERE method=?", Method).Scan(&n); e != nil || n != 0 { |
| + t.Fatal("Home sessions survived unlink", n, e) |
| + } |
| +} |
diff --git a/internal/idtest/deletion_test.go b/internal/idtest/deletion_test.go| new file mode 100644 |
| index 00000000..bdc30c0e |
| --- /dev/null |
| +++ b/internal/idtest/deletion_test.go |
| @@ -0,0 +1,55 @@ |
| +package idtest |
| + |
| +import ( |
| + "net/url" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestIDDeletedAccountCannotBeRecreatedWithOldLink(t *testing.T) { |
| + f := newFixture(t, true) |
| + f.link(t) |
| + done, _ := f.exchange(t, nil, nil, person) |
| + session := cookie(t, done, "__Host-rastrillo_session") |
| + if _, e := f.db.Writer().Exec("DELETE FROM members WHERE address=?", address); e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e := f.db.Writer().Exec("INSERT INTO members(address,role,active,session_epoch) VALUES(?,'owner',1,?)", address, time.Now().Unix()); e != nil { |
| + t.Fatal(e) |
| + } |
| + if r := f.request("GET", "/work", "", nil, session); r.Code == 200 { |
| + t.Fatal("deleted account's Home session revived") |
| + } |
| + if r, _ := f.exchange(t, nil, nil, person); r.Code != 403 { |
| + t.Fatal("old Home link transferred to recreated account", r.Code) |
| + } |
| +} |
| +func TestIDAddressChangeNeedsFreshLink(t *testing.T) { |
| + f := newFixture(t, true) |
| + f.link(t) |
| + if _, e := f.db.Writer().Exec("UPDATE members SET address='changed@example.invalid' WHERE address=?", address); e != nil { |
| + t.Fatal(e) |
| + } |
| + if r, _ := f.exchange(t, nil, nil, person); r.Code != 403 { |
| + t.Fatal("address change preserved link", r.Code) |
| + } |
| +} |
| + |
| +func TestIDLocalReauthenticationUsesRealEmail(t *testing.T) { |
| + f := newFixture(t, true) |
| + old := f.local(t, address) |
| + start := f.request("POST", "/account/home/reauth", f.origin, url.Values{"purpose": {"link"}}, old) |
| + proof := cookie(t, start, "__Host-equipo-id-reauth") |
| + fresh := f.emailWith(t, start.Header().Get("Location"), old) |
| + if fresh.Value == old.Value { |
| + t.Fatal("local reauthentication reused session") |
| + } |
| + end := f.request("GET", "/account/home/reauth-complete", "", nil, proof, fresh) |
| + if end.Code != 303 || end.Header().Get("Location") != "/auth/home" { |
| + t.Fatal("local proof did not start Home leg", end.Code, end.Body.String()) |
| + } |
| + done, _ := f.exchange(t, cookie(t, end, "__Host-equipo-id-init"), fresh, person) |
| + if done.Code != 303 { |
| + t.Fatal("fresh email then Home", done.Code) |
| + } |
| +} |
diff --git a/internal/idtest/guards_test.go b/internal/idtest/guards_test.go| new file mode 100644 |
| index 00000000..f68ad78d |
| --- /dev/null |
| +++ b/internal/idtest/guards_test.go |
| @@ -0,0 +1,165 @@ |
| +package idtest |
| + |
| +import ( |
| + "bytes" |
| + "encoding/base64" |
| + "encoding/json" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo" |
| + "amadan.net/rastrillo/rastrillo/assertion" |
| + "amadan.net/rastrillo/rastrillo/crypto" |
| +) |
| + |
| +func TestIDCallbackGuardAndPendingNonce(t *testing.T) { |
| + for _, kind := range []string{"missing-nonce", "wrong-origin", "duplicate-origin", "duplicate-assertion", "wrong-method", "oversize", "replay"} { |
| + t.Run(kind, func(t *testing.T) { |
| + f := newFixture(t, true) |
| + start := f.request("GET", "/auth/home", "", nil) |
| + u, _ := url.Parse(start.Header().Get("Location")) |
| + nonce := u.Query().Get("nonce") |
| + if kind == "missing-nonce" { |
| + nonce, _ = assertion.RandomID() |
| + } |
| + token := f.signed(t, nonce, person, time.Now()) |
| + form := url.Values{"assertion": {token}} |
| + origin := f.issuer |
| + method := "POST" |
| + switch kind { |
| + case "wrong-origin": |
| + origin = "https://evil.example" |
| + case "duplicate-assertion": |
| + form.Add("assertion", token) |
| + case "wrong-method": |
| + method = "GET" |
| + case "oversize": |
| + form.Set("assertion", strings.Repeat("x", 13*1024)) |
| + } |
| + var outCode int |
| + if kind == "duplicate-origin" { |
| + req := httptest.NewRequest("POST", f.origin+"/auth/assertion", strings.NewReader(form.Encode())) |
| + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| + req.Header.Add("Origin", origin) |
| + req.Header.Add("Origin", origin) |
| + out := httptest.NewRecorder() |
| + f.h.ServeHTTP(out, req) |
| + outCode = out.Code |
| + } else { |
| + out := f.request(method, "/auth/assertion", origin, form) |
| + if kind == "replay" { |
| + if out.Code != 303 { |
| + t.Fatal(out.Code) |
| + } |
| + out = f.request(method, "/auth/assertion", origin, form) |
| + } |
| + outCode = out.Code |
| + } |
| + if outCode < 400 { |
| + t.Fatal("bad callback accepted", kind, outCode) |
| + } |
| + var n int |
| + if e := f.db.Writer().QueryRow("SELECT count(*) FROM oficina_handoff_inbox").Scan(&n); e != nil { |
| + t.Fatal(e) |
| + } |
| + want := 0 |
| + if kind == "replay" { |
| + want = 1 |
| + } |
| + if n != want { |
| + t.Fatal("invalid callback stored receipt", n) |
| + } |
| + }) |
| + } |
| +} |
| +func TestIDIdenticalAdmissionAndNoAccountSwitch(t *testing.T) { |
| + for _, kind := range []string{"removed", "epoch", "lookup-error", "other-account"} { |
| + t.Run(kind, func(t *testing.T) { |
| + f := newFixture(t, true) |
| + local := f.link(t) |
| + done, _ := f.exchange(t, nil, nil, person) |
| + home := cookie(t, done, "__Host-rastrillo_session") |
| + switch kind { |
| + case "removed": |
| + f.db.Writer().Exec("UPDATE members SET active=0") |
| + case "epoch": |
| + f.db.Writer().Exec("UPDATE members SET session_epoch=?", time.Now().Unix()+1) |
| + case "lookup-error": |
| + f.db.Writer().Exec("ALTER TABLE members RENAME TO unavailable_members") |
| + case "other-account": |
| + f.db.Writer().Exec("INSERT INTO members(address,role,active,session_epoch) VALUES('other@example.invalid','member',1,0)") |
| + other := f.local(t, "other@example.invalid") |
| + out, _ := f.exchange(t, nil, other, person) |
| + if out.Code < 400 { |
| + t.Fatal("Home replaced another account") |
| + } |
| + return |
| + } |
| + for _, session := range []*http.Cookie{local, home} { |
| + if out := f.request("GET", "/work", "", nil, session); out.Code == 200 { |
| + t.Fatal("inadmissible session accepted", kind) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| +func TestIDConfigurationPins(t *testing.T) { |
| + k, e := crypto.Generate() |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + manifest, _ := json.Marshal(map[string]string{"old": base64.StdEncoding.EncodeToString(k.SignPub())}) |
| + env := map[string]string{"EQUIPO_ORIGIN": appOrigin, "EQUIPO_INSTANCE_KEY": "config-key", "CARLOS_SMTP_HOST": "smtp.example", "CARLOS_SMTP_FROM": "sender@example.invalid"} |
| + get := func(k string) string { return env[k] } |
| + cfg, e := equipo.LoadConfig(get) |
| + if e != nil || cfg.Home != nil { |
| + t.Fatal("default on", e) |
| + } |
| + env["EQUIPO_HOME_ISSUER"] = issuer |
| + if _, e = equipo.LoadConfig(get); e == nil { |
| + t.Fatal("partial config accepted") |
| + } |
| + env["EQUIPO_HOME_CONSUMER_ID"] = "equipo" |
| + env["EQUIPO_HOME_KEYS_BASE64"] = base64.StdEncoding.EncodeToString(manifest) |
| + env["EQUIPO_HOME_DEK_BASE64"] = base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, 32)) |
| + cfg, e = equipo.LoadConfig(get) |
| + if e != nil || cfg.Home == nil { |
| + t.Fatal("valid pins", e) |
| + } |
| + newer, e := crypto.Generate() |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + keys := map[string][]byte{"old": k.SignPub(), "new": newer.SignPub()} |
| + now := time.Now() |
| + id, _ := assertion.RandomID() |
| + nonce, _ := assertion.RandomID() |
| + claims := assertion.Claims{Version: 1, KeyID: "new", Issuer: issuer, Audience: appOrigin, Subject: person, ID: id, Nonce: nonce, IssuedAt: now.Unix(), ExpiresAt: now.Unix() + 120, AuthTime: now.Unix()} |
| + token, e := assertion.Sign(newer, claims) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + old, e := assertion.NewVerifier(issuer, appOrigin, cfg.Home.Keys) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e = old.Verify(token, now); e == nil { |
| + t.Fatal("unknown pin accepted") |
| + } |
| + both, e := assertion.NewVerifier(issuer, appOrigin, keys) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e = both.Verify(token, now); e != nil { |
| + t.Fatal("rotation pins", e) |
| + } |
| + manifest = []byte(`{"old":"bad","old":"bad"}`) |
| + env["EQUIPO_HOME_KEYS_BASE64"] = base64.StdEncoding.EncodeToString(manifest) |
| + if _, e = equipo.LoadConfig(get); e == nil { |
| + t.Fatal("duplicate pin accepted") |
| + } |
| +} |
diff --git a/internal/idtest/id_browser_test.go b/internal/idtest/id_browser_test.go| index dc574091..c3efee98 100644 |
| --- a/internal/idtest/id_browser_test.go |
| +++ b/internal/idtest/id_browser_test.go |
| @@ -99,37 +99,41 @@ func TestBrowserOficinaIDDoor(t *testing.T) { |
| return e |
| })) |
| run(chromedp.Navigate(origin+"/signin"), browsertest.Wait(`!!document.querySelector('a[href^="/auth/home"]')`)) |
| - for _, width := range []int64{390, 1280} { |
| - run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| - _, e := cdp.Call(ctx, target, emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: width, Height: 900, DeviceScaleFactor: 1, Mobile: width == 390}) |
| - if e != nil { |
| - return e |
| - } |
| - overflow, e := chromedp.Evaluate[bool](`document.documentElement.scrollWidth>innerWidth`)(ctx, target) |
| - if e != nil { |
| - return e |
| - } |
| - if overflow { |
| - return fmt.Errorf("door overflows at %d", width) |
| - } |
| - if dir := os.Getenv("EQUIPO_BROWSER_ARTIFACTS"); dir != "" { |
| - shot, e := chromedp.CaptureScreenshot()(ctx, target) |
| + capture := func(name string) { |
| + for _, width := range []int64{390, 1280} { |
| + run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| + _, e := cdp.Call(ctx, target, emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: width, Height: 900, DeviceScaleFactor: 1, Mobile: width == 390}) |
| if e != nil { |
| return e |
| } |
| - if e = os.MkdirAll(dir, 0700); e != nil { |
| + overflow, e := chromedp.Evaluate[bool](`document.documentElement.scrollWidth>innerWidth`)(ctx, target) |
| + if e != nil { |
| return e |
| } |
| - return os.WriteFile(filepath.Join(dir, fmt.Sprintf("oficina-id-door-%d.png", width)), shot, 0600) |
| - } |
| - return nil |
| - })) |
| + if overflow { |
| + return fmt.Errorf("%s overflows at %d", name, width) |
| + } |
| + if dir := os.Getenv("EQUIPO_BROWSER_ARTIFACTS"); dir != "" { |
| + shot, e := chromedp.CaptureScreenshot()(ctx, target) |
| + if e != nil { |
| + return e |
| + } |
| + if e = os.MkdirAll(dir, 0700); e != nil { |
| + return e |
| + } |
| + return os.WriteFile(filepath.Join(dir, fmt.Sprintf("%s-%d.png", name, width)), shot, 0600) |
| + } |
| + return nil |
| + })) |
| + } |
| } |
| + capture("oficina-id-door") |
| run(browsertest.Click(`a[href^="/auth/home"]`), browsertest.Wait(`location.origin==="https://id.example.org" && !!document.querySelector('#continue')`), browsertest.Click("#continue"), browsertest.Wait(`!!document.querySelector('#return')`), browsertest.Click("#return"), browsertest.Wait(`location.origin==="https://equipo.example.test" && location.pathname==="/conversation"`)) |
| if callbacks.Load() != 1 { |
| t.Fatal("full callback did not run", callbacks.Load()) |
| } |
| run(chromedp.Navigate(origin+"/conversation/settings/oficina-id"), browsertest.Wait(`document.body.textContent.includes("pr_aaaaaaaaaaaaaaaaaaaaaaaaaa")`)) |
| + capture("oficina-id-settings") |
| run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| body, e := chromedp.Evaluate[string](`document.body.textContent`)(ctx, target) |
| if e != nil { |
diff --git a/internal/idtest/id_test.go b/internal/idtest/id_test.go| index 36765c9e..9080e26d 100644 |
| --- a/internal/idtest/id_test.go |
| +++ b/internal/idtest/id_test.go |
| @@ -305,13 +305,14 @@ func fields(body, action string) url.Values { |
| } |
| return v |
| } |
| -func (f *fixture) email(t *testing.T) { |
| +func (f *fixture) email(t *testing.T) { f.emailWith(t, "/signin?force=1", nil) } |
| +func (f *fixture) emailWith(t *testing.T, start string, original *http.Cookie) *http.Cookie { |
| t.Helper() |
| - page := f.request("GET", "/signin?force=1", "", nil) |
| + page := f.request("GET", start, "", nil, original) |
| form := fields(page.Body.String(), "/auth/begin") |
| form.Set("address", address) |
| time.Sleep(pow.DefaultMinAge + 20*time.Millisecond) |
| - begin := f.request("POST", "/auth/begin", f.origin, form) |
| + begin := f.request("POST", "/auth/begin", f.origin, form, original) |
| if begin.Code != 303 { |
| t.Fatal("email begin", begin.Code, begin.Body.String()) |
| } |
| @@ -332,19 +333,25 @@ func (f *fixture) email(t *testing.T) { |
| if target == "" { |
| t.Fatal("no emailed link") |
| } |
| - confirm := f.request("GET", target, "", nil) |
| + jar := mergeCookies([]*http.Cookie{original}, page.Result().Cookies(), begin.Result().Cookies()) |
| + confirm := f.request("GET", target, "", nil, jar...) |
| if confirm.Code != 200 { |
| t.Fatal("email confirmation", confirm.Code) |
| } |
| values := fields(confirm.Body.String(), "/auth/verify") |
| - done := f.request("POST", "/auth/verify", f.origin, values, confirm.Result().Cookies()...) |
| + done := f.request("POST", "/auth/verify", f.origin, values, mergeCookies(jar, confirm.Result().Cookies())...) |
| if done.Code != 303 { |
| t.Fatal("email verify", done.Code, done.Body.String()) |
| } |
| + startURL, _ := url.Parse(start) |
| + if back := startURL.Query().Get("return_to"); back != "" && done.Header().Get("Location") != back { |
| + t.Fatal("email lost return target", done.Header().Get("Location")) |
| + } |
| local := cookie(t, done, "__Host-rastrillo_session") |
| if r := f.request("GET", "/work", "", nil, local); r.Code != 200 { |
| t.Fatal("local admission", r.Code) |
| } |
| + return local |
| } |
| func TestIDHangingHomeLocalSignoutAndEmail(t *testing.T) { |
| entered := make(chan struct{}, 1) |
| @@ -361,8 +368,16 @@ func TestIDHangingHomeLocalSignoutAndEmail(t *testing.T) { |
| }() |
| <-entered |
| u, _ := url.Parse(home.URL) |
| - host, port, _ := net.SplitHostPort(u.Host) |
| - _ = host |
| + _, port, _ := net.SplitHostPort(u.Host) |
| + transport := home.Client().Transport.(*http.Transport).Clone() |
| + transport.TLSClientConfig = transport.TLSClientConfig.Clone() |
| + transport.TLSClientConfig.InsecureSkipVerify = true // The test issuer is served only on loopback. |
| + transport.DialContext = func(ctx context.Context, network, _ string) (net.Conn, error) { |
| + return (&net.Dialer{}).DialContext(ctx, network, u.Host) |
| + } |
| + previous := http.DefaultClient |
| + http.DefaultClient = &http.Client{Transport: transport, Timeout: 2 * time.Second} |
| + defer func() { http.DefaultClient = previous; transport.CloseIdleConnections() }() |
| f := fixtureAt(t, true, appOrigin, "https://id.example:"+port) |
| f.link(t) |
| done, _ := f.exchange(t, nil, nil, person) |
| @@ -380,6 +395,17 @@ func TestIDHangingHomeLocalSignoutAndEmail(t *testing.T) { |
| t.Fatal("session not revoked") |
| } |
| f.email(t) |
| + localForUnlink := f.local(t, address) |
| + reauth := f.request("POST", "/account/home/reauth", f.origin, url.Values{"purpose": {"unlink"}}, localForUnlink) |
| + fresh := f.local(t, address) |
| + proof := cookie(t, reauth, "__Host-equipo-id-reauth") |
| + if r := f.request("GET", "/account/home/reauth-complete", "", nil, fresh, proof); r.Code != 303 { |
| + t.Fatal("outage reauth", r.Code) |
| + } |
| + before = time.Now() |
| + if r := f.request("POST", "/account/home/unlink", f.origin, nil, fresh, proof); r.Code != 303 || time.Since(before) > time.Second { |
| + t.Fatal("unlink depends on Home", r.Code) |
| + } |
| local := f.local(t, address) |
| out = f.request("POST", "/signout", f.origin, nil, local) |
| landing = f.request("GET", "/signed-out", "", nil, out.Result().Cookies()...) |
| @@ -387,3 +413,24 @@ func TestIDHangingHomeLocalSignoutAndEmail(t *testing.T) { |
| t.Fatal("local session offered Home hop") |
| } |
| } |
| + |
| +func mergeCookies(groups ...[]*http.Cookie) []*http.Cookie { |
| + jar := map[string]*http.Cookie{} |
| + for _, group := range groups { |
| + for _, c := range group { |
| + if c == nil { |
| + continue |
| + } |
| + if c.MaxAge < 0 { |
| + delete(jar, c.Name) |
| + } else { |
| + jar[c.Name] = c |
| + } |
| + } |
| + } |
| + var out []*http.Cookie |
| + for _, c := range jar { |
| + out = append(out, c) |
| + } |
| + return out |
| +} |
diff --git a/internal/idtest/main_test.go b/internal/idtest/main_test.go| new file mode 100644 |
| index 00000000..c4947702 |
| --- /dev/null |
| +++ b/internal/idtest/main_test.go |
| @@ -0,0 +1,9 @@ |
| +package idtest |
| + |
| +import ( |
| + "amadan.net/rastrillo/rastrillo/budget" |
| + "os" |
| + "testing" |
| +) |
| + |
| +func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } |