Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for Fastify v5 #276

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.0.0
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4

If you use v4 then it'll automatically pick up the latest, i.e. if we release 4.0.1 then it'll use that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will do that

But then I'm not understanding something

Why didn't this work with rate-limit? Using v4 there with the redis workflow resulted in errors

fastify/fastify-rate-limit#350
https://github.com/fastify/fastify-rate-limit/actions/runs/7195862716

Copy link
Member Author

@gurgunday gurgunday Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There you go, it didn't work...

I think it might be because v4 doesn't exist as a release/tag — there is only v4.0.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, forgot the v4 release went awry: fastify/workflows#107, grumble grumble grumble.

with:
license-check: true
lint: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ lib-cov
coverage
*.lcov

# tap test output
.tap

# nyc test coverage
.nyc_output

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@
},
"homepage": "https://github.com/fastify/fastify-cookie#readme",
"devDependencies": {
"@fastify/pre-commit": "^2.0.2",
"@types/node": "^20.1.0",
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^20.11.6",
"benchmark": "^2.1.4",
"fastify": "^4.0.0",
"sinon": "^17.0.0",
"fastify": "^4.25.2",
"sinon": "^17.0.1",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tsd": "^0.30.0"
"standard": "^17.1.0",
"tap": "^18.6.1",
"tsd": "^0.30.4"
},
"dependencies": {
"fastify-plugin": "^4.0.0",
"cookie-signature": "^1.1.0"
"fastify-plugin": "^4.5.1",
"cookie-signature": "^1.2.1"
},
"tsd": {
"directory": "test"
Expand Down
8 changes: 4 additions & 4 deletions signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

const crypto = require('node:crypto')

const base64PaddingRE = /=/gu

function Signer (secrets, algorithm = 'sha256') {
if (!(this instanceof Signer)) {
return new Signer(secrets, algorithm)
Expand Down Expand Up @@ -45,12 +43,13 @@ function _sign (value, secret, algorithm) {
if (typeof value !== 'string') {
throw new TypeError('Cookie value must be provided as a string.')
}

return value + '.' + crypto
.createHmac(algorithm, secret)
.update(value)
.digest('base64')
// remove base64 padding (=) as it has special meaning in cookies
.replace(base64PaddingRE, '')
.replaceAll('=', '')
gurgunday marked this conversation as resolved.
Show resolved Hide resolved
}

function _unsign (signedValue, secrets, algorithm) {
Expand All @@ -67,7 +66,8 @@ function _unsign (signedValue, secrets, algorithm) {
.update(value)
.digest('base64')
// remove base64 padding (=) as it has special meaning in cookies
.replace(base64PaddingRE, ''))
.replaceAll('=', ''))

if (
expected.length === actual.length &&
crypto.timingSafeEqual(expected, actual)
Expand Down
2 changes: 1 addition & 1 deletion test/cookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ test('result in an error if hook-option is set to an invalid value', (t) => {
const fastify = Fastify()

t.rejects(
() => fastify.register(plugin, { hook: true }),
async () => fastify.register(plugin, { hook: true }),
new Error("@fastify/cookie: Invalid value provided for the hook-option. You can set the hook-option only to false, 'onRequest' , 'preParsing' , 'preValidation' or 'preHandler'")
)
})
Expand Down