Test that a signed-in cross-site confirm leaves the dead link as it was
Astra's nit on ebd3b8f: TestOficinaOldLinkClearedOnlyByTheMember now also has the owner freshly signed in by email while another site posts the confirm in their browser. Each refused case asserts the 403 and that the stored row (subject, member number, binding) is exactly as before, so a change that cleared the dead link first and refused afterwards would fail. make ci: 16 packages ran, 0 failed; test step 8.0s of 60s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+31
−3
internal/webtest/oficina_origin_test.go+31 −3
diff --git a/internal/webtest/oficina_origin_test.go b/internal/webtest/oficina_origin_test.go| index 5a51d89..74c6fba 100644 |
| --- a/internal/webtest/oficina_origin_test.go |
| +++ b/internal/webtest/oficina_origin_test.go |
| @@ -3,6 +3,7 @@ package webtest |
| import ( |
| "bytes" |
| "context" |
| + "fmt" |
| "net/http" |
| "net/url" |
| "strings" |
| @@ -167,15 +168,42 @@ func TestOficinaOldLinkOfAnotherMemberStays(t *testing.T) { |
| func TestOficinaOldLinkClearedOnlyByTheMember(t *testing.T) { |
| a := newHomeApp(t) |
| a.linkAtOldOrigin(ownerAddress, "subject-owner") |
| + before := a.linkRow(ownerAddress) |
| + unchanged := func(what string) { |
| + t.Helper() |
| + if after := a.linkRow(ownerAddress); after != before { |
| + t.Fatalf("%s changed the dead link: %q, was %q", what, after, before) |
| + } |
| + } |
| if r := a.postFrom(homeIssuer, "/account/home/confirm", url.Values{}); r.Code != http.StatusForbidden { |
| - t.Fatalf("cross-site confirm: %d", r.Code) |
| + t.Fatalf("signed-out cross-site confirm: %d", r.Code) |
| } |
| + unchanged("a signed-out cross-site confirm") |
| if r := a.post("/account/home/confirm", nil); r.Code == http.StatusOK { |
| t.Fatalf("signed-out confirm: %d", r.Code) |
| } |
| - if n := a.linkRows(ownerAddress); n != 1 { |
| - t.Fatalf("a refused request cleared the link: %d", n) |
| + unchanged("a signed-out confirm") |
| + // The owner freshly signed in by email, and a page on another site |
| + // posting the confirm in their browser: refused before anything is |
| + // cleared. |
| + a.signedInOwner() |
| + if r := a.postFrom(homeIssuer, "/account/home/confirm", url.Values{}); r.Code != http.StatusForbidden { |
| + t.Fatalf("signed-in cross-site confirm: %d", r.Code) |
| } |
| + unchanged("a signed-in cross-site confirm") |
| +} |
| + |
| +// linkRow is the Oficina ID link naming email's member, as stored. |
| +func (a *testApp) linkRow(email string) string { |
| + a.t.Helper() |
| + var subject, binding string |
| + var person int64 |
| + if err := a.DB.QueryRow(`SELECT l.subject, l.person_id, l.person_binding FROM home_identity_links l |
| + JOIN member_numbers n ON n.number = l.person_id JOIN members m ON m.id = n.member_id WHERE m.email = ?`, email). |
| + Scan(&subject, &person, &binding); err != nil { |
| + a.t.Fatalf("link row for %s: %v", email, err) |
| + } |
| + return fmt.Sprintf("%s/%d/%s", subject, person, binding) |
| } |
| // An email sign-in older than connect's five minutes clears nothing. |