Skip to content

Commit

Permalink
feat: fastify v4 support (#552)
Browse files Browse the repository at this point in the history
* fix: fastify-secure-session

* chore: bump dependency to fastify@4
  • Loading branch information
climba03003 authored May 14, 2022
1 parent d72b25b commit 673e5ab
Show file tree
Hide file tree
Showing 13 changed files with 559 additions and 235 deletions.
728 changes: 529 additions & 199 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,14 @@
"url": "https://github.com/fastify/fastify-passport/issues"
},
"homepage": "http://passportjs.org/",
"engines": {
"node": ">= 12.0.0"
},
"dependencies": {
"@fastify/flash": "^4.0.0",
"@fastify/flash": "^5.0.0",
"fastify-plugin": "^3.0.0"
},
"peerDependencies": {
"fastify": "^3.0.3"
},
"devDependencies": {
"@fastify/cookie": "^6.0.0",
"@fastify/secure-session": "^4.0.0",
"@fastify/session": "^8.0.0",
"@fastify/cookie": "^7.0.0",
"@fastify/secure-session": "^5.0.0",
"@fastify/session": "^9.0.0",
"@types/jest": "^27.0.0",
"@types/node": "^17.0.0",
"@types/passport": "^1.0.5",
Expand All @@ -60,7 +54,7 @@
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^4.0.0",
"fastify": "^3.9.2",
"fastify": "^4.0.0-rc.2",
"got": "^11.8.1",
"jest": "^27.0.6",
"passport-facebook": "^3.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/Authenticator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FastifyPlugin, FastifyRequest, RouteHandlerMethod } from 'fastify'
import fastifyPlugin from 'fastify-plugin'
import { AuthenticateCallback, AuthenticateOptions, AuthenticationRoute } from './AuthenticationRoute'
import { CreateInitializePlugin } from './CreateInitializePlugin'
import { SecureSessionManager } from './session-managers/SecureSessionManager'
import { AnyStrategy, SessionStrategy, Strategy } from './strategies'
import { FastifyRequest, RouteHandlerMethod, FastifyPlugin } from 'fastify'
import { AuthenticateOptions, AuthenticateCallback, AuthenticationRoute } from './AuthenticationRoute'
import { CreateInitializePlugin } from './CreateInitializePlugin'
import fastifyPlugin from 'fastify-plugin'

export type SerializeFunction<User = any, SerializedUser = any> = (
user: User,
Expand Down Expand Up @@ -209,7 +209,7 @@ export class Authenticator {
}

/**
* Hook or handler that will restore login state from a session managed by fastify-secure-session.
* Hook or handler that will restore login state from a session managed by @fastify/secure-session.
*
* Web applications typically use sessions to maintain login state between requests. For example, a user will authenticate by entering credentials into a form which is submitted to the server. If the credentials are valid, a login session is established by setting a cookie containing a session identifier in the user's web browser. The web browser will send this cookie in subsequent requests to the server, allowing a session to be maintained.
*
Expand Down
2 changes: 1 addition & 1 deletion src/session-managers/SecureSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { FastifyRequest } from 'fastify'
import { SerializeFunction } from '../Authenticator'

/** Class for storing passport data in the session using `fastify-secure-session` or `@fastify/session` */
/** Class for storing passport data in the session using `@fastify/secure-session` or `@fastify/session` */
export class SecureSessionManager {
key: string
serializeUser: SerializeFunction
Expand Down
4 changes: 2 additions & 2 deletions test/authorize.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getConfiguredTestServer, generateTestUser } from './helpers'
import { Strategy } from '../src'
import { generateTestUser, getConfiguredTestServer } from './helpers'

export class TestThirdPartyStrategy extends Strategy {
authenticate(_request: any, _options?: { pauseStream?: boolean }) {
Expand Down Expand Up @@ -32,4 +32,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
4 changes: 2 additions & 2 deletions test/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getConfiguredTestServer, TestStrategy } from './helpers'
const suite = (sessionPluginName) => {
describe(`${sessionPluginName} tests`, () => {
const sessionOnlyTest = sessionPluginName === '@fastify/session' ? test : test.skip
const secureSessionOnlyTest = sessionPluginName === 'fastify-secure-session' ? test : test.skip
const secureSessionOnlyTest = sessionPluginName === '@fastify/secure-session' ? test : test.skip

describe('Request decorators', () => {
test('logIn allows logging in an arbitrary user', async () => {
Expand Down Expand Up @@ -137,4 +137,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
4 changes: 2 additions & 2 deletions test/independent-strategy-instances.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { getConfiguredTestServer, getRegisteredTestServer, TestStrategy } from './helpers'
import { Strategy } from '../src/strategies'
import { TestThirdPartyStrategy } from './authorize.test'
import { getConfiguredTestServer, getRegisteredTestServer, TestStrategy } from './helpers'

class WelcomeStrategy extends Strategy {
authenticate(request: any, _options?: { pauseStream?: boolean }) {
Expand Down Expand Up @@ -175,4 +175,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
4 changes: 2 additions & 2 deletions test/multi-instance.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FastifyInstance } from 'fastify'
import { getTestServer, TestBrowserSession } from './helpers'
import { Authenticator } from '../src/Authenticator'
import { Strategy } from '../src/strategies'
import { getTestServer, TestBrowserSession } from './helpers'

const suite = (sessionPluginName) => {
describe(`${sessionPluginName} tests`, () => {
Expand Down Expand Up @@ -255,4 +255,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
8 changes: 4 additions & 4 deletions test/passport.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import got from 'got'
import Authenticator from '../src/Authenticator'
import { getTestServer, getConfiguredTestServer, TestStrategy, getRegisteredTestServer } from './helpers'
import { AddressInfo } from 'net'
import { Strategy } from '../src/strategies'
import { AuthenticateOptions } from '../src/AuthenticationRoute'
import Authenticator from '../src/Authenticator'
import { Strategy } from '../src/strategies'
import { getConfiguredTestServer, getRegisteredTestServer, getTestServer, TestStrategy } from './helpers'

const suite = (sessionPluginName) => {
describe(`${sessionPluginName} tests`, () => {
Expand Down Expand Up @@ -651,4 +651,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
4 changes: 2 additions & 2 deletions test/session-isolation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { getConfiguredTestServer, TestBrowserSession, generateTestUser } from './helpers'
import { generateTestUser, getConfiguredTestServer, TestBrowserSession } from './helpers'

const { server, fastifyPassport } = getConfiguredTestServer()

Expand Down Expand Up @@ -180,4 +180,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
2 changes: 1 addition & 1 deletion test/session-serialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
6 changes: 3 additions & 3 deletions test/strategies-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getConfiguredTestServer, TestStrategy } from './helpers'
import { OAuth2Strategy as GoogleStrategy } from 'passport-google-oauth'
import { Strategy as FacebookStrategy } from 'passport-facebook'
import { Strategy as GitHubStrategy } from 'passport-github2'
import { OAuth2Strategy as GoogleStrategy } from 'passport-google-oauth'
import { getConfiguredTestServer, TestStrategy } from './helpers'

const suite = (sessionPluginName) => {
describe(`${sessionPluginName} tests`, () => {
Expand Down Expand Up @@ -89,4 +89,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')
2 changes: 1 addition & 1 deletion test/strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ const suite = (sessionPluginName) => {
}

suite('@fastify/session')
suite('fastify-secure-session')
suite('@fastify/secure-session')

0 comments on commit 673e5ab

Please sign in to comment.