From 7c3f53a10a628a103f1d6182f64b8b1cc00268c9 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mark@zenbusiness.com>
Date: Fri, 11 Oct 2024 09:12:38 -0400
Subject: [PATCH] feat!: Upgrade to Fastify 5 and Node 20

---
 .github/workflows/ci.yml |  2 +-
 index.js                 |  2 +-
 package.json             | 12 ++++++------
 test/test.js             | 12 ++++++------
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2097fde..df0838f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -14,7 +14,7 @@ jobs:
       AUTH0_API_AUDIENCE: ${{ secrets.AUTH0_API_AUDIENCE }}
     strategy:
       matrix:
-        node: [16, 18, 20]
+        node: [20, 22]
     steps:
       - uses: actions/checkout@v4
       - uses: actions/setup-node@v4
diff --git a/index.js b/index.js
index c3cae63..3bcaa98 100644
--- a/index.js
+++ b/index.js
@@ -43,7 +43,7 @@ function fastifyAuth0Verify(instance, options, done) {
   }
 }
 
-module.exports = fastifyPlugin(fastifyAuth0Verify, { name: 'fastify-auth0-verify', fastify: '4.x' })
+module.exports = fastifyPlugin(fastifyAuth0Verify, { name: 'fastify-auth0-verify', fastify: '5.x' })
 
 // Set the default export to the fastifyAuth0Verify function for ES module compatibility
 module.exports.default = fastifyAuth0Verify
diff --git a/package.json b/package.json
index af60558..d7a72f0 100644
--- a/package.json
+++ b/package.json
@@ -46,10 +46,10 @@
     "postpublish": "git push origin && git push origin -f --tags"
   },
   "dependencies": {
-    "@fastify/cookie": "^9.0.4",
-    "@fastify/jwt": "^8.0.0",
-    "fastify-jwt-jwks": "^1.1.3",
-    "fastify-plugin": "^4.0.0"
+    "@fastify/cookie": "^11.0.1",
+    "@fastify/jwt": "^9.0.1",
+    "fastify-jwt-jwks": "^2.0.0",
+    "fastify-plugin": "^5.0.1"
   },
   "devDependencies": {
     "cross-fetch": "^4.0.0",
@@ -63,7 +63,7 @@
     "eslint-plugin-prettier": "^5.0.0",
     "eslint-plugin-promise": "^6.0.1",
     "fast-jwt": "^4.0.0",
-    "fastify": "^4.0.2",
+    "fastify": "^5.0.0",
     "jest": "^29.0.0",
     "nock": "^13.0.2",
     "prettier": "^3.0.1",
@@ -71,6 +71,6 @@
     "typescript": "^5.0.2"
   },
   "engines": {
-    "node": ">= 16"
+    "node": ">= 20"
   }
 }
diff --git a/test/test.js b/test/test.js
index c64dd71..5191ae0 100644
--- a/test/test.js
+++ b/test/test.js
@@ -295,12 +295,12 @@ describe('JWT token decoding', function () {
   it('should complain if the HTTP Authorization header is in the wrong format', async function () {
     const response = await server.inject({ method: 'GET', url: '/decode', headers: { Authorization: 'FOO' } })
 
-    expect(response.statusCode).toEqual(400)
+    expect(response.statusCode).toEqual(401)
     expect(response.json()).toEqual({
-      code: 'FST_JWT_BAD_REQUEST',
-      statusCode: 400,
-      error: 'Bad Request',
-      message: 'Format is Authorization: Bearer [token]'
+      code: 'FST_JWT_NO_AUTHORIZATION_IN_HEADER',
+      statusCode: 401,
+      error: 'Unauthorized',
+      message: 'No Authorization was found in request.headers'
     })
   })
 })
@@ -920,7 +920,7 @@ describe('General error handling', function () {
     expect(response.json()).toEqual({
       statusCode: 401,
       error: 'Unauthorized',
-      message: 'Authorization header should be in format: Bearer [token].'
+      message: 'Missing Authorization HTTP header.'
     })
   })