Skip to content

test: cover logout edge cases - #104

Closed
mroderick wants to merge 3 commits into
test/cookie-attributesfrom
test/logout-edge-cases
Closed

mroderick wants to merge 3 commits into
test/cookie-attributesfrom
test/logout-edge-cases

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Three logout paths had no coverage. This adds a test for each, stacked on #103 because it extends the test file that PR introduces.

  • GET /logout clears the same three cookies as POST /logout. The handler is registered for both verbs, and only POST was covered.
  • forwardCookies keeps a Set-Cookie that is already on the response instead of replacing it. This pins the append behaviour that fix: forward every set-cookie header on logout #103 relies on, and documents the one residual risk the security review raised: appending preserves anything already set.
  • logout redirects when signOut returns no headers, covering the if (status.headers) guard in src/app/handlers/logout.js.

Each test fails when its target is removed. Dropping { append: true } fails the first two; removing the status.headers guard fails the third.

Review notes

Nothing risky here: test-only, no production change. The third test builds a minimal auth object with getSession and signOut and passes it to createApp, which already accepts an injected instance, so no module mocking is involved.

Base is test/cookie-attributes, so this merges after #103.

forwardCookies called c.header once per cookie. Hono keeps only the last
value of a repeated header, so the three clearing cookies from signOut
collapsed into better-auth.dont_remember and the browser kept the stale
session cookies.

Pass append: true so each Set-Cookie survives as its own header. The new
integration test asserts that all three arrive with Max-Age=0, Path=/,
HttpOnly and SameSite=Lax.
readSetCookie returned only the first Set-Cookie entry when headers
arrived in array shape, and magicLinkHeaders returned an undefined
headers object that surfaced later as a generic assertion failure.
Both are test-only diagnostics.
Three paths had no coverage: the GET verb on /logout, a Set-Cookie
already present on the response before forwardCookies appends to it,
and a signOut that returns no headers at all. Each fails when its
target is removed.
@mroderick
mroderick added this pull request to stack #106 November 11, 2026 16:31
@mroderick
mroderick marked this pull request as ready for review November 11, 2026 16:31
import { forwardCookies } from "../../src/app/utils/cookies.js";
import { authorizeParams } from "../helpers/oauth-flow.js";

const SESSION_COOKIE = "better-auth.session_token";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a q about this in the other PR, I think if we really have to do this, then we should probably unify this?

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to get coverage!

mroderick added a commit that referenced this pull request Nov 12, 2026
/logout answers both verbs from the same handler, but only POST was
covered. Salvaged from #104, whose other two tests targeted code #107
deleted.
@mroderick

Copy link
Copy Markdown
Collaborator Author

Not needed in this form. Two of the three tests pin code #107 deleted, and the other is salvaged into #108.

#107 merged into test/cookie-attributes rather than main, so none of this was on main until #108, which lands the fix and the surviving test together.

@mroderick mroderick closed this Nov 12, 2026
@mroderick
mroderick deleted the test/logout-edge-cases branch November 12, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants