@@ -39,7 +39,7 @@ describe('CodeFlowCallbackService ', () => {
3939 expect ( codeFlowCallbackService ) . toBeTruthy ( ) ;
4040 } ) ;
4141
42- describe ( 'authorizedCallbackWithCode ' , ( ) => {
42+ describe ( 'authenticatedCallbackWithCode ' , ( ) => {
4343 it ( 'calls flowsService.processCodeFlowCallback with correct url' , ( ) => {
4444 const spy = spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( of ( null ) ) ;
4545 //spyOn(configurationProvider, 'getOpenIDConfiguration').and.returnValue({ triggerAuthorizationResultEvent: true });
@@ -53,111 +53,105 @@ describe('CodeFlowCallbackService ', () => {
5353 expect ( spy ) . toHaveBeenCalledOnceWith ( 'some-url1' , config , [ config ] ) ;
5454 } ) ;
5555
56- it (
57- 'does nothing if triggerAuthorizationResultEvent is true and isRenewProcess is true' ,
58- waitForAsync ( ( ) => {
59- const callbackContext = {
60- code : '' ,
61- refreshToken : '' ,
62- state : '' ,
63- sessionState : null ,
64- authResult : null ,
65- isRenewProcess : true ,
66- jwtKeys : null ,
67- validationResult : null ,
68- existingIdToken : '' ,
69- } ;
70- const spy = spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( of ( callbackContext ) ) ;
71- const routerSpy = spyOn ( router , 'navigateByUrl' ) ;
72- const config = {
73- configId : 'configId1' ,
74- triggerAuthorizationResultEvent : true ,
75- } ;
76-
77- codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url2' , config , [ config ] ) . subscribe ( ( ) => {
78- expect ( spy ) . toHaveBeenCalledOnceWith ( 'some-url2' , config , [ config ] ) ;
79- expect ( routerSpy ) . not . toHaveBeenCalled ( ) ;
80- } ) ;
81- } )
82- ) ;
83-
84- it (
85- 'calls router if triggerAuthorizationResultEvent is false and isRenewProcess is false' ,
86- waitForAsync ( ( ) => {
87- const callbackContext = {
88- code : '' ,
89- refreshToken : '' ,
90- state : '' ,
91- sessionState : null ,
92- authResult : null ,
93- isRenewProcess : false ,
94- jwtKeys : null ,
95- validationResult : null ,
96- existingIdToken : '' ,
97- } ;
98- const spy = spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( of ( callbackContext ) ) ;
99- const routerSpy = spyOn ( router , 'navigateByUrl' ) ;
100- const config = {
101- configId : 'configId1' ,
102- triggerAuthorizationResultEvent : false ,
103- postLoginRoute : 'postLoginRoute' ,
104- } ;
105-
106- codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url3' , config , [ config ] ) . subscribe ( ( ) => {
107- expect ( spy ) . toHaveBeenCalledOnceWith ( 'some-url3' , config , [ config ] ) ;
108- expect ( routerSpy ) . toHaveBeenCalledOnceWith ( 'postLoginRoute' ) ;
109- } ) ;
110- } )
111- ) ;
112-
113- it (
114- 'resetSilentRenewRunning and stopPeriodicallTokenCheck in case of error' ,
115- waitForAsync ( ( ) => {
116- spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( throwError ( ( ) => new Error ( 'error' ) ) ) ;
117- const resetSilentRenewRunningSpy = spyOn ( flowsDataService , 'resetSilentRenewRunning' ) ;
118- const stopPeriodicallTokenCheckSpy = spyOn ( intervalService , 'stopPeriodicTokenCheck' ) ;
119-
120- const config = {
121- configId : 'configId1' ,
122- triggerAuthorizationResultEvent : false ,
123- postLoginRoute : 'postLoginRoute' ,
124- } ;
125-
126- codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url4' , config , [ config ] ) . subscribe ( {
127- error : ( err ) => {
128- expect ( resetSilentRenewRunningSpy ) . toHaveBeenCalled ( ) ;
129- expect ( stopPeriodicallTokenCheckSpy ) . toHaveBeenCalled ( ) ;
130- expect ( err ) . toBeTruthy ( ) ;
131- } ,
132- } ) ;
133- } )
134- ) ;
135-
136- it (
137- `navigates to unauthorizedRoute in case of error and in case of error and
138- triggerAuthorizationResultEvent is false` ,
139- waitForAsync ( ( ) => {
140- spyOn ( flowsDataService , 'isSilentRenewRunning' ) . and . returnValue ( false ) ;
141- spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( throwError ( ( ) => new Error ( 'error' ) ) ) ;
142- const resetSilentRenewRunningSpy = spyOn ( flowsDataService , 'resetSilentRenewRunning' ) ;
143- const stopPeriodicallTokenCheckSpy = spyOn ( intervalService , 'stopPeriodicTokenCheck' ) ;
144- const routerSpy = spyOn ( router , 'navigateByUrl' ) ;
145-
146- const config = {
147- configId : 'configId1' ,
148- triggerAuthorizationResultEvent : false ,
149- unauthorizedRoute : 'unauthorizedRoute' ,
150- } ;
151-
152- codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url5' , config , [ config ] ) . subscribe ( {
153- error : ( err ) => {
154- expect ( resetSilentRenewRunningSpy ) . toHaveBeenCalled ( ) ;
155- expect ( stopPeriodicallTokenCheckSpy ) . toHaveBeenCalled ( ) ;
156- expect ( err ) . toBeTruthy ( ) ;
157- expect ( routerSpy ) . toHaveBeenCalledOnceWith ( 'unauthorizedRoute' ) ;
158- } ,
159- } ) ;
160- } )
161- ) ;
56+ it ( 'does only call resetCodeFlowInProgress if triggerAuthorizationResultEvent is true and isRenewProcess is true' , waitForAsync ( ( ) => {
57+ const callbackContext = {
58+ code : '' ,
59+ refreshToken : '' ,
60+ state : '' ,
61+ sessionState : null ,
62+ authResult : null ,
63+ isRenewProcess : true ,
64+ jwtKeys : null ,
65+ validationResult : null ,
66+ existingIdToken : '' ,
67+ } ;
68+ const spy = spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( of ( callbackContext ) ) ;
69+ const flowsDataSpy = spyOn ( flowsDataService , 'resetCodeFlowInProgress' ) ;
70+ const routerSpy = spyOn ( router , 'navigateByUrl' ) ;
71+ const config = {
72+ configId : 'configId1' ,
73+ triggerAuthorizationResultEvent : true ,
74+ } ;
75+
76+ codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url2' , config , [ config ] ) . subscribe ( ( ) => {
77+ expect ( spy ) . toHaveBeenCalledOnceWith ( 'some-url2' , config , [ config ] ) ;
78+ expect ( routerSpy ) . not . toHaveBeenCalled ( ) ;
79+ expect ( flowsDataSpy ) . toHaveBeenCalled ( ) ;
80+ } ) ;
81+ } ) ) ;
82+
83+ it ( 'calls router and resetCodeFlowInProgress if triggerAuthorizationResultEvent is false and isRenewProcess is false' , waitForAsync ( ( ) => {
84+ const callbackContext = {
85+ code : '' ,
86+ refreshToken : '' ,
87+ state : '' ,
88+ sessionState : null ,
89+ authResult : null ,
90+ isRenewProcess : false ,
91+ jwtKeys : null ,
92+ validationResult : null ,
93+ existingIdToken : '' ,
94+ } ;
95+ const spy = spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( of ( callbackContext ) ) ;
96+ const flowsDataSpy = spyOn ( flowsDataService , 'resetCodeFlowInProgress' ) ;
97+ const routerSpy = spyOn ( router , 'navigateByUrl' ) ;
98+ const config = {
99+ configId : 'configId1' ,
100+ triggerAuthorizationResultEvent : false ,
101+ postLoginRoute : 'postLoginRoute' ,
102+ } ;
103+
104+ codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url3' , config , [ config ] ) . subscribe ( ( ) => {
105+ expect ( spy ) . toHaveBeenCalledOnceWith ( 'some-url3' , config , [ config ] ) ;
106+ expect ( routerSpy ) . toHaveBeenCalledOnceWith ( 'postLoginRoute' ) ;
107+ expect ( flowsDataSpy ) . toHaveBeenCalled ( ) ;
108+ } ) ;
109+ } ) ) ;
110+
111+ it ( 'resetSilentRenewRunning, resetCodeFlowInProgress and stopPeriodicallTokenCheck in case of error' , waitForAsync ( ( ) => {
112+ spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( throwError ( ( ) => new Error ( 'error' ) ) ) ;
113+ const resetSilentRenewRunningSpy = spyOn ( flowsDataService , 'resetSilentRenewRunning' ) ;
114+ const resetCodeFlowInProgressSpy = spyOn ( flowsDataService , 'resetCodeFlowInProgress' ) ;
115+ const stopPeriodicallTokenCheckSpy = spyOn ( intervalService , 'stopPeriodicTokenCheck' ) ;
116+
117+ const config = {
118+ configId : 'configId1' ,
119+ triggerAuthorizationResultEvent : false ,
120+ postLoginRoute : 'postLoginRoute' ,
121+ } ;
122+
123+ codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url4' , config , [ config ] ) . subscribe ( {
124+ error : ( err ) => {
125+ expect ( resetSilentRenewRunningSpy ) . toHaveBeenCalled ( ) ;
126+ expect ( resetCodeFlowInProgressSpy ) . toHaveBeenCalled ( ) ;
127+ expect ( stopPeriodicallTokenCheckSpy ) . toHaveBeenCalled ( ) ;
128+ expect ( err ) . toBeTruthy ( ) ;
129+ } ,
130+ } ) ;
131+ } ) ) ;
132+
133+ it ( `navigates to unauthorizedRoute in case of error and in case of error and
134+ triggerAuthorizationResultEvent is false` , waitForAsync ( ( ) => {
135+ spyOn ( flowsDataService , 'isSilentRenewRunning' ) . and . returnValue ( false ) ;
136+ spyOn ( flowsService , 'processCodeFlowCallback' ) . and . returnValue ( throwError ( ( ) => new Error ( 'error' ) ) ) ;
137+ const resetSilentRenewRunningSpy = spyOn ( flowsDataService , 'resetSilentRenewRunning' ) ;
138+ const stopPeriodicallTokenCheckSpy = spyOn ( intervalService , 'stopPeriodicTokenCheck' ) ;
139+ const routerSpy = spyOn ( router , 'navigateByUrl' ) ;
140+
141+ const config = {
142+ configId : 'configId1' ,
143+ triggerAuthorizationResultEvent : false ,
144+ unauthorizedRoute : 'unauthorizedRoute' ,
145+ } ;
146+
147+ codeFlowCallbackService . authenticatedCallbackWithCode ( 'some-url5' , config , [ config ] ) . subscribe ( {
148+ error : ( err ) => {
149+ expect ( resetSilentRenewRunningSpy ) . toHaveBeenCalled ( ) ;
150+ expect ( stopPeriodicallTokenCheckSpy ) . toHaveBeenCalled ( ) ;
151+ expect ( err ) . toBeTruthy ( ) ;
152+ expect ( routerSpy ) . toHaveBeenCalledOnceWith ( 'unauthorizedRoute' ) ;
153+ } ,
154+ } ) ;
155+ } ) ) ;
162156 } ) ;
163157} ) ;
0 commit comments