feat: init and fork some code from angular-auth-oidc-client
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run
This commit is contained in:
794
src/oidc.security.service.spec.ts
Normal file
794
src/oidc.security.service.spec.ts
Normal file
@@ -0,0 +1,794 @@
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { mockProvider } from '../test/auto-mock';
|
||||
import { AuthStateService } from './auth-state/auth-state.service';
|
||||
import { CheckAuthService } from './auth-state/check-auth.service';
|
||||
import { CallbackService } from './callback/callback.service';
|
||||
import { RefreshSessionService } from './callback/refresh-session.service';
|
||||
import { AuthWellKnownService } from './config/auth-well-known/auth-well-known.service';
|
||||
import { ConfigurationService } from './config/config.service';
|
||||
import { FlowsDataService } from './flows/flows-data.service';
|
||||
import { CheckSessionService } from './iframe/check-session.service';
|
||||
import { LoginResponse } from './login/login-response';
|
||||
import { LoginService } from './login/login.service';
|
||||
import { LogoffRevocationService } from './logoff-revoke/logoff-revocation.service';
|
||||
import { OidcSecurityService } from './oidc.security.service';
|
||||
import { UserService } from './user-data/user.service';
|
||||
import { TokenHelperService } from './utils/tokenHelper/token-helper.service';
|
||||
import { UrlService } from './utils/url/url.service';
|
||||
|
||||
describe('OidcSecurityService', () => {
|
||||
let oidcSecurityService: OidcSecurityService;
|
||||
let configurationService: ConfigurationService;
|
||||
let authStateService: AuthStateService;
|
||||
let authWellKnownService: AuthWellKnownService;
|
||||
let tokenHelperService: TokenHelperService;
|
||||
let flowsDataService: FlowsDataService;
|
||||
let logoffRevocationService: LogoffRevocationService;
|
||||
let loginService: LoginService;
|
||||
let refreshSessionService: RefreshSessionService;
|
||||
let checkAuthService: CheckAuthService;
|
||||
let checkSessionService: CheckSessionService;
|
||||
let userService: UserService;
|
||||
let urlService: UrlService;
|
||||
let callbackService: CallbackService;
|
||||
let authenticatedSpy: jasmine.Spy;
|
||||
let userDataSpy: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
providers: [
|
||||
OidcSecurityService,
|
||||
mockProvider(CheckSessionService),
|
||||
mockProvider(CheckAuthService),
|
||||
mockProvider(UserService),
|
||||
mockProvider(TokenHelperService),
|
||||
mockProvider(ConfigurationService),
|
||||
mockProvider(AuthStateService),
|
||||
mockProvider(FlowsDataService),
|
||||
mockProvider(CallbackService),
|
||||
mockProvider(LogoffRevocationService),
|
||||
mockProvider(LoginService),
|
||||
mockProvider(RefreshSessionService),
|
||||
mockProvider(UrlService),
|
||||
mockProvider(AuthWellKnownService),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
authStateService = TestBed.inject(AuthStateService);
|
||||
tokenHelperService = TestBed.inject(TokenHelperService);
|
||||
configurationService = TestBed.inject(ConfigurationService);
|
||||
flowsDataService = TestBed.inject(FlowsDataService);
|
||||
logoffRevocationService = TestBed.inject(LogoffRevocationService);
|
||||
loginService = TestBed.inject(LoginService);
|
||||
refreshSessionService = TestBed.inject(RefreshSessionService);
|
||||
checkAuthService = TestBed.inject(CheckAuthService);
|
||||
userService = TestBed.inject(UserService);
|
||||
urlService = TestBed.inject(UrlService);
|
||||
authWellKnownService = TestBed.inject(AuthWellKnownService);
|
||||
checkSessionService = TestBed.inject(CheckSessionService);
|
||||
callbackService = TestBed.inject(CallbackService);
|
||||
|
||||
// this is required because these methods will be invoked by the signal properties when the service is created
|
||||
authenticatedSpy = spyOnProperty(
|
||||
authStateService,
|
||||
'authenticated$'
|
||||
).and.returnValue(
|
||||
of({ isAuthenticated: false, allConfigsAuthenticated: [] })
|
||||
);
|
||||
userDataSpy = spyOnProperty(userService, 'userData$').and.returnValue(
|
||||
of({ userData: null, allUserData: [] })
|
||||
);
|
||||
oidcSecurityService = TestBed.inject(OidcSecurityService);
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(oidcSecurityService).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('userData$', () => {
|
||||
it('calls userService.userData$', waitForAsync(() => {
|
||||
oidcSecurityService.userData$.subscribe(() => {
|
||||
// 1x from this subscribe
|
||||
// 1x by the signal property
|
||||
expect(userDataSpy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('userData', () => {
|
||||
it('calls userService.userData$', waitForAsync(() => {
|
||||
const _userdata = oidcSecurityService.userData();
|
||||
|
||||
expect(userDataSpy).toHaveBeenCalledTimes(1);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('isAuthenticated$', () => {
|
||||
it('calls authStateService.isAuthenticated$', waitForAsync(() => {
|
||||
oidcSecurityService.isAuthenticated$.subscribe(() => {
|
||||
// 1x from this subscribe
|
||||
// 1x by the signal property
|
||||
expect(authenticatedSpy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('authenticated', () => {
|
||||
it('calls authStateService.isAuthenticated$', waitForAsync(() => {
|
||||
const _authenticated = oidcSecurityService.authenticated();
|
||||
|
||||
expect(authenticatedSpy).toHaveBeenCalledTimes(1);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('checkSessionChanged$', () => {
|
||||
it('calls checkSessionService.checkSessionChanged$', waitForAsync(() => {
|
||||
const spy = spyOnProperty(
|
||||
checkSessionService,
|
||||
'checkSessionChanged$'
|
||||
).and.returnValue(of(true));
|
||||
|
||||
oidcSecurityService.checkSessionChanged$.subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('stsCallback$', () => {
|
||||
it('calls callbackService.stsCallback$', waitForAsync(() => {
|
||||
const spy = spyOnProperty(
|
||||
callbackService,
|
||||
'stsCallback$'
|
||||
).and.returnValue(of());
|
||||
|
||||
oidcSecurityService.stsCallback$.subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('preloadAuthWellKnownDocument', () => {
|
||||
it('calls authWellKnownService.queryAndStoreAuthWellKnownEndPoints with config', waitForAsync(() => {
|
||||
const config = { configId: 'configid1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(
|
||||
authWellKnownService,
|
||||
'queryAndStoreAuthWellKnownEndPoints'
|
||||
).and.returnValue(of({}));
|
||||
|
||||
oidcSecurityService.preloadAuthWellKnownDocument().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getConfigurations', () => {
|
||||
it('is not of type observable', () => {
|
||||
expect(oidcSecurityService.getConfigurations).not.toEqual(
|
||||
jasmine.any(Observable)
|
||||
);
|
||||
});
|
||||
|
||||
it('calls configurationProvider.getAllConfigurations', () => {
|
||||
const spy = spyOn(configurationService, 'getAllConfigurations');
|
||||
|
||||
oidcSecurityService.getConfigurations();
|
||||
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getConfiguration', () => {
|
||||
it('is not of type observable', () => {
|
||||
expect(oidcSecurityService.getConfiguration).not.toEqual(
|
||||
jasmine.any(Observable)
|
||||
);
|
||||
});
|
||||
|
||||
it('calls configurationProvider.getOpenIDConfiguration with passed configId when configId is passed', () => {
|
||||
const spy = spyOn(configurationService, 'getOpenIDConfiguration');
|
||||
|
||||
oidcSecurityService.getConfiguration('configId');
|
||||
|
||||
expect(spy).toHaveBeenCalledOnceWith('configId');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getUserData', () => {
|
||||
it('calls configurationProvider.getOpenIDConfiguration with config', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(userService, 'getUserDataFromStore').and.returnValue({
|
||||
some: 'thing',
|
||||
});
|
||||
|
||||
oidcSecurityService.getUserData('configId').subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
|
||||
it('returns userdata', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
spyOn(userService, 'getUserDataFromStore').and.returnValue({
|
||||
some: 'thing',
|
||||
});
|
||||
|
||||
oidcSecurityService.getUserData('configId').subscribe((result) => {
|
||||
expect(result).toEqual({ some: 'thing' });
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('checkAuth', () => {
|
||||
it('calls checkAuthService.checkAuth() without url if none is passed', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
|
||||
const spy = spyOn(checkAuthService, 'checkAuth').and.returnValue(
|
||||
of({} as LoginResponse)
|
||||
);
|
||||
|
||||
oidcSecurityService.checkAuth().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, [config], undefined);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls checkAuthService.checkAuth() with url if one is passed', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
|
||||
const spy = spyOn(checkAuthService, 'checkAuth').and.returnValue(
|
||||
of({} as LoginResponse)
|
||||
);
|
||||
|
||||
oidcSecurityService.checkAuth('some-url').subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, [config], 'some-url');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('checkAuthMultiple', () => {
|
||||
it('calls checkAuthService.checkAuth() without url if none is passed', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
|
||||
const spy = spyOn(checkAuthService, 'checkAuthMultiple').and.returnValue(
|
||||
of([{}] as LoginResponse[])
|
||||
);
|
||||
|
||||
oidcSecurityService.checkAuthMultiple().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith([config], undefined);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls checkAuthService.checkAuthMultiple() with url if one is passed', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
|
||||
const spy = spyOn(checkAuthService, 'checkAuthMultiple').and.returnValue(
|
||||
of([{}] as LoginResponse[])
|
||||
);
|
||||
|
||||
oidcSecurityService.checkAuthMultiple('some-url').subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith([config], 'some-url');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('isAuthenticated()', () => {
|
||||
it('calls authStateService.isAuthenticated with passed configId when configId is passed', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(authStateService, 'isAuthenticated').and.returnValue(
|
||||
true
|
||||
);
|
||||
|
||||
oidcSecurityService.isAuthenticated().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('checkAuthIncludingServer', () => {
|
||||
it('calls checkAuthService.checkAuthIncludingServer()', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
|
||||
const spy = spyOn(
|
||||
checkAuthService,
|
||||
'checkAuthIncludingServer'
|
||||
).and.returnValue(of({} as LoginResponse));
|
||||
|
||||
oidcSecurityService.checkAuthIncludingServer().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, [config]);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getAccessToken', () => {
|
||||
it('calls authStateService.getAccessToken()', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(authStateService, 'getAccessToken').and.returnValue('');
|
||||
|
||||
oidcSecurityService.getAccessToken().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getIdToken', () => {
|
||||
it('calls authStateService.getIdToken()', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(authStateService, 'getIdToken').and.returnValue('');
|
||||
|
||||
oidcSecurityService.getIdToken().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getRefreshToken', () => {
|
||||
it('calls authStateService.getRefreshToken()', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(authStateService, 'getRefreshToken').and.returnValue(
|
||||
''
|
||||
);
|
||||
|
||||
oidcSecurityService.getRefreshToken().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getAuthenticationResult', () => {
|
||||
it('calls authStateService.getAuthenticationResult()', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(
|
||||
authStateService,
|
||||
'getAuthenticationResult'
|
||||
).and.returnValue(null);
|
||||
|
||||
oidcSecurityService.getAuthenticationResult().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getPayloadFromIdToken', () => {
|
||||
it('calls `authStateService.getIdToken` method, encode = false', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
spyOn(authStateService, 'getIdToken').and.returnValue('some-token');
|
||||
const spy = spyOn(
|
||||
tokenHelperService,
|
||||
'getPayloadFromToken'
|
||||
).and.returnValue(null);
|
||||
|
||||
oidcSecurityService.getPayloadFromIdToken().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith('some-token', false, config);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls `authStateService.getIdToken` method, encode = true', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
spyOn(authStateService, 'getIdToken').and.returnValue('some-token');
|
||||
const spy = spyOn(
|
||||
tokenHelperService,
|
||||
'getPayloadFromToken'
|
||||
).and.returnValue(null);
|
||||
|
||||
oidcSecurityService.getPayloadFromIdToken(true).subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith('some-token', true, config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getPayloadFromAccessToken', () => {
|
||||
it('calls `authStateService.getAccessToken` method, encode = false', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
spyOn(authStateService, 'getAccessToken').and.returnValue(
|
||||
'some-access-token'
|
||||
);
|
||||
const spy = spyOn(
|
||||
tokenHelperService,
|
||||
'getPayloadFromToken'
|
||||
).and.returnValue(null);
|
||||
|
||||
oidcSecurityService.getPayloadFromAccessToken().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
'some-access-token',
|
||||
false,
|
||||
config
|
||||
);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls `authStateService.getIdToken` method, encode = true', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
spyOn(authStateService, 'getAccessToken').and.returnValue(
|
||||
'some-access-token'
|
||||
);
|
||||
const spy = spyOn(
|
||||
tokenHelperService,
|
||||
'getPayloadFromToken'
|
||||
).and.returnValue(null);
|
||||
|
||||
oidcSecurityService.getPayloadFromAccessToken(true).subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith('some-access-token', true, config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('setState', () => {
|
||||
it('calls flowsDataService.setAuthStateControl with param', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(flowsDataService, 'setAuthStateControl');
|
||||
|
||||
oidcSecurityService.setState('anyString').subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith('anyString', config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getState', () => {
|
||||
it('calls flowsDataService.getAuthStateControl', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(flowsDataService, 'getAuthStateControl');
|
||||
|
||||
oidcSecurityService.getState().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('authorize', () => {
|
||||
it('calls login service login', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(loginService, 'login');
|
||||
|
||||
oidcSecurityService.authorize();
|
||||
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, undefined);
|
||||
}));
|
||||
|
||||
it('calls login service login with authoptions', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(loginService, 'login');
|
||||
|
||||
oidcSecurityService.authorize('configId', {
|
||||
customParams: { some: 'param' },
|
||||
});
|
||||
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, {
|
||||
customParams: { some: 'param' },
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('authorizeWithPopUp', () => {
|
||||
it('calls login service loginWithPopUp', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
const spy = spyOn(loginService, 'loginWithPopUp').and.callFake(() =>
|
||||
of({} as LoginResponse)
|
||||
);
|
||||
|
||||
oidcSecurityService.authorizeWithPopUp().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(
|
||||
config,
|
||||
[config],
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('forceRefreshSession', () => {
|
||||
it('calls refreshSessionService userForceRefreshSession with configId from config when none is passed', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
|
||||
const spy = spyOn(
|
||||
refreshSessionService,
|
||||
'userForceRefreshSession'
|
||||
).and.returnValue(of({} as LoginResponse));
|
||||
|
||||
oidcSecurityService.forceRefreshSession().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, [config], undefined);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('logoffAndRevokeTokens', () => {
|
||||
it('calls logoffRevocationService.logoffAndRevokeTokens', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
const spy = spyOn(
|
||||
logoffRevocationService,
|
||||
'logoffAndRevokeTokens'
|
||||
).and.returnValue(of(null));
|
||||
|
||||
oidcSecurityService.logoffAndRevokeTokens().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, [config], undefined);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('logoff', () => {
|
||||
it('calls logoffRevocationService.logoff', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
const spy = spyOn(logoffRevocationService, 'logoff').and.returnValue(
|
||||
of(null)
|
||||
);
|
||||
|
||||
oidcSecurityService.logoff().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, [config], undefined);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('logoffLocal', () => {
|
||||
it('calls logoffRevocationService.logoffLocal', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
const spy = spyOn(logoffRevocationService, 'logoffLocal');
|
||||
|
||||
oidcSecurityService.logoffLocal();
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, [config]);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('logoffLocalMultiple', () => {
|
||||
it('calls logoffRevocationService.logoffLocalMultiple', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfigurations').and.returnValue(
|
||||
of({ allConfigs: [config], currentConfig: config })
|
||||
);
|
||||
const spy = spyOn(logoffRevocationService, 'logoffLocalMultiple');
|
||||
|
||||
oidcSecurityService.logoffLocalMultiple();
|
||||
expect(spy).toHaveBeenCalledOnceWith([config]);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('revokeAccessToken', () => {
|
||||
it('calls logoffRevocationService.revokeAccessToken', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(
|
||||
logoffRevocationService,
|
||||
'revokeAccessToken'
|
||||
).and.returnValue(of(null));
|
||||
|
||||
oidcSecurityService.revokeAccessToken().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, undefined);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls logoffRevocationService.revokeAccessToken with accesstoken', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(
|
||||
logoffRevocationService,
|
||||
'revokeAccessToken'
|
||||
).and.returnValue(of(null));
|
||||
|
||||
oidcSecurityService.revokeAccessToken('access_token').subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, 'access_token');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('revokeRefreshToken', () => {
|
||||
it('calls logoffRevocationService.revokeRefreshToken', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(
|
||||
logoffRevocationService,
|
||||
'revokeRefreshToken'
|
||||
).and.returnValue(of(null));
|
||||
|
||||
oidcSecurityService.revokeRefreshToken().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, undefined);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls logoffRevocationService.revokeRefreshToken with refresh token', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
const spy = spyOn(
|
||||
logoffRevocationService,
|
||||
'revokeRefreshToken'
|
||||
).and.returnValue(of(null));
|
||||
|
||||
oidcSecurityService.revokeRefreshToken('refresh_token').subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, 'refresh_token');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getEndSessionUrl', () => {
|
||||
it('calls logoffRevocationService.getEndSessionUrl ', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(urlService, 'getEndSessionUrl').and.returnValue(null);
|
||||
|
||||
oidcSecurityService.getEndSessionUrl().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, undefined);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls logoffRevocationService.getEndSessionUrl with customparams', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(urlService, 'getEndSessionUrl').and.returnValue(null);
|
||||
|
||||
oidcSecurityService
|
||||
.getEndSessionUrl({ custom: 'params' })
|
||||
.subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, { custom: 'params' });
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('getAuthorizeUrl', () => {
|
||||
it('calls urlService.getAuthorizeUrl ', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(urlService, 'getAuthorizeUrl').and.returnValue(
|
||||
of(null)
|
||||
);
|
||||
|
||||
oidcSecurityService.getAuthorizeUrl().subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, undefined);
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls urlService.getAuthorizeUrl with customparams', waitForAsync(() => {
|
||||
const config = { configId: 'configId1' };
|
||||
|
||||
spyOn(configurationService, 'getOpenIDConfiguration').and.returnValue(
|
||||
of(config)
|
||||
);
|
||||
|
||||
const spy = spyOn(urlService, 'getAuthorizeUrl').and.returnValue(
|
||||
of(null)
|
||||
);
|
||||
|
||||
oidcSecurityService
|
||||
.getAuthorizeUrl({ custom: 'params' })
|
||||
.subscribe(() => {
|
||||
expect(spy).toHaveBeenCalledOnceWith(config, {
|
||||
customParams: { custom: 'params' },
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user