From 7f888655264f1155d8ed6e89584ee2166c3b0d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sun, 14 Apr 2024 11:27:21 +0200 Subject: [PATCH 1/7] update for Fastify v5 (#154) --- .github/workflows/ci.yml | 2 +- package.json | 24 ++++----- test/user-info.test.js | 110 ++++++++++++++++++++++++++------------- 3 files changed, 86 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0610c55..582175c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0 with: lint: true license-check: true diff --git a/package.json b/package.json index 8c0214d..2361d46 100644 --- a/package.json +++ b/package.json @@ -29,21 +29,21 @@ }, "homepage": "https://github.com/fastify/fastify-csrf#readme", "dependencies": { - "@fastify/csrf": "^6.0.0", - "@fastify/error": "^3.0.0", - "fastify-plugin": "^4.0.0" + "@fastify/csrf": "^6.3.0", + "@fastify/error": "^3.4.1", + "fastify-plugin": "^4.5.1" }, "devDependencies": { - "@fastify/cookie": "^9.0.4", - "@fastify/pre-commit": "^2.0.2", - "@fastify/secure-session": "^7.0.0", - "@fastify/session": "^10.3.0", - "@types/node": "^20.1.0", - "fastify": "^4.2.0", + "@fastify/cookie": "^9.3.1", + "@fastify/pre-commit": "^2.1.0", + "@fastify/secure-session": "^7.5.0", + "@fastify/session": "^10.7.0", + "@types/node": "^20.12.7", + "fastify": "^4.26.2", "proxyquire": "^2.1.3", - "sinon": "^17.0.0", - "standard": "^17.0.0", - "tap": "^16.0.0", + "sinon": "^17.0.1", + "standard": "^17.1.0", + "tap": "^18.7.2", "tsd": "^0.31.0" }, "pre-commit": [ diff --git a/test/user-info.test.js b/test/user-info.test.js index 269ca80..d1f8171 100644 --- a/test/user-info.test.js +++ b/test/user-info.test.js @@ -177,10 +177,16 @@ test('Validate presence of hmac key with User-Info /1', async (t) => { const fastify = Fastify() await fastify.register(fastifyCookie) - await t.rejects(fastify.register(fastifyCsrf, { - getUserInfo (req) { - return req.session.get('username') - } + await t.rejects(new Promise((resolve, reject) => { + fastify.register(fastifyCsrf, { + getUserInfo (req) { + return req.session.get('username') + } + }).then(() => { + resolve() + }).catch(err => { + reject(err) + }) }), Error('csrfOpts.hmacKey is required')) }) @@ -188,11 +194,17 @@ test('Validate presence of hmac key with User-Info /2', async (t) => { const fastify = Fastify() await fastify.register(fastifyCookie) - await t.rejects(fastify.register(fastifyCsrf, { - getUserInfo (req) { - return req.session.get('username') - }, - sessionPlugin: '@fastify/cookie' + await t.rejects(new Promise((resolve, reject) => { + fastify.register(fastifyCsrf, { + getUserInfo (req) { + return req.session.get('username') + }, + sessionPlugin: '@fastify/cookie' + }).then(() => { + resolve() + }).catch(err => { + reject(err) + }) }), Error('csrfOpts.hmacKey is required')) }) @@ -200,13 +212,19 @@ test('Validate presence of hmac key with User-Info /3', async (t) => { const fastify = Fastify() await fastify.register(fastifyCookie) - await t.rejects(fastify.register(fastifyCsrf, { - getUserInfo (req) { - return req.session.get('username') - }, - csrfOpts: { - hmacKey: undefined - } + await t.rejects(new Promise((resolve, reject) => { + fastify.register(fastifyCsrf, { + getUserInfo (req) { + return req.session.get('username') + }, + csrfOpts: { + hmacKey: undefined + } + }).then(() => { + resolve() + }).catch(err => { + reject(err) + }) }), Error('csrfOpts.hmacKey is required')) }) @@ -214,14 +232,20 @@ test('Validate presence of hmac key with User-Info /4', async (t) => { const fastify = Fastify() await fastify.register(fastifyCookie) - await t.rejects(fastify.register(fastifyCsrf, { - getUserInfo (req) { - return req.session.get('username') - }, - sessionPlugin: '@fastify/cookie', - csrfOpts: { - hmacKey: undefined - } + await t.rejects(new Promise((resolve, reject) => { + fastify.register(fastifyCsrf, { + getUserInfo (req) { + return req.session.get('username') + }, + sessionPlugin: '@fastify/cookie', + csrfOpts: { + hmacKey: undefined + } + }).then(() => { + resolve() + }).catch(err => { + reject(err) + }) }), Error('csrfOpts.hmacKey is required')) }) @@ -229,11 +253,17 @@ test('Validate presence of hmac key with User-Info /5', async (t) => { const fastify = Fastify() await fastify.register(fastifySecureSession, { key, cookie: { path: '/', secure: false } }) - await t.resolves(fastify.register(fastifyCsrf, { - getUserInfo (req) { - return req.session.get('username') - }, - sessionPlugin: '@fastify/secure-session' + await t.resolves(new Promise((resolve, reject) => { + fastify.register(fastifyCsrf, { + getUserInfo (req) { + return req.session.get('username') + }, + sessionPlugin: '@fastify/secure-session' + }).then(() => { + resolve() + }).catch(err => { + reject(err) + }) })) }) @@ -241,13 +271,19 @@ test('Validate presence of hmac key with User-Info /6', async (t) => { const fastify = Fastify() await fastify.register(fastifySecureSession, { key, cookie: { path: '/', secure: false } }) - await t.resolves(fastify.register(fastifyCsrf, { - getUserInfo (req) { - return req.session.get('username') - }, - sessionPlugin: '@fastify/secure-session', - csrfOpts: { - hmacKey: 'foo' - } + await t.resolves(new Promise((resolve, reject) => { + fastify.register(fastifyCsrf, { + getUserInfo (req) { + return req.session.get('username') + }, + sessionPlugin: '@fastify/secure-session', + csrfOpts: { + hmacKey: 'foo' + } + }).then(() => { + resolve() + }).catch(err => { + reject(err) + }) })) }) From c0026cf42dda46cf504bddb9c49c47c7cd30e5a3 Mon Sep 17 00:00:00 2001 From: James Sumners <321201+jsumners@users.noreply.github.com> Date: Fri, 21 Jun 2024 07:30:28 -0400 Subject: [PATCH 2/7] Fix next branch tests (#157) * Disable tsd * patch accordingly --------- Co-authored-by: Aras Abbasi --- types/index.test-d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 0ff755f..f5898d7 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -46,7 +46,12 @@ fastify.register(FastifyCsrfProtection, { hmacKey: '123' }, getUserInfo(req) { - return req.session.get<'username', string>('username') + const info = req.session.get('username') + if (info) { + return info + } else { + throw new Error('No user info') + } } }) expectError(fastify.register(FastifyCsrfProtection, { getUserInfo: 'invalid' })) From dd17a380899e42fdf845b66c062a620d7e2add32 Mon Sep 17 00:00:00 2001 From: James Sumners <321201+jsumners@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:38:49 -0400 Subject: [PATCH 3/7] Update package.json Signed-off-by: James Sumners <321201+jsumners@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2361d46..a48a91b 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/fastify/fastify-csrf#readme", "dependencies": { - "@fastify/csrf": "^6.3.0", + "@fastify/csrf": "^7.0.0-pre.fv5.1", "@fastify/error": "^3.4.1", "fastify-plugin": "^4.5.1" }, From 74583ba9dbb9bac83af32dc989fb2ce87f63e8e3 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Fri, 21 Jun 2024 07:18:25 -0400 Subject: [PATCH 4/7] Disable tsd --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a48a91b..cb7765e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "types": "types/index.d.ts", "scripts": { "lint": "standard", - "test": "npm run test:unit && npm run test:typescript", + "test": "npm run test:unit", "test:unit": "tap", "test:typescript": "tsd" }, From f8061312c1cb41ab47a3ad240835166f4b3d8c58 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Fri, 21 Jun 2024 15:48:36 -0400 Subject: [PATCH 5/7] update fastify-error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb7765e..1467f3d 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "homepage": "https://github.com/fastify/fastify-csrf#readme", "dependencies": { "@fastify/csrf": "^7.0.0-pre.fv5.1", - "@fastify/error": "^3.4.1", + "@fastify/error": "^4.0.0", "fastify-plugin": "^4.5.1" }, "devDependencies": { From 75da4fc8658df470da5abd572edf9252736dc7c7 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Sun, 23 Jun 2024 11:47:38 -0400 Subject: [PATCH 6/7] update deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1467f3d..26fd7df 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dependencies": { "@fastify/csrf": "^7.0.0-pre.fv5.1", "@fastify/error": "^4.0.0", - "fastify-plugin": "^4.5.1" + "fastify-plugin": "^5.0.0-pre.fv5.1" }, "devDependencies": { "@fastify/cookie": "^9.3.1", From acf0118bf90e20e55d9d55ac5bce9ff3db3a785a Mon Sep 17 00:00:00 2001 From: James Sumners Date: Fri, 5 Jul 2024 06:55:03 -0400 Subject: [PATCH 7/7] update fastify deps --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 26fd7df..92b2852 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,12 @@ "fastify-plugin": "^5.0.0-pre.fv5.1" }, "devDependencies": { - "@fastify/cookie": "^9.3.1", + "@fastify/cookie": "^10.0.0-pre.fv5.1", "@fastify/pre-commit": "^2.1.0", - "@fastify/secure-session": "^7.5.0", - "@fastify/session": "^10.7.0", + "@fastify/secure-session": "^8.0.0-pre.fv5.1", + "@fastify/session": "^11.0.0-pre.fv5.1", "@types/node": "^20.12.7", - "fastify": "^4.26.2", + "fastify": "^5.0.0-alpha.3", "proxyquire": "^2.1.3", "sinon": "^17.0.1", "standard": "^17.1.0",