-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Matt Kane <[email protected]> Co-authored-by: Emanuele Stoppa <[email protected]>
- Loading branch information
1 parent
8809b85
commit 440d8a5
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fixes a bug where the session ID wasn't correctly regenerated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import assert from 'node:assert/strict'; | ||
import { before, describe, it } from 'node:test'; | ||
import testAdapter from './test-adapter.js'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Astro.session', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/sessions/', | ||
output: 'server', | ||
adapter: testAdapter(), | ||
}); | ||
}); | ||
|
||
describe('Production', () => { | ||
let app; | ||
before(async () => { | ||
await fixture.build(); | ||
app = await fixture.loadTestAdapterApp(); | ||
}); | ||
|
||
async function fetchResponse(path, requestInit) { | ||
const request = new Request('http://example.com' + path, requestInit); | ||
const response = await app.render(request); | ||
return response; | ||
} | ||
|
||
it('can regenerate session cookies upon request', async () => { | ||
const firstResponse = await fetchResponse('/regenerate', { method: 'GET' }); | ||
const firstHeaders = Array.from(app.setCookieHeaders(firstResponse)); | ||
const firstSessionId = firstHeaders[0].split(';')[0].split('=')[1]; | ||
|
||
const secondResponse = await fetchResponse('/regenerate', { | ||
method: 'GET', | ||
headers: { | ||
cookie: `astro-session=${firstSessionId}`, | ||
}, | ||
}); | ||
const secondHeaders = Array.from(app.setCookieHeaders(secondResponse)); | ||
const secondSessionId = secondHeaders[0].split(';')[0].split('=')[1]; | ||
assert.notEqual(firstSessionId, secondSessionId); | ||
}); | ||
}); | ||
}); |