This repository has been archived by the owner on Feb 10, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
126 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
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
{ | ||
"extends": "astro/tsconfigs/base", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"~/assets/*": ["src/assets/*"] | ||
}, | ||
}, | ||
"include": [".astro/types.d.ts", "**/*"], | ||
"exclude": ["dist"] | ||
} |
This file was deleted.
Oops, something went wrong.
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,98 @@ | ||
import assert from 'node:assert/strict'; | ||
import { before, describe, it } from 'node:test'; | ||
import * as devalue from 'devalue'; | ||
import nodejs from '../dist/index.js'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Astro.session', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/session/', | ||
output: 'server', | ||
adapter: nodejs({ | ||
mode: 'standalone', | ||
experimentalSessions: true, | ||
}), | ||
}); | ||
}); | ||
|
||
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); | ||
}); | ||
|
||
it('can save session data by value', async () => { | ||
const firstResponse = await fetchResponse('/update', { method: 'GET' }); | ||
const firstValue = await firstResponse.json(); | ||
assert.equal(firstValue.previousValue, 'none'); | ||
|
||
const firstHeaders = Array.from(app.setCookieHeaders(firstResponse)); | ||
const firstSessionId = firstHeaders[0].split(';')[0].split('=')[1]; | ||
const secondResponse = await fetchResponse('/update', { | ||
method: 'GET', | ||
headers: { | ||
cookie: `astro-session=${firstSessionId}`, | ||
}, | ||
}); | ||
const secondValue = await secondResponse.json(); | ||
assert.equal(secondValue.previousValue, 'expected'); | ||
}); | ||
|
||
it('can save and restore URLs in session data', async () => { | ||
const firstResponse = await fetchResponse('/_actions/addUrl', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ favoriteUrl: 'https://domain.invalid' }), | ||
}); | ||
|
||
assert.equal(firstResponse.ok, true); | ||
const firstHeaders = Array.from(app.setCookieHeaders(firstResponse)); | ||
const firstSessionId = firstHeaders[0].split(';')[0].split('=')[1]; | ||
|
||
const data = devalue.parse(await firstResponse.text()); | ||
assert.equal(data.message, 'Favorite URL set to https://domain.invalid/ from nothing'); | ||
const secondResponse = await fetchResponse('/_actions/addUrl', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
cookie: `astro-session=${firstSessionId}`, | ||
}, | ||
body: JSON.stringify({ favoriteUrl: 'https://example.com' }), | ||
}); | ||
const secondData = devalue.parse(await secondResponse.text()); | ||
assert.equal( | ||
secondData.message, | ||
'Favorite URL set to https://example.com/ from https://domain.invalid/' | ||
); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.