feat: init
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { TestBed, mockImplementationWhenArgsEqual } from '@/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { skip } from 'rxjs/operators';
|
||||
import { mockAbstractProvider, mockProvider } from '../../test/auto-mock';
|
||||
import { vi } from 'vitest';
|
||||
import { LoggerService } from '../logging/logger.service';
|
||||
import { OidcSecurityService } from '../oidc.security.service';
|
||||
import { PublicEventsService } from '../public-events/public-events.service';
|
||||
import { AbstractSecurityStorage } from '../storage/abstract-security-storage';
|
||||
import { DefaultSessionStorageService } from '../storage/default-sessionstorage.service';
|
||||
import { StoragePersistenceService } from '../storage/storage-persistence.service';
|
||||
import { mockAbstractProvider, mockProvider } from '../testing/mock';
|
||||
import { PlatformProvider } from '../utils/platform-provider/platform.provider';
|
||||
import { CheckSessionService } from './check-session.service';
|
||||
import { IFrameService } from './existing-iframe.service';
|
||||
@@ -67,7 +68,7 @@ describe('CheckSessionService', () => {
|
||||
});
|
||||
|
||||
it('getOrCreateIframe calls iFrameService.addIFrameToWindowBody if no Iframe exists', () => {
|
||||
spyOn(iFrameService, 'addIFrameToWindowBody').and.callThrough();
|
||||
vi.spyOn(iFrameService, 'addIFrameToWindowBody')();
|
||||
|
||||
const result = (checkSessionService as any).getOrCreateIframe({
|
||||
configId: 'configId1',
|
||||
@@ -89,7 +90,7 @@ describe('CheckSessionService', () => {
|
||||
|
||||
it('init appends iframe on body with correct values', () => {
|
||||
expect((checkSessionService as any).sessionIframe).toBeFalsy();
|
||||
spyOn<any>(loggerService, 'logDebug').and.callFake(() => undefined);
|
||||
vi.spyOn(loggerService, 'logDebug').mockImplementation(() => undefined);
|
||||
|
||||
(checkSessionService as any).init();
|
||||
const iframe = (checkSessionService as any).getOrCreateIframe({
|
||||
@@ -105,29 +106,34 @@ describe('CheckSessionService', () => {
|
||||
});
|
||||
|
||||
it('log warning if authWellKnownEndpoints.check_session_iframe is not existing', () => {
|
||||
const spyLogWarning = spyOn<any>(loggerService, 'logWarning');
|
||||
const spyLogWarning = vi.spyOn<any>(loggerService, 'logWarning');
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn<any>(loggerService, 'logDebug').and.callFake(() => undefined);
|
||||
spyOn(storagePersistenceService, 'read')
|
||||
vi.spyOn<any>(loggerService, 'logDebug').mockImplementation(
|
||||
() => undefined
|
||||
);
|
||||
vi.spyOn(storagePersistenceService, 'read')
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.and.returnValue({ checkSessionIframe: undefined });
|
||||
.mockReturnValue({ checkSessionIframe: undefined });
|
||||
(checkSessionService as any).init(config);
|
||||
|
||||
expect(spyLogWarning).toHaveBeenCalledOnceWith(config, jasmine.any(String));
|
||||
expect(spyLogWarning).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
|
||||
it('start() calls pollserversession() with clientId if no scheduledheartbeat is set', () => {
|
||||
const spy = spyOn<any>(checkSessionService, 'pollServerSession');
|
||||
const spy = vi.spyOn<any>(checkSessionService, 'pollServerSession');
|
||||
const config = { clientId: 'clientId', configId: 'configId1' };
|
||||
|
||||
checkSessionService.start(config);
|
||||
expect(spy).toHaveBeenCalledOnceWith('clientId', config);
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith('clientId', config);
|
||||
});
|
||||
|
||||
it('start() does not call pollServerSession() if scheduledHeartBeatRunning is set', () => {
|
||||
const config = { configId: 'configId1' };
|
||||
const spy = spyOn<any>(checkSessionService, 'pollServerSession');
|
||||
const spy = vi.spyOn<any>(checkSessionService, 'pollServerSession');
|
||||
|
||||
(checkSessionService as any).scheduledHeartBeatRunning = (): void =>
|
||||
undefined;
|
||||
@@ -148,10 +154,10 @@ describe('CheckSessionService', () => {
|
||||
|
||||
it('stopCheckingSession does nothing if scheduledHeartBeatRunning is not set', () => {
|
||||
(checkSessionService as any).scheduledHeartBeatRunning = null;
|
||||
const spy = spyOn<any>(checkSessionService, 'clearScheduledHeartBeat');
|
||||
const spy = vi.spyOn<any>(checkSessionService, 'clearScheduledHeartBeat');
|
||||
|
||||
checkSessionService.stop();
|
||||
expect(spy).not.toHaveBeenCalledOnceWith();
|
||||
expect(spy).not.toHaveBeenCalledExactlyOnceWith();
|
||||
});
|
||||
|
||||
describe('serverStateChanged', () => {
|
||||
@@ -167,7 +173,7 @@ describe('CheckSessionService', () => {
|
||||
const config = { startCheckSession: true, configId: 'configId1' };
|
||||
const result = checkSessionService.serverStateChanged(config);
|
||||
|
||||
expect(result).toBeFalse();
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns true if startCheckSession is configured and checkSessionReceived is true', () => {
|
||||
@@ -175,17 +181,17 @@ describe('CheckSessionService', () => {
|
||||
const config = { startCheckSession: true, configId: 'configId1' };
|
||||
const result = checkSessionService.serverStateChanged(config);
|
||||
|
||||
expect(result).toBeTrue();
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('pollServerSession', () => {
|
||||
beforeEach(() => {
|
||||
spyOn<any>(checkSessionService, 'init').and.returnValue(of(undefined));
|
||||
vi.spyOn<any>(checkSessionService, 'init').mockReturnValue(of(undefined));
|
||||
});
|
||||
|
||||
it('increases outstandingMessages', () => {
|
||||
spyOn<any>(checkSessionService, 'getExistingIframe').and.returnValue({
|
||||
vi.spyOn<any>(checkSessionService, 'getExistingIframe').mockReturnValue({
|
||||
contentWindow: { postMessage: () => undefined },
|
||||
});
|
||||
const authWellKnownEndpoints = {
|
||||
@@ -193,18 +199,20 @@ describe('CheckSessionService', () => {
|
||||
};
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(storagePersistenceService, 'read')
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.and.returnValue(authWellKnownEndpoints)
|
||||
mockImplementationWhenArgsEqual(
|
||||
vi.spyOn(storagePersistenceService, 'read'),
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
)
|
||||
.withArgs('session_state', config)
|
||||
.and.returnValue('session_state');
|
||||
spyOn(loggerService, 'logDebug').and.callFake(() => undefined);
|
||||
.mockReturnValue('session_state');
|
||||
vi.spyOn(loggerService, 'logDebug').mockImplementation(() => undefined);
|
||||
(checkSessionService as any).pollServerSession('clientId', config);
|
||||
expect((checkSessionService as any).outstandingMessages).toBe(1);
|
||||
});
|
||||
|
||||
it('logs warning if iframe does not exist', () => {
|
||||
spyOn<any>(checkSessionService, 'getExistingIframe').and.returnValue(
|
||||
vi.spyOn<any>(checkSessionService, 'getExistingIframe').mockReturnValue(
|
||||
null
|
||||
);
|
||||
const authWellKnownEndpoints = {
|
||||
@@ -212,77 +220,91 @@ describe('CheckSessionService', () => {
|
||||
};
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(storagePersistenceService, 'read')
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.and.returnValue(authWellKnownEndpoints);
|
||||
const spyLogWarning = spyOn(loggerService, 'logWarning').and.callFake(
|
||||
() => undefined
|
||||
mockImplementationWhenArgsEqual(
|
||||
vi.spyOn(storagePersistenceService, 'read'),
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
const spyLogWarning = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
|
||||
spyOn(loggerService, 'logDebug').and.callFake(() => undefined);
|
||||
vi.spyOn(loggerService, 'logDebug').mockImplementation(() => undefined);
|
||||
(checkSessionService as any).pollServerSession('clientId', config);
|
||||
expect(spyLogWarning).toHaveBeenCalledOnceWith(
|
||||
expect(spyLogWarning).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
jasmine.any(String)
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
|
||||
it('logs warning if clientId is not set', () => {
|
||||
spyOn<any>(checkSessionService, 'getExistingIframe').and.returnValue({});
|
||||
vi.spyOn<any>(checkSessionService, 'getExistingIframe').mockReturnValue(
|
||||
{}
|
||||
);
|
||||
const authWellKnownEndpoints = {
|
||||
checkSessionIframe: 'https://some-testing-url.com',
|
||||
};
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(storagePersistenceService, 'read')
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.and.returnValue(authWellKnownEndpoints);
|
||||
const spyLogWarning = spyOn(loggerService, 'logWarning').and.callFake(
|
||||
() => undefined
|
||||
mockImplementationWhenArgsEqual(
|
||||
vi.spyOn(storagePersistenceService, 'read'),
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
const spyLogWarning = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
|
||||
spyOn(loggerService, 'logDebug').and.callFake(() => undefined);
|
||||
vi.spyOn(loggerService, 'logDebug').mockImplementation(() => undefined);
|
||||
(checkSessionService as any).pollServerSession('', config);
|
||||
expect(spyLogWarning).toHaveBeenCalledOnceWith(
|
||||
expect(spyLogWarning).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
jasmine.any(String)
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
|
||||
it('logs debug if session_state is not set', () => {
|
||||
spyOn<any>(checkSessionService, 'getExistingIframe').and.returnValue({});
|
||||
vi.spyOn<any>(checkSessionService, 'getExistingIframe').mockReturnValue(
|
||||
{}
|
||||
);
|
||||
const authWellKnownEndpoints = {
|
||||
checkSessionIframe: 'https://some-testing-url.com',
|
||||
};
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(storagePersistenceService, 'read')
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.and.returnValue(authWellKnownEndpoints)
|
||||
mockImplementationWhenArgsEqual(
|
||||
vi.spyOn(storagePersistenceService, 'read'),
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
)
|
||||
.withArgs('session_state', config)
|
||||
.and.returnValue(null);
|
||||
.mockReturnValue(null);
|
||||
|
||||
const spyLogDebug = spyOn(loggerService, 'logDebug').and.callFake(
|
||||
() => undefined
|
||||
);
|
||||
const spyLogDebug = vi
|
||||
.spyOn(loggerService, 'logDebug')
|
||||
.mockImplementation(() => undefined);
|
||||
|
||||
(checkSessionService as any).pollServerSession('clientId', config);
|
||||
expect(spyLogDebug).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('logs debug if session_state is set but authWellKnownEndpoints are not set', () => {
|
||||
spyOn<any>(checkSessionService, 'getExistingIframe').and.returnValue({});
|
||||
vi.spyOn<any>(checkSessionService, 'getExistingIframe').mockReturnValue(
|
||||
{}
|
||||
);
|
||||
const authWellKnownEndpoints = null;
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(storagePersistenceService, 'read')
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.and.returnValue(authWellKnownEndpoints)
|
||||
mockImplementationWhenArgsEqual(
|
||||
vi.spyOn(storagePersistenceService, 'read'),
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
)
|
||||
.withArgs('session_state', config)
|
||||
.and.returnValue('some_session_state');
|
||||
const spyLogDebug = spyOn(loggerService, 'logDebug').and.callFake(
|
||||
() => undefined
|
||||
);
|
||||
.mockReturnValue('some_session_state');
|
||||
const spyLogDebug = vi
|
||||
.spyOn(loggerService, 'logDebug')
|
||||
.mockImplementation(() => undefined);
|
||||
|
||||
(checkSessionService as any).pollServerSession('clientId', config);
|
||||
expect(spyLogDebug).toHaveBeenCalledTimes(2);
|
||||
@@ -290,7 +312,7 @@ describe('CheckSessionService', () => {
|
||||
});
|
||||
|
||||
describe('init', () => {
|
||||
it('returns falsy observable when lastIframerefresh and iframeRefreshInterval are bigger than now', waitForAsync(() => {
|
||||
it('returns falsy observable when lastIframerefresh and iframeRefreshInterval are bigger than now', async () => {
|
||||
const serviceAsAny = checkSessionService as any;
|
||||
const dateNow = new Date();
|
||||
const lastRefresh = dateNow.setMinutes(dateNow.getMinutes() + 30);
|
||||
@@ -301,7 +323,7 @@ describe('CheckSessionService', () => {
|
||||
serviceAsAny.init().subscribe((result: any) => {
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('isCheckSessionConfigured', () => {
|
||||
@@ -323,7 +345,7 @@ describe('CheckSessionService', () => {
|
||||
});
|
||||
|
||||
describe('checkSessionChanged$', () => {
|
||||
it('emits when internal event is thrown', waitForAsync(() => {
|
||||
it('emits when internal event is thrown', async () => {
|
||||
checkSessionService.checkSessionChanged$
|
||||
.pipe(skip(1))
|
||||
.subscribe((result) => {
|
||||
@@ -333,15 +355,15 @@ describe('CheckSessionService', () => {
|
||||
const serviceAsAny = checkSessionService as any;
|
||||
|
||||
serviceAsAny.checkSessionChangedInternal$.next(true);
|
||||
}));
|
||||
});
|
||||
|
||||
it('emits false initially', waitForAsync(() => {
|
||||
it('emits false initially', async () => {
|
||||
checkSessionService.checkSessionChanged$.subscribe((result) => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('emits false then true when emitted', waitForAsync(() => {
|
||||
it('emits false then true when emitted', async () => {
|
||||
const expectedResultsInOrder = [false, true];
|
||||
let counter = 0;
|
||||
|
||||
@@ -351,6 +373,6 @@ describe('CheckSessionService', () => {
|
||||
});
|
||||
|
||||
(checkSessionService as any).checkSessionChangedInternal$.next(true);
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { TestBed } from '@/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { mockProvider } from '../../test/auto-mock';
|
||||
import { vi } from 'vitest';
|
||||
import { LoggerService } from '../logging/logger.service';
|
||||
import { mockProvider } from '../testing/mock';
|
||||
import { UrlService } from '../utils/url/url.service';
|
||||
import { RefreshSessionIframeService } from './refresh-session-iframe.service';
|
||||
import { SilentRenewService } from './silent-renew.service';
|
||||
@@ -31,37 +32,43 @@ describe('RefreshSessionIframeService ', () => {
|
||||
});
|
||||
|
||||
describe('refreshSessionWithIframe', () => {
|
||||
it('calls sendAuthorizeRequestUsingSilentRenew with created url', waitForAsync(() => {
|
||||
spyOn(urlService, 'getRefreshSessionSilentRenewUrl').and.returnValue(
|
||||
it('calls sendAuthorizeRequestUsingSilentRenew with created url', async () => {
|
||||
vi.spyOn(urlService, 'getRefreshSessionSilentRenewUrl').mockReturnValue(
|
||||
of('a-url')
|
||||
);
|
||||
const sendAuthorizeRequestUsingSilentRenewSpy = spyOn(
|
||||
refreshSessionIframeService as any,
|
||||
'sendAuthorizeRequestUsingSilentRenew'
|
||||
).and.returnValue(of(null));
|
||||
const sendAuthorizeRequestUsingSilentRenewSpy = vi
|
||||
.spyOn(
|
||||
refreshSessionIframeService as any,
|
||||
'sendAuthorizeRequestUsingSilentRenew'
|
||||
)
|
||||
.mockReturnValue(of(null));
|
||||
const allConfigs = [{ configId: 'configId1' }];
|
||||
|
||||
refreshSessionIframeService
|
||||
.refreshSessionWithIframe(allConfigs[0], allConfigs)
|
||||
.refreshSessionWithIframe(allConfigs[0]!, allConfigs)
|
||||
.subscribe(() => {
|
||||
expect(
|
||||
sendAuthorizeRequestUsingSilentRenewSpy
|
||||
).toHaveBeenCalledOnceWith('a-url', allConfigs[0], allConfigs);
|
||||
).toHaveBeenCalledExactlyOnceWith(
|
||||
'a-url',
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('initSilentRenewRequest', () => {
|
||||
it('dispatches customevent to window object', waitForAsync(() => {
|
||||
const dispatchEventSpy = spyOn(window, 'dispatchEvent');
|
||||
it('dispatches customevent to window object', async () => {
|
||||
const dispatchEventSpy = vi.spyOn(window, 'dispatchEvent');
|
||||
|
||||
(refreshSessionIframeService as any).initSilentRenewRequest();
|
||||
|
||||
expect(dispatchEventSpy).toHaveBeenCalledOnceWith(
|
||||
expect(dispatchEventSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
new CustomEvent('oidc-silent-renew-init', {
|
||||
detail: jasmine.any(Number),
|
||||
detail: expect.any(Number),
|
||||
})
|
||||
);
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DOCUMENT } from '../dom';
|
||||
import { Injectable, RendererFactory2, inject } from 'injection-js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { OpenIdConfiguration } from '../config/openid-configuration';
|
||||
import type { OpenIdConfiguration } from '../config/openid-configuration';
|
||||
import { DOCUMENT } from '../dom';
|
||||
import { LoggerService } from '../logging/logger.service';
|
||||
import { UrlService } from '../utils/url/url.service';
|
||||
import { SilentRenewService } from './silent-renew.service';
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
|
||||
import { TestBed, fakeAsync, tick } from '@/testing';
|
||||
import { Observable, of, throwError } from 'rxjs';
|
||||
import { mockProvider } from '../../test/auto-mock';
|
||||
import { vi } from 'vitest';
|
||||
import { AuthStateService } from '../auth-state/auth-state.service';
|
||||
import { ImplicitFlowCallbackService } from '../callback/implicit-flow-callback.service';
|
||||
import { IntervalService } from '../callback/interval.service';
|
||||
import { CallbackContext } from '../flows/callback-context';
|
||||
import type { CallbackContext } from '../flows/callback-context';
|
||||
import { FlowsDataService } from '../flows/flows-data.service';
|
||||
import { FlowsService } from '../flows/flows.service';
|
||||
import { ResetAuthDataService } from '../flows/reset-auth-data.service';
|
||||
import { LoggerService } from '../logging/logger.service';
|
||||
import { mockProvider } from '../testing/mock';
|
||||
import { FlowHelper } from '../utils/flowHelper/flow-helper.service';
|
||||
import { ValidationResult } from '../validation/validation-result';
|
||||
import { IFrameService } from './existing-iframe.service';
|
||||
@@ -63,7 +64,7 @@ describe('SilentRenewService ', () => {
|
||||
describe('refreshSessionWithIFrameCompleted', () => {
|
||||
it('is of type observable', () => {
|
||||
expect(silentRenewService.refreshSessionWithIFrameCompleted$).toEqual(
|
||||
jasmine.any(Observable)
|
||||
expect.any(Observable)
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -95,7 +96,7 @@ describe('SilentRenewService ', () => {
|
||||
|
||||
describe('getOrCreateIframe', () => {
|
||||
it('returns iframe if iframe is truthy', () => {
|
||||
spyOn(silentRenewService as any, 'getExistingIframe').and.returnValue({
|
||||
vi.spyOn(silentRenewService as any, 'getExistingIframe').mockReturnValue({
|
||||
name: 'anything',
|
||||
});
|
||||
|
||||
@@ -109,31 +110,33 @@ describe('SilentRenewService ', () => {
|
||||
it('adds iframe to body if existing iframe is falsy', () => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(silentRenewService as any, 'getExistingIframe').and.returnValue(
|
||||
vi.spyOn(silentRenewService as any, 'getExistingIframe').mockReturnValue(
|
||||
null
|
||||
);
|
||||
|
||||
const spy = spyOn(iFrameService, 'addIFrameToWindowBody').and.returnValue(
|
||||
{ name: 'anything' } as HTMLIFrameElement
|
||||
);
|
||||
const spy = vi
|
||||
.spyOn(iFrameService, 'addIFrameToWindowBody')
|
||||
.mockReturnValue({ name: 'anything' } as HTMLIFrameElement);
|
||||
|
||||
const result = silentRenewService.getOrCreateIframe(config);
|
||||
|
||||
expect(result).toEqual({ name: 'anything' } as HTMLIFrameElement);
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
expect(spy).toHaveBeenCalledOnceWith('myiFrameForSilentRenew', config);
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
'myiFrameForSilentRenew',
|
||||
config
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('codeFlowCallbackSilentRenewIframe', () => {
|
||||
it('calls processSilentRenewCodeFlowCallback with correct arguments', waitForAsync(() => {
|
||||
it('calls processSilentRenewCodeFlowCallback with correct arguments', async () => {
|
||||
const config = { configId: 'configId1' };
|
||||
const allConfigs = [config];
|
||||
|
||||
const spy = spyOn(
|
||||
flowsService,
|
||||
'processSilentRenewCodeFlowCallback'
|
||||
).and.returnValue(of({} as CallbackContext));
|
||||
const spy = vi
|
||||
.spyOn(flowsService, 'processSilentRenewCodeFlowCallback')
|
||||
.mockReturnValue(of({} as CallbackContext));
|
||||
const expectedContext = {
|
||||
code: 'some-code',
|
||||
refreshToken: '',
|
||||
@@ -152,32 +155,31 @@ describe('SilentRenewService ', () => {
|
||||
silentRenewService
|
||||
.codeFlowCallbackSilentRenewIframe([url, urlParts], config, allConfigs)
|
||||
.subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
expect(spy).toHaveBeenCalledExactlyOnceWith(
|
||||
expectedContext,
|
||||
config,
|
||||
allConfigs
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('throws error if url has error param and resets everything on error', waitForAsync(() => {
|
||||
it('throws error if url has error param and resets everything on error', async () => {
|
||||
const config = { configId: 'configId1' };
|
||||
const allConfigs = [config];
|
||||
|
||||
const spy = spyOn(
|
||||
flowsService,
|
||||
'processSilentRenewCodeFlowCallback'
|
||||
).and.returnValue(of({} as CallbackContext));
|
||||
const authStateServiceSpy = spyOn(
|
||||
const spy = vi
|
||||
.spyOn(flowsService, 'processSilentRenewCodeFlowCallback')
|
||||
.mockReturnValue(of({} as CallbackContext));
|
||||
const authStateServiceSpy = vi.spyOn(
|
||||
authStateService,
|
||||
'updateAndPublishAuthState'
|
||||
);
|
||||
const resetAuthorizationDataSpy = spyOn(
|
||||
const resetAuthorizationDataSpy = vi.spyOn(
|
||||
resetAuthDataService,
|
||||
'resetAuthorizationData'
|
||||
);
|
||||
const setNonceSpy = spyOn(flowsDataService, 'setNonce');
|
||||
const stopPeriodicTokenCheckSpy = spyOn(
|
||||
const setNonceSpy = vi.spyOn(flowsDataService, 'setNonce');
|
||||
const stopPeriodicTokenCheckSpy = vi.spyOn(
|
||||
intervalService,
|
||||
'stopPeriodicTokenCheck'
|
||||
);
|
||||
@@ -191,121 +193,116 @@ describe('SilentRenewService ', () => {
|
||||
error: (error) => {
|
||||
expect(error).toEqual(new Error('some_error'));
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
expect(authStateServiceSpy).toHaveBeenCalledOnceWith({
|
||||
expect(authStateServiceSpy).toHaveBeenCalledExactlyOnceWith({
|
||||
isAuthenticated: false,
|
||||
validationResult: ValidationResult.LoginRequired,
|
||||
isRenewProcess: true,
|
||||
});
|
||||
expect(resetAuthorizationDataSpy).toHaveBeenCalledOnceWith(
|
||||
expect(resetAuthorizationDataSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
allConfigs
|
||||
);
|
||||
expect(setNonceSpy).toHaveBeenCalledOnceWith('', config);
|
||||
expect(setNonceSpy).toHaveBeenCalledExactlyOnceWith('', config);
|
||||
expect(stopPeriodicTokenCheckSpy).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('silentRenewEventHandler', () => {
|
||||
it('returns if no details is given', fakeAsync(() => {
|
||||
const isCurrentFlowCodeFlowSpy = spyOn(
|
||||
flowHelper,
|
||||
'isCurrentFlowCodeFlow'
|
||||
).and.returnValue(false);
|
||||
it('returns if no details is given', async () => {
|
||||
const isCurrentFlowCodeFlowSpy = vi
|
||||
.spyOn(flowHelper, 'isCurrentFlowCodeFlow')
|
||||
.mockReturnValue(false);
|
||||
|
||||
spyOn(
|
||||
vi.spyOn(
|
||||
implicitFlowCallbackService,
|
||||
'authenticatedImplicitFlowCallback'
|
||||
).and.returnValue(of({} as CallbackContext));
|
||||
).mockReturnValue(of({} as CallbackContext));
|
||||
const eventData = { detail: null } as CustomEvent;
|
||||
const allConfigs = [{ configId: 'configId1' }];
|
||||
|
||||
silentRenewService.silentRenewEventHandler(
|
||||
eventData,
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
tick(1000);
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(isCurrentFlowCodeFlowSpy).not.toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls authorizedImplicitFlowCallback if current flow is not code flow', fakeAsync(() => {
|
||||
const isCurrentFlowCodeFlowSpy = spyOn(
|
||||
flowHelper,
|
||||
'isCurrentFlowCodeFlow'
|
||||
).and.returnValue(false);
|
||||
const authorizedImplicitFlowCallbackSpy = spyOn(
|
||||
implicitFlowCallbackService,
|
||||
'authenticatedImplicitFlowCallback'
|
||||
).and.returnValue(of({} as CallbackContext));
|
||||
it('calls authorizedImplicitFlowCallback if current flow is not code flow', async () => {
|
||||
const isCurrentFlowCodeFlowSpy = vi
|
||||
.spyOn(flowHelper, 'isCurrentFlowCodeFlow')
|
||||
.mockReturnValue(false);
|
||||
const authorizedImplicitFlowCallbackSpy = vi
|
||||
.spyOn(implicitFlowCallbackService, 'authenticatedImplicitFlowCallback')
|
||||
.mockReturnValue(of({} as CallbackContext));
|
||||
const eventData = { detail: 'detail' } as CustomEvent;
|
||||
const allConfigs = [{ configId: 'configId1' }];
|
||||
|
||||
silentRenewService.silentRenewEventHandler(
|
||||
eventData,
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
tick(1000);
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(isCurrentFlowCodeFlowSpy).toHaveBeenCalled();
|
||||
expect(authorizedImplicitFlowCallbackSpy).toHaveBeenCalledOnceWith(
|
||||
allConfigs[0],
|
||||
expect(authorizedImplicitFlowCallbackSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
allConfigs[0]!,
|
||||
allConfigs,
|
||||
'detail'
|
||||
);
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls codeFlowCallbackSilentRenewIframe if current flow is code flow', fakeAsync(() => {
|
||||
spyOn(flowHelper, 'isCurrentFlowCodeFlow').and.returnValue(true);
|
||||
const codeFlowCallbackSilentRenewIframe = spyOn(
|
||||
silentRenewService,
|
||||
'codeFlowCallbackSilentRenewIframe'
|
||||
).and.returnValue(of({} as CallbackContext));
|
||||
it('calls codeFlowCallbackSilentRenewIframe if current flow is code flow', async () => {
|
||||
vi.spyOn(flowHelper, 'isCurrentFlowCodeFlow').mockReturnValue(true);
|
||||
const codeFlowCallbackSilentRenewIframe = vi
|
||||
.spyOn(silentRenewService, 'codeFlowCallbackSilentRenewIframe')
|
||||
.mockReturnValue(of({} as CallbackContext));
|
||||
const eventData = { detail: 'detail?detail2' } as CustomEvent;
|
||||
const allConfigs = [{ configId: 'configId1' }];
|
||||
|
||||
silentRenewService.silentRenewEventHandler(
|
||||
eventData,
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
tick(1000);
|
||||
expect(codeFlowCallbackSilentRenewIframe).toHaveBeenCalledOnceWith(
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(codeFlowCallbackSilentRenewIframe).toHaveBeenCalledExactlyOnceWith(
|
||||
['detail', 'detail2'],
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls authorizedImplicitFlowCallback if current flow is not code flow', fakeAsync(() => {
|
||||
spyOn(flowHelper, 'isCurrentFlowCodeFlow').and.returnValue(true);
|
||||
const codeFlowCallbackSilentRenewIframe = spyOn(
|
||||
silentRenewService,
|
||||
'codeFlowCallbackSilentRenewIframe'
|
||||
).and.returnValue(of({} as CallbackContext));
|
||||
it('calls authorizedImplicitFlowCallback if current flow is not code flow', async () => {
|
||||
vi.spyOn(flowHelper, 'isCurrentFlowCodeFlow').mockReturnValue(true);
|
||||
const codeFlowCallbackSilentRenewIframe = vi
|
||||
.spyOn(silentRenewService, 'codeFlowCallbackSilentRenewIframe')
|
||||
.mockReturnValue(of({} as CallbackContext));
|
||||
const eventData = { detail: 'detail?detail2' } as CustomEvent;
|
||||
const allConfigs = [{ configId: 'configId1' }];
|
||||
|
||||
silentRenewService.silentRenewEventHandler(
|
||||
eventData,
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
tick(1000);
|
||||
expect(codeFlowCallbackSilentRenewIframe).toHaveBeenCalledOnceWith(
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(codeFlowCallbackSilentRenewIframe).toHaveBeenCalledExactlyOnceWith(
|
||||
['detail', 'detail2'],
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls next on refreshSessionWithIFrameCompleted with callbackcontext', fakeAsync(() => {
|
||||
spyOn(flowHelper, 'isCurrentFlowCodeFlow').and.returnValue(true);
|
||||
spyOn(
|
||||
it('calls next on refreshSessionWithIFrameCompleted with callbackcontext', async () => {
|
||||
vi.spyOn(flowHelper, 'isCurrentFlowCodeFlow').mockReturnValue(true);
|
||||
vi.spyOn(
|
||||
silentRenewService,
|
||||
'codeFlowCallbackSilentRenewIframe'
|
||||
).and.returnValue(
|
||||
).mockReturnValue(
|
||||
of({ refreshToken: 'callbackContext' } as CallbackContext)
|
||||
);
|
||||
const eventData = { detail: 'detail?detail2' } as CustomEvent;
|
||||
@@ -321,42 +318,42 @@ describe('SilentRenewService ', () => {
|
||||
|
||||
silentRenewService.silentRenewEventHandler(
|
||||
eventData,
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
tick(1000);
|
||||
}));
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
});
|
||||
|
||||
it('loggs and calls flowsDataService.resetSilentRenewRunning in case of an error', fakeAsync(() => {
|
||||
spyOn(flowHelper, 'isCurrentFlowCodeFlow').and.returnValue(true);
|
||||
spyOn(
|
||||
it('loggs and calls flowsDataService.resetSilentRenewRunning in case of an error', async () => {
|
||||
vi.spyOn(flowHelper, 'isCurrentFlowCodeFlow').mockReturnValue(true);
|
||||
vi.spyOn(
|
||||
silentRenewService,
|
||||
'codeFlowCallbackSilentRenewIframe'
|
||||
).and.returnValue(throwError(() => new Error('ERROR')));
|
||||
const resetSilentRenewRunningSpy = spyOn(
|
||||
).mockReturnValue(throwError(() => new Error('ERROR')));
|
||||
const resetSilentRenewRunningSpy = vi.spyOn(
|
||||
flowsDataService,
|
||||
'resetSilentRenewRunning'
|
||||
);
|
||||
const logErrorSpy = spyOn(loggerService, 'logError');
|
||||
const logErrorSpy = vi.spyOn(loggerService, 'logError');
|
||||
const allConfigs = [{ configId: 'configId1' }];
|
||||
const eventData = { detail: 'detail?detail2' } as CustomEvent;
|
||||
|
||||
silentRenewService.silentRenewEventHandler(
|
||||
eventData,
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
tick(1000);
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(resetSilentRenewRunningSpy).toHaveBeenCalledTimes(1);
|
||||
expect(logErrorSpy).toHaveBeenCalledTimes(1);
|
||||
}));
|
||||
});
|
||||
|
||||
it('calls next on refreshSessionWithIFrameCompleted with null in case of error', fakeAsync(() => {
|
||||
spyOn(flowHelper, 'isCurrentFlowCodeFlow').and.returnValue(true);
|
||||
spyOn(
|
||||
it('calls next on refreshSessionWithIFrameCompleted with null in case of error', async () => {
|
||||
vi.spyOn(flowHelper, 'isCurrentFlowCodeFlow').mockReturnValue(true);
|
||||
vi.spyOn(
|
||||
silentRenewService,
|
||||
'codeFlowCallbackSilentRenewIframe'
|
||||
).and.returnValue(throwError(() => new Error('ERROR')));
|
||||
).mockReturnValue(throwError(() => new Error('ERROR')));
|
||||
const eventData = { detail: 'detail?detail2' } as CustomEvent;
|
||||
const allConfigs = [{ configId: 'configId1' }];
|
||||
|
||||
@@ -368,10 +365,10 @@ describe('SilentRenewService ', () => {
|
||||
|
||||
silentRenewService.silentRenewEventHandler(
|
||||
eventData,
|
||||
allConfigs[0],
|
||||
allConfigs[0]!,
|
||||
allConfigs
|
||||
);
|
||||
tick(1000);
|
||||
}));
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { HttpParams } from '@ngify/http';
|
||||
import { inject, Injectable } from 'injection-js';
|
||||
import { Observable, Subject, throwError } from 'rxjs';
|
||||
import { Injectable, inject } from 'injection-js';
|
||||
import { type Observable, Subject, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { AuthStateService } from '../auth-state/auth-state.service';
|
||||
import { ImplicitFlowCallbackService } from '../callback/implicit-flow-callback.service';
|
||||
import { IntervalService } from '../callback/interval.service';
|
||||
import { OpenIdConfiguration } from '../config/openid-configuration';
|
||||
import { CallbackContext } from '../flows/callback-context';
|
||||
import type { OpenIdConfiguration } from '../config/openid-configuration';
|
||||
import type { CallbackContext } from '../flows/callback-context';
|
||||
import { FlowsDataService } from '../flows/flows-data.service';
|
||||
import { FlowsService } from '../flows/flows.service';
|
||||
import { ResetAuthDataService } from '../flows/reset-auth-data.service';
|
||||
|
||||
Reference in New Issue
Block a user