@@ -24,6 +24,7 @@ const clientId = '11111';
2424const redirectUri = 'https://test.com' ;
2525const popupRedirectUri = `${ redirectUri } -popup` ;
2626const logoutEndpoint = '/v2/logout' ;
27+ const crossSdkBridgeLogoutEndpoint = '/im-logged-out' ;
2728const logoutRedirectUri = `${ redirectUri } logout/callback` ;
2829
2930const getConfig = ( values ?: Partial < PassportModuleConfiguration > ) => new PassportConfiguration ( {
@@ -108,7 +109,7 @@ describe('AuthManager', () => {
108109 mockOverlayAppend = jest . fn ( ) ;
109110 mockOverlayRemove = jest . fn ( ) ;
110111 mockRevokeTokens = jest . fn ( ) ;
111- ( UserManager as jest . Mock ) . mockReturnValue ( {
112+ ( UserManager as jest . Mock ) . mockImplementation ( ( config ) => ( {
112113 signinPopup : mockSigninPopup ,
113114 signinCallback : mockSigninCallback ,
114115 signinRedirectCallback : mockSigninRedirectCallback ,
@@ -118,7 +119,12 @@ describe('AuthManager', () => {
118119 signinSilent : mockSigninSilent ,
119120 storeUser : mockStoreUser ,
120121 revokeTokens : mockRevokeTokens ,
121- } ) ;
122+ settings : {
123+ metadata : {
124+ end_session_endpoint : config . metadata ?. end_session_endpoint ,
125+ } ,
126+ } ,
127+ } ) ) ;
122128 ( Overlay as jest . Mock ) . mockReturnValue ( {
123129 append : mockOverlayAppend ,
124130 remove : mockOverlayRemove ,
@@ -718,7 +724,9 @@ describe('AuthManager', () => {
718724
719725 const am = new AuthManager ( getConfig ( { logoutRedirectUri } ) ) ;
720726 const result = await am . getLogoutUrl ( ) ;
721- const uri = new URL ( result ) ;
727+
728+ expect ( result ) . not . toBeNull ( ) ;
729+ const uri = new URL ( result ! ) ;
722730
723731 expect ( uri . hostname ) . toEqual ( authenticationDomain ) ;
724732 expect ( uri . pathname ) . toEqual ( logoutEndpoint ) ;
@@ -733,13 +741,43 @@ describe('AuthManager', () => {
733741
734742 const am = new AuthManager ( getConfig ( ) ) ;
735743 const result = await am . getLogoutUrl ( ) ;
736- const uri = new URL ( result ) ;
744+
745+ expect ( result ) . not . toBeNull ( ) ;
746+ const uri = new URL ( result ! ) ;
737747
738748 expect ( uri . hostname ) . toEqual ( authenticationDomain ) ;
739749 expect ( uri . pathname ) . toEqual ( logoutEndpoint ) ;
740750 expect ( uri . searchParams . get ( 'client_id' ) ) . toEqual ( clientId ) ;
741751 } ) ;
742752 } ) ;
753+
754+ describe ( 'when crossSdkBridgeEnabled is true' , ( ) => {
755+ it ( 'should use the bridge logout endpoint path' , async ( ) => {
756+ mockGetUser . mockReturnValue ( mockOidcUser ) ;
757+
758+ const am = new AuthManager ( getConfig ( { crossSdkBridgeEnabled : true , logoutRedirectUri } ) ) ;
759+ const result = await am . getLogoutUrl ( ) ;
760+
761+ expect ( result ) . not . toBeNull ( ) ;
762+ const uri = new URL ( result ! ) ;
763+
764+ expect ( uri . hostname ) . toEqual ( authenticationDomain ) ;
765+ expect ( uri . pathname ) . toEqual ( crossSdkBridgeLogoutEndpoint ) ;
766+ expect ( uri . searchParams . get ( 'client_id' ) ) . toEqual ( clientId ) ;
767+ expect ( uri . searchParams . get ( 'returnTo' ) ) . toEqual ( logoutRedirectUri ) ;
768+ } ) ;
769+ } ) ;
770+ } ) ;
771+
772+ describe ( 'when end_session_endpoint is not available' , ( ) => {
773+ it ( 'should return null' , async ( ) => {
774+ const am = new AuthManager ( getConfig ( ) ) ;
775+ // eslint-disable-next-line @typescript-eslint/dot-notation
776+ am [ 'userManager' ] . settings . metadata ! . end_session_endpoint = undefined ;
777+
778+ const result = await am . getLogoutUrl ( ) ;
779+ expect ( result ) . toBeNull ( ) ;
780+ } ) ;
743781 } ) ;
744782 } ) ;
745783
0 commit comments