From 27f3d19a638abe6c98970a0741902b7e91c83d82 Mon Sep 17 00:00:00 2001 From: Munish Sharma Date: Thu, 21 Nov 2024 15:26:56 +0000 Subject: [PATCH] failing test fix --- package.json | 2 +- src/auth/models/strategy.class.ts | 8 ++++---- src/auth/oidc/models/openid.class.spec.ts | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 32e8e9b..1ccd7c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/rpx-xui-node-lib", - "version": "2.29.5-exui-2079-rc8", + "version": "2.29.5-exui-2079-rc9", "description": "Common nodejs library components for XUI", "main": "dist/index", "types": "dist/index.d.ts", diff --git a/src/auth/models/strategy.class.ts b/src/auth/models/strategy.class.ts index 96408e0..28b2b7a 100644 --- a/src/auth/models/strategy.class.ts +++ b/src/auth/models/strategy.class.ts @@ -241,9 +241,9 @@ export abstract class Strategy extends events.EventEmitter { this.serializeUser() this.deserializeUser() - ;(async () => { - await Promise.all([this.initialiseStrategy(this.options)]) - })() + ; (async () => { + await Promise.all([this.initialiseStrategy(this.options)]) + })() this.initializePassport() this.initializeSession() @@ -413,7 +413,7 @@ export abstract class Strategy extends events.EventEmitter { this.logger.error( `User has no application access, as they do not have a ${this.options.allowRolesRegex} role.`, ) - return this.logout(req, res) + return this.logout(req, res, next) } if (!this.listenerCount(AUTH.EVENT.AUTHENTICATE_SUCCESS)) { this.logger.log(`redirecting, no listener count: ${AUTH.EVENT.AUTHENTICATE_SUCCESS}`) diff --git a/src/auth/oidc/models/openid.class.spec.ts b/src/auth/oidc/models/openid.class.spec.ts index 414ab3c..135259a 100644 --- a/src/auth/oidc/models/openid.class.spec.ts +++ b/src/auth/oidc/models/openid.class.spec.ts @@ -2,7 +2,7 @@ import { oidc, OpenID } from './openid.class' import passport from 'passport' -import express, { Request, response, Response, Router } from 'express' +import express, { NextFunction, Request, response, Response, Router } from 'express' import { AUTH } from '../../auth.constants' import { Client, Issuer, Strategy, TokenSet, UserinfoResponse } from 'openid-client' import { createMock } from 'ts-auto-mock' @@ -399,7 +399,7 @@ xtest('verify() Should return a no access roles messages if the User has no role const tokenSet = createMock() const userinfo = createMock() - const doneFunction = jest.fn((err, user, message) => {}) + const doneFunction = jest.fn((err, user, message) => { }) oidc.verify(tokenSet, userinfo, doneFunction) @@ -421,7 +421,7 @@ xtest('verify() Should return the user token set if a User has roles.', async () idToken: tokenSet.id_token, } - const doneFunction = jest.fn((err, user, message) => {}) + const doneFunction = jest.fn((err, user, message) => { }) oidc.verify(tokenSet, userinfo, doneFunction) @@ -452,6 +452,7 @@ xtest('makeAuthorization() Should make an authorisation string', async () => { xtest('strategy logout', async () => { const session = createMock() const mockRequest = createMock() + const mockNextFunction = createMock() session.passport = { user: { tokenset: { @@ -472,7 +473,7 @@ xtest('strategy logout', async () => { mockResponse.redirect = jest.fn() const spyhttp = jest.spyOn(http, 'delete').mockImplementation(() => Promise.resolve({} as any)) const spySessionDestroy = jest.spyOn(oidc, 'destroySession').mockImplementation(() => Promise.resolve({} as any)) - await oidc.logout(mockRequest, mockResponse) + await oidc.logout(mockRequest, mockResponse, mockNextFunction) expect(spyhttp).toHaveBeenCalled() expect(spySessionDestroy).toHaveBeenCalled() })