Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nichoth committed Nov 3, 2024
1 parent 553e25f commit ef51764
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ Create a string suitable for use as a cookie. Sign the given data with a secret

>
> [!NOTE]
> This will add default values for additional cookie attributes -- `Max-Age=604800` (1 week), `Path=/`, `HttpOnly`, `Secure`, `SameSite=Lax`.
> This will add default values for additional cookie attributes.
> ```
> session=N6bimY9qCPv7HdQ8NX1w6gUpuCU4tNawWwY0EvL3smAeyJoZWxsbyI6IndvcmxkIn0; Max-Age=604800; Path=/; HttpOnly; Secure; SameSite=Lax
> ```
>
These environment variables can be used to set the cookie attributes:
Expand Down
9 changes: 5 additions & 4 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test('verify an invalid session', async t => {
let cookie
test('create a cookie', async t => {
cookie = await createCookie({ hello: 'world' }, SECRET_KEY)
console.log('**cookie**', cookie)
t.equal(typeof cookie, 'string', 'should return a string')
t.ok(cookie.includes('session='), 'should include the default session name')
})
Expand All @@ -43,7 +44,7 @@ test('Create some headers', t => {
const headers2 = new Headers()
const headers3 = setCookie(cookie, headers2)
t.equal(headers2, headers3, 'should patch a given Headers instance')
t.ok(parseCookie(headers2.getSetCookie()[0]).session,
t.ok(parseCookie(headers2.getSetCookie()[0])!.session,
'should patch the headers we passsed in')
})

Expand All @@ -68,14 +69,14 @@ test('parse a cookie', async t => {
SameSite: 'Lax'
}, 'should parse the cookie string')

t.ok(await verifySessionString(parsed.session, SECRET_KEY),
t.ok(await verifySessionString(parsed!.session, SECRET_KEY),
'should verify the session token')
})

test('parse the session string', async t => {
t.ok(await verifySessionString(parsed.session, SECRET_KEY),
t.ok(await verifySessionString(parsed!.session, SECRET_KEY),
'should be a valid session')
const session = parseSession(parsed.session)
const session = parseSession(parsed!.session)
t.deepEqual(session, {
hello: 'world'
}, 'should parse to the same data we passed in')
Expand Down

0 comments on commit ef51764

Please sign in to comment.