@@ -24,6 +24,7 @@ const clientId = '11111';
24
24
const redirectUri = 'https://test.com' ;
25
25
const popupRedirectUri = `${ redirectUri } -popup` ;
26
26
const logoutEndpoint = '/v2/logout' ;
27
+ const crossSdkBridgeLogoutEndpoint = '/im-logged-out' ;
27
28
const logoutRedirectUri = `${ redirectUri } logout/callback` ;
28
29
29
30
const getConfig = ( values ?: Partial < PassportModuleConfiguration > ) => new PassportConfiguration ( {
@@ -108,7 +109,7 @@ describe('AuthManager', () => {
108
109
mockOverlayAppend = jest . fn ( ) ;
109
110
mockOverlayRemove = jest . fn ( ) ;
110
111
mockRevokeTokens = jest . fn ( ) ;
111
- ( UserManager as jest . Mock ) . mockReturnValue ( {
112
+ ( UserManager as jest . Mock ) . mockImplementation ( ( config ) => ( {
112
113
signinPopup : mockSigninPopup ,
113
114
signinCallback : mockSigninCallback ,
114
115
signinRedirectCallback : mockSigninRedirectCallback ,
@@ -118,7 +119,12 @@ describe('AuthManager', () => {
118
119
signinSilent : mockSigninSilent ,
119
120
storeUser : mockStoreUser ,
120
121
revokeTokens : mockRevokeTokens ,
121
- } ) ;
122
+ settings : {
123
+ metadata : {
124
+ end_session_endpoint : config . metadata ?. end_session_endpoint ,
125
+ } ,
126
+ } ,
127
+ } ) ) ;
122
128
( Overlay as jest . Mock ) . mockReturnValue ( {
123
129
append : mockOverlayAppend ,
124
130
remove : mockOverlayRemove ,
@@ -718,7 +724,9 @@ describe('AuthManager', () => {
718
724
719
725
const am = new AuthManager ( getConfig ( { logoutRedirectUri } ) ) ;
720
726
const result = await am . getLogoutUrl ( ) ;
721
- const uri = new URL ( result ) ;
727
+
728
+ expect ( result ) . not . toBeNull ( ) ;
729
+ const uri = new URL ( result ! ) ;
722
730
723
731
expect ( uri . hostname ) . toEqual ( authenticationDomain ) ;
724
732
expect ( uri . pathname ) . toEqual ( logoutEndpoint ) ;
@@ -733,13 +741,43 @@ describe('AuthManager', () => {
733
741
734
742
const am = new AuthManager ( getConfig ( ) ) ;
735
743
const result = await am . getLogoutUrl ( ) ;
736
- const uri = new URL ( result ) ;
744
+
745
+ expect ( result ) . not . toBeNull ( ) ;
746
+ const uri = new URL ( result ! ) ;
737
747
738
748
expect ( uri . hostname ) . toEqual ( authenticationDomain ) ;
739
749
expect ( uri . pathname ) . toEqual ( logoutEndpoint ) ;
740
750
expect ( uri . searchParams . get ( 'client_id' ) ) . toEqual ( clientId ) ;
741
751
} ) ;
742
752
} ) ;
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
+ } ) ;
743
781
} ) ;
744
782
} ) ;
745
783
0 commit comments