Skip to content

Commit 504be1f

Browse files
FIxed some tests
1 parent d3c5cee commit 504be1f

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

projects/angular-auth-oidc-client/src/lib/check-auth.service.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,72 @@ describe('CheckAuthService', () => {
436436
});
437437
})
438438
);
439+
440+
it(
441+
'should start check session and validation after forceRefreshSession has been called and is authenticated after forcing with silentrenew',
442+
waitForAsync(() => {
443+
spyOn(configurationProvider, 'hasAsLeastOneConfig').and.returnValue(true);
444+
spyOn(configurationProvider, 'getOpenIDConfiguration').and.returnValue({ authority: 'authority' });
445+
spyOn(callBackService, 'isCallback').and.returnValue(false);
446+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
447+
spyOn(callBackService, 'handleCallbackAndFireEvents').and.returnValue(of(null));
448+
spyOn(checkSessionService, 'isCheckSessionConfigured').and.returnValue(true);
449+
spyOn(silentRenewService, 'isSilentRenewConfigured').and.returnValue(true);
450+
451+
const checkSessionServiceStartSpy = spyOn(checkSessionService, 'start');
452+
const periodicallyTokenCheckServiceSpy = spyOn(periodicallyTokenCheckService, 'startTokenValidationPeriodically');
453+
const getOrCreateIframeSpy = spyOn(silentRenewService, 'getOrCreateIframe');
454+
455+
spyOn(refreshSessionService, 'forceRefreshSession').and.returnValue(
456+
of({
457+
idToken: 'idToken',
458+
accessToken: 'access_token',
459+
isAuthenticated: true,
460+
userData: null,
461+
configId: 'configId',
462+
})
463+
);
464+
465+
checkAuthService.checkAuthIncludingServer('configId').subscribe((result) => {
466+
expect(checkSessionServiceStartSpy).toHaveBeenCalledOnceWith('configId');
467+
expect(periodicallyTokenCheckServiceSpy).toHaveBeenCalledTimes(1);
468+
expect(getOrCreateIframeSpy).toHaveBeenCalledOnceWith('configId');
469+
});
470+
})
471+
);
472+
473+
it(
474+
'should start check session and validation after forceRefreshSession has been called and is authenticated after forcing without silentrenew',
475+
waitForAsync(() => {
476+
spyOn(configurationProvider, 'hasAsLeastOneConfig').and.returnValue(true);
477+
spyOn(configurationProvider, 'getOpenIDConfiguration').and.returnValue({ authority: 'authority' });
478+
spyOn(callBackService, 'isCallback').and.returnValue(false);
479+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
480+
spyOn(callBackService, 'handleCallbackAndFireEvents').and.returnValue(of(null));
481+
spyOn(checkSessionService, 'isCheckSessionConfigured').and.returnValue(true);
482+
spyOn(silentRenewService, 'isSilentRenewConfigured').and.returnValue(false);
483+
484+
const checkSessionServiceStartSpy = spyOn(checkSessionService, 'start');
485+
const periodicallyTokenCheckServiceSpy = spyOn(periodicallyTokenCheckService, 'startTokenValidationPeriodically');
486+
const getOrCreateIframeSpy = spyOn(silentRenewService, 'getOrCreateIframe');
487+
488+
spyOn(refreshSessionService, 'forceRefreshSession').and.returnValue(
489+
of({
490+
idToken: 'idToken',
491+
accessToken: 'access_token',
492+
isAuthenticated: true,
493+
userData: null,
494+
configId: 'configId',
495+
})
496+
);
497+
498+
checkAuthService.checkAuthIncludingServer('configId').subscribe((result) => {
499+
expect(checkSessionServiceStartSpy).toHaveBeenCalledOnceWith('configId');
500+
expect(periodicallyTokenCheckServiceSpy).toHaveBeenCalledTimes(1);
501+
expect(getOrCreateIframeSpy).not.toHaveBeenCalled();
502+
});
503+
})
504+
);
439505
});
440506

441507
describe('checkAuthMultiple', () => {

projects/angular-auth-oidc-client/src/lib/flows/callback-handling/code-flow-callback-handler.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CodeFlowCallbackHandlerService {
2727
codeFlowCallback(urlToCheck: string, configId: string): Observable<CallbackContext> {
2828
const code = this.urlService.getUrlParameter(urlToCheck, 'code');
2929
const state = this.urlService.getUrlParameter(urlToCheck, 'state');
30-
const sessionState = this.urlService.getUrlParameter(urlToCheck, 'session_state') || null;
30+
const sessionState = this.urlService.getUrlParameter(urlToCheck, 'session_state');
3131

3232
if (!state) {
3333
this.loggerService.logDebug(configId, 'no state in url');

0 commit comments

Comments
 (0)