-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shaed Parkar
committed
May 2, 2024
1 parent
c9e8b7b
commit 5cc9de7
Showing
12 changed files
with
373 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,3 +349,4 @@ TESTS.xml | |
Coverage/ | ||
**/SpecFlow/userid | ||
.angular/ | ||
.nx/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
VideoWeb/VideoWeb/ClientApp/src/app/security/guards/already-authenticated-dom1.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { AlreadyAuthenticatedDom1Guard } from './already-authenticated-dom1.guard'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { Subject, of } from 'rxjs'; | ||
import { Router } from '@angular/router'; | ||
import { ISecurityService } from '../authentication/security-service.interface'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
|
||
describe('AlreadyAuthenticatedDom1Guard', () => { | ||
let guard: AlreadyAuthenticatedDom1Guard; | ||
let isAuthenticatedSubject: Subject<boolean>; | ||
let securityServiceSpy: jasmine.SpyObj<ISecurityService>; | ||
let securityServiceProviderSpy: jasmine.SpyObj<SecurityServiceProvider>; | ||
let routerSpy: jasmine.SpyObj<Router>; | ||
|
||
beforeEach(() => { | ||
isAuthenticatedSubject = new Subject<boolean>(); | ||
securityServiceSpy = jasmine.createSpyObj<ISecurityService>('ISecurityService', ['isAuthenticated']); | ||
securityServiceSpy.isAuthenticated.and.returnValue(isAuthenticatedSubject.asObservable()); | ||
|
||
securityServiceProviderSpy = jasmine.createSpyObj<SecurityServiceProvider>('SecurityServiceProvider', ['getSecurityService']); | ||
securityServiceProviderSpy.getSecurityService.and.returnValue(securityServiceSpy); | ||
|
||
routerSpy = jasmine.createSpyObj<Router>('Router', ['navigate']); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: SecurityServiceProvider, useValue: securityServiceProviderSpy }, | ||
{ provide: Router, useValue: routerSpy } | ||
] | ||
}); | ||
guard = TestBed.inject(AlreadyAuthenticatedDom1Guard); | ||
}); | ||
|
||
it('should return true if not authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(false)); | ||
|
||
// act | ||
let result: boolean; | ||
guard.canActivate().subscribe(res => (result = res)); | ||
tick(); | ||
|
||
// assert | ||
expect(result).toBeTrue(); | ||
})); | ||
|
||
it('should navigate to home page if already authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(true)); | ||
|
||
// act | ||
guard.canActivate().subscribe(); | ||
tick(); | ||
|
||
// assert | ||
expect(routerSpy.navigate).toHaveBeenCalledWith([pageUrls.Home]); | ||
})); | ||
}); |
32 changes: 32 additions & 0 deletions
32
VideoWeb/VideoWeb/ClientApp/src/app/security/guards/already-authenticated-dom1.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
import { take, tap, map, timeout } from 'rxjs/operators'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { IdpProviders } from '../idp-providers'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class AlreadyAuthenticatedDom1Guard { | ||
currentIdp: IdpProviders = IdpProviders.dom1; | ||
constructor( | ||
private securityServiceProvider: SecurityServiceProvider, | ||
private router: Router | ||
) {} | ||
|
||
canActivate(): Observable<boolean> { | ||
return this.securityServiceProvider | ||
.getSecurityService(this.currentIdp) | ||
.isAuthenticated(this.currentIdp) | ||
.pipe( | ||
timeout(30000), | ||
take(1), | ||
tap(authenticated => { | ||
if (authenticated) { | ||
this.router.navigate([pageUrls.Home]); | ||
} | ||
}), | ||
map(authenticated => !authenticated) | ||
); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
VideoWeb/VideoWeb/ClientApp/src/app/security/guards/already-authenticated-ejud.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { Subject, of } from 'rxjs'; | ||
import { Router } from '@angular/router'; | ||
import { ISecurityService } from '../authentication/security-service.interface'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
import { AlreadyAuthenticatedEjudGuard } from './already-authenticated-ejud.guard'; | ||
|
||
describe('AlreadyAuthenticatedDom1Guard', () => { | ||
let guard: AlreadyAuthenticatedEjudGuard; | ||
let isAuthenticatedSubject: Subject<boolean>; | ||
let securityServiceSpy: jasmine.SpyObj<ISecurityService>; | ||
let securityServiceProviderSpy: jasmine.SpyObj<SecurityServiceProvider>; | ||
let routerSpy: jasmine.SpyObj<Router>; | ||
|
||
beforeEach(() => { | ||
isAuthenticatedSubject = new Subject<boolean>(); | ||
securityServiceSpy = jasmine.createSpyObj<ISecurityService>('ISecurityService', ['isAuthenticated']); | ||
securityServiceSpy.isAuthenticated.and.returnValue(isAuthenticatedSubject.asObservable()); | ||
|
||
securityServiceProviderSpy = jasmine.createSpyObj<SecurityServiceProvider>('SecurityServiceProvider', ['getSecurityService']); | ||
securityServiceProviderSpy.getSecurityService.and.returnValue(securityServiceSpy); | ||
|
||
routerSpy = jasmine.createSpyObj<Router>('Router', ['navigate']); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: SecurityServiceProvider, useValue: securityServiceProviderSpy }, | ||
{ provide: Router, useValue: routerSpy } | ||
] | ||
}); | ||
guard = TestBed.inject(AlreadyAuthenticatedEjudGuard); | ||
}); | ||
|
||
it('should return true if not authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(false)); | ||
|
||
// act | ||
let result: boolean; | ||
guard.canActivate().subscribe(res => (result = res)); | ||
tick(); | ||
|
||
// assert | ||
expect(result).toBeTrue(); | ||
})); | ||
|
||
it('should navigate to home page if already authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(true)); | ||
|
||
// act | ||
guard.canActivate().subscribe(); | ||
tick(); | ||
|
||
// assert | ||
expect(routerSpy.navigate).toHaveBeenCalledWith([pageUrls.Home]); | ||
})); | ||
}); |
32 changes: 32 additions & 0 deletions
32
VideoWeb/VideoWeb/ClientApp/src/app/security/guards/already-authenticated-ejud.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
import { take, tap, map, timeout } from 'rxjs/operators'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { IdpProviders } from '../idp-providers'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class AlreadyAuthenticatedEjudGuard { | ||
currentIdp: IdpProviders = IdpProviders.ejud; | ||
constructor( | ||
private securityServiceProvider: SecurityServiceProvider, | ||
private router: Router | ||
) {} | ||
|
||
canActivate(): Observable<boolean> { | ||
return this.securityServiceProvider | ||
.getSecurityService(this.currentIdp) | ||
.isAuthenticated(this.currentIdp) | ||
.pipe( | ||
timeout(30000), | ||
take(1), | ||
tap(authenticated => { | ||
if (authenticated) { | ||
this.router.navigate([pageUrls.Home]); | ||
} | ||
}), | ||
map(authenticated => !authenticated) | ||
); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...VideoWeb/ClientApp/src/app/security/guards/already-authenticated-quick-link.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { Subject, of } from 'rxjs'; | ||
import { Router } from '@angular/router'; | ||
import { ISecurityService } from '../authentication/security-service.interface'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
import { AlreadyAuthenticatedQuickLinkGuard } from './already-authenticated-quick-link.guard'; | ||
|
||
describe('AlreadyAuthenticatedDom1Guard', () => { | ||
let guard: AlreadyAuthenticatedQuickLinkGuard; | ||
let isAuthenticatedSubject: Subject<boolean>; | ||
let securityServiceSpy: jasmine.SpyObj<ISecurityService>; | ||
let securityServiceProviderSpy: jasmine.SpyObj<SecurityServiceProvider>; | ||
let routerSpy: jasmine.SpyObj<Router>; | ||
|
||
beforeEach(() => { | ||
isAuthenticatedSubject = new Subject<boolean>(); | ||
securityServiceSpy = jasmine.createSpyObj<ISecurityService>('ISecurityService', ['isAuthenticated']); | ||
securityServiceSpy.isAuthenticated.and.returnValue(isAuthenticatedSubject.asObservable()); | ||
|
||
securityServiceProviderSpy = jasmine.createSpyObj<SecurityServiceProvider>('SecurityServiceProvider', ['getSecurityService']); | ||
securityServiceProviderSpy.getSecurityService.and.returnValue(securityServiceSpy); | ||
|
||
routerSpy = jasmine.createSpyObj<Router>('Router', ['navigate']); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: SecurityServiceProvider, useValue: securityServiceProviderSpy }, | ||
{ provide: Router, useValue: routerSpy } | ||
] | ||
}); | ||
guard = TestBed.inject(AlreadyAuthenticatedQuickLinkGuard); | ||
}); | ||
|
||
it('should return true if not authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(false)); | ||
|
||
// act | ||
let result: boolean; | ||
guard.canActivate().subscribe(res => (result = res)); | ||
tick(); | ||
|
||
// assert | ||
expect(result).toBeTrue(); | ||
})); | ||
|
||
it('should navigate to home page if already authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(true)); | ||
|
||
// act | ||
guard.canActivate().subscribe(); | ||
tick(); | ||
|
||
// assert | ||
expect(routerSpy.navigate).toHaveBeenCalledWith([pageUrls.Home]); | ||
})); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...oWeb/VideoWeb/ClientApp/src/app/security/guards/already-authenticated-quick-link.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
import { take, tap, map, timeout } from 'rxjs/operators'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { IdpProviders } from '../idp-providers'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class AlreadyAuthenticatedQuickLinkGuard { | ||
currentIdp: IdpProviders = IdpProviders.quickLink; | ||
constructor( | ||
private securityServiceProvider: SecurityServiceProvider, | ||
private router: Router | ||
) {} | ||
|
||
canActivate(): Observable<boolean> { | ||
return this.securityServiceProvider | ||
.getSecurityService(this.currentIdp) | ||
.isAuthenticated(this.currentIdp) | ||
.pipe( | ||
timeout(30000), | ||
take(1), | ||
tap(authenticated => { | ||
if (authenticated) { | ||
this.router.navigate([pageUrls.Home]); | ||
} | ||
}), | ||
map(authenticated => !authenticated) | ||
); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
VideoWeb/VideoWeb/ClientApp/src/app/security/guards/already-authenticated-vh.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { Subject, of } from 'rxjs'; | ||
import { Router } from '@angular/router'; | ||
import { ISecurityService } from '../authentication/security-service.interface'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
import { AlreadyAuthenticatedVhGuard } from './already-authenticated-vh.guard'; | ||
|
||
describe('AlreadyAuthenticatedDom1Guard', () => { | ||
let guard: AlreadyAuthenticatedVhGuard; | ||
let isAuthenticatedSubject: Subject<boolean>; | ||
let securityServiceSpy: jasmine.SpyObj<ISecurityService>; | ||
let securityServiceProviderSpy: jasmine.SpyObj<SecurityServiceProvider>; | ||
let routerSpy: jasmine.SpyObj<Router>; | ||
|
||
beforeEach(() => { | ||
isAuthenticatedSubject = new Subject<boolean>(); | ||
securityServiceSpy = jasmine.createSpyObj<ISecurityService>('ISecurityService', ['isAuthenticated']); | ||
securityServiceSpy.isAuthenticated.and.returnValue(isAuthenticatedSubject.asObservable()); | ||
|
||
securityServiceProviderSpy = jasmine.createSpyObj<SecurityServiceProvider>('SecurityServiceProvider', ['getSecurityService']); | ||
securityServiceProviderSpy.getSecurityService.and.returnValue(securityServiceSpy); | ||
|
||
routerSpy = jasmine.createSpyObj<Router>('Router', ['navigate']); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: SecurityServiceProvider, useValue: securityServiceProviderSpy }, | ||
{ provide: Router, useValue: routerSpy } | ||
] | ||
}); | ||
guard = TestBed.inject(AlreadyAuthenticatedVhGuard); | ||
}); | ||
|
||
it('should return true if not authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(false)); | ||
|
||
// act | ||
let result: boolean; | ||
guard.canActivate().subscribe(res => (result = res)); | ||
tick(); | ||
|
||
// assert | ||
expect(result).toBeTrue(); | ||
})); | ||
|
||
it('should navigate to home page if already authenticated', fakeAsync(() => { | ||
// arrange | ||
securityServiceSpy.isAuthenticated.and.returnValue(of(true)); | ||
|
||
// act | ||
guard.canActivate().subscribe(); | ||
tick(); | ||
|
||
// assert | ||
expect(routerSpy.navigate).toHaveBeenCalledWith([pageUrls.Home]); | ||
})); | ||
}); |
32 changes: 32 additions & 0 deletions
32
VideoWeb/VideoWeb/ClientApp/src/app/security/guards/already-authenticated-vh.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
import { take, tap, map, timeout } from 'rxjs/operators'; | ||
import { pageUrls } from 'src/app/shared/page-url.constants'; | ||
import { SecurityServiceProvider } from '../authentication/security-provider.service'; | ||
import { IdpProviders } from '../idp-providers'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class AlreadyAuthenticatedVhGuard { | ||
currentIdp: IdpProviders = IdpProviders.vhaad; | ||
constructor( | ||
private securityServiceProvider: SecurityServiceProvider, | ||
private router: Router | ||
) {} | ||
|
||
canActivate(): Observable<boolean> { | ||
return this.securityServiceProvider | ||
.getSecurityService(this.currentIdp) | ||
.isAuthenticated(this.currentIdp) | ||
.pipe( | ||
timeout(30000), | ||
take(1), | ||
tap(authenticated => { | ||
if (authenticated) { | ||
this.router.navigate([pageUrls.Home]); | ||
} | ||
}), | ||
map(authenticated => !authenticated) | ||
); | ||
} | ||
} |
Oops, something went wrong.