Skip to content

Commit

Permalink
Bumped v10.9.0
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <[email protected]>
  • Loading branch information
mcollina committed May 21, 2024
1 parent 0495ce5 commit 742e1dc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions lib/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module.exports = class Cookie {
this.partitioned = cookie.partitioned
this._expires = null

if(cookie.expires) {
if (cookie.expires) {
this.originalExpires = new Date(cookie.expires)
}

if (originalMaxAge) {
this.maxAge = originalMaxAge
} else if (cookie.expires) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fastify/session",
"version": "10.8.0",
"version": "10.9.0",
"description": "a session plugin for fastify",
"main": "lib/fastifySession.js",
"type": "commonjs",
Expand Down
82 changes: 41 additions & 41 deletions test/expiration.test.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
"use strict";
'use strict'

const test = require("tap").test;
const { buildFastify, DEFAULT_SECRET } = require("./util");
const { setTimeout } = require("node:timers/promises");
const test = require('tap').test
const { buildFastify, DEFAULT_SECRET } = require('./util')
const { setTimeout } = require('node:timers/promises')

test("sessions should be deleted if expired", async (t) => {
t.plan(5);
test('sessions should be deleted if expired', async (t) => {
t.plan(5)

const sessions = {};
const sessions = {}
const options = {
secret: DEFAULT_SECRET,
store: {
get(id, cb) {
t.pass("session was restored");
cb(null, sessions[id]);
get (id, cb) {
t.pass('session was restored')
cb(null, sessions[id])
},
set(id, session, cb) {
sessions[id] = session;
cb();
},
destroy(id, cb) {
t.pass("expired session is destroyed");
cb();
set (id, session, cb) {
sessions[id] = session
cb()
},
destroy (id, cb) {
t.pass('expired session is destroyed')
cb()
}
},
cookie: { maxAge: 1000, secure: false },
};
cookie: { maxAge: 1000, secure: false }
}

const fastify = await buildFastify((request, reply) => {
reply.send(200);
}, options);
reply.send(200)
}, options)
t.teardown(() => {
fastify.close();
});
fastify.close()
})

let response;
let response
response = await fastify.inject({
url: "/",
});
url: '/'
})

const initialSession = response.headers["set-cookie"]
.split(" ")[0]
.replace(";", "");
t.ok(initialSession.startsWith("sessionId="));
const initialSession = response.headers['set-cookie']
.split(' ')[0]
.replace(';', '')
t.ok(initialSession.startsWith('sessionId='))

// Wait for the cookie to expire
await setTimeout(2000);
await setTimeout(2000)

response = await fastify.inject({
url: "/",
url: '/',
headers: {
Cookie: initialSession,
},
});
Cookie: initialSession
}
})

const endingSession = response.headers["set-cookie"]
.split(" ")[0]
.replace(";", "");
t.ok(endingSession.startsWith("sessionId="));
const endingSession = response.headers['set-cookie']
.split(' ')[0]
.replace(';', '')
t.ok(endingSession.startsWith('sessionId='))

t.not(initialSession, endingSession);
});
t.not(initialSession, endingSession)
})

0 comments on commit 742e1dc

Please sign in to comment.