]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/services/no-sso-guard.service.spec.ts
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / services / no-sso-guard.service.spec.ts
CommitLineData
9f95a23c
TL
1import { Component, NgZone } from '@angular/core';
2import { fakeAsync, TestBed, tick } from '@angular/core/testing';
f67539c2 3import { Routes } from '@angular/router';
9f95a23c
TL
4import { RouterTestingModule } from '@angular/router/testing';
5
f67539c2
TL
6import { DashboardUserDeniedError } from '~/app/core/error/error';
7import { configureTestBed } from '~/testing/unit-test-helper';
9f95a23c
TL
8import { AuthStorageService } from './auth-storage.service';
9import { NoSsoGuardService } from './no-sso-guard.service';
10
11describe('NoSsoGuardService', () => {
12 let service: NoSsoGuardService;
13 let authStorageService: AuthStorageService;
14 let ngZone: NgZone;
9f95a23c
TL
15
16 @Component({ selector: 'cd-404', template: '' })
17 class NotFoundComponent {}
18
19 const routes: Routes = [{ path: '404', component: NotFoundComponent }];
20
21 configureTestBed({
22 imports: [RouterTestingModule.withRoutes(routes)],
23 providers: [NoSsoGuardService, AuthStorageService],
24 declarations: [NotFoundComponent]
25 });
26
27 beforeEach(() => {
f67539c2
TL
28 service = TestBed.inject(NoSsoGuardService);
29 authStorageService = TestBed.inject(AuthStorageService);
30 ngZone = TestBed.inject(NgZone);
9f95a23c
TL
31 });
32
33 it('should be created', () => {
34 expect(service).toBeTruthy();
35 });
36
37 it('should allow if not logged in via SSO', () => {
38 spyOn(authStorageService, 'isSSO').and.returnValue(false);
39 expect(service.canActivate()).toBe(true);
40 });
41
42 it('should prevent if logged in via SSO', fakeAsync(() => {
43 spyOn(authStorageService, 'isSSO').and.returnValue(true);
44 ngZone.run(() => {
f67539c2 45 expect(() => service.canActivate()).toThrowError(DashboardUserDeniedError);
9f95a23c
TL
46 });
47 tick();
9f95a23c
TL
48 }));
49});