-
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.
Browse files
Browse the repository at this point in the history
…1298) * added manage new audio file format * added test * test fix * Update AudioPlatformController.cs * Update FeatureToggles.cs * resolving sonar clou vulnerability * added new feature toggle and guard to hide get audio file * test fix * update package * update package * lint fix
- Loading branch information
1 parent
1cdb598
commit 87e2167
Showing
16 changed files
with
225 additions
and
34 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
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
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
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
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
AdminWebsite/AdminWebsite/ClientApp/src/app/security/audio-search.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,45 @@ | ||
import { fakeAsync, TestBed } from '@angular/core/testing'; | ||
import { AuthGuard } from './auth.guard'; | ||
import { Router } from '@angular/router'; | ||
import { MockOidcSecurityService } from '../testing/mocks/MockOidcSecurityService'; | ||
import { OidcSecurityService } from 'angular-auth-oidc-client'; | ||
import { Logger } from '../services/logger'; | ||
import { AudioSearchGuard } from './audio-search.guard'; | ||
import { LaunchDarklyService } from '../services/launch-darkly.service'; | ||
import { MockLaunchDarklyService } from '../testing/mocks/MockLaunchDarklyService'; | ||
|
||
describe('audiosearchguard', () => { | ||
let audioSearchGuard: AudioSearchGuard; | ||
let launchDarklyService; | ||
const loggerSpy = jasmine.createSpyObj<Logger>('Logger', ['error', 'debug', 'warn']); | ||
const router = { | ||
navigate: jasmine.createSpy('navigate') | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
AudioSearchGuard, | ||
{ provide: LaunchDarklyService, useClass: MockLaunchDarklyService }, | ||
{ provide: Router, useValue: router }, | ||
{ provide: Logger, useValue: loggerSpy } | ||
] | ||
}).compileComponents(); | ||
launchDarklyService = TestBed.inject(LaunchDarklyService); | ||
audioSearchGuard = TestBed.inject(AudioSearchGuard); | ||
}); | ||
|
||
describe('when toggle off with successful authentication', () => { | ||
it('canActivate should return true', () => { | ||
launchDarklyService.setAudioSearchFlag(false); | ||
audioSearchGuard.canActivate().subscribe(result => expect(result).toBeTruthy()); | ||
}); | ||
}); | ||
|
||
describe('when toggle is on with successful authentication', () => { | ||
it('canActivate should return false', fakeAsync(() => { | ||
launchDarklyService.setAudioSearchFlag(true); | ||
audioSearchGuard.canActivate().subscribe(result => expect(result).toBeFalsy()); | ||
})); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
AdminWebsite/AdminWebsite/ClientApp/src/app/security/audio-search.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,28 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { CanActivate, Router } from '@angular/router'; | ||
import { AuthenticatedResult, OidcSecurityService } from 'angular-auth-oidc-client'; | ||
import { Observable, takeUntil } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { PageUrls } from '../shared/page-url.constants'; | ||
import { Logger } from '../services/logger'; | ||
import { FeatureFlags, LaunchDarklyService } from '../services/launch-darkly.service'; | ||
|
||
@Injectable() | ||
export class AudioSearchGuard implements CanActivate { | ||
private readonly loggerPrefix = '[AudioSearchGuard] -'; | ||
constructor(private launchDarklyService: LaunchDarklyService, private router: Router, private logger: Logger) {} | ||
|
||
canActivate(): Observable<boolean> { | ||
return this.launchDarklyService.getFlag<boolean>(FeatureFlags.audioSearch).pipe( | ||
map(result => { | ||
if (result) { | ||
this.logger.warn(`${this.loggerPrefix} - canActivate isAuthorized: ` + !result); | ||
this.router.navigate([`/${PageUrls.Login}`]); | ||
return false; | ||
} | ||
this.logger.debug(`${this.loggerPrefix} - canActivate isAuthorized: ` + !result); | ||
return true; | ||
}) | ||
); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
AdminWebsite/AdminWebsite/ClientApp/src/app/testing/mocks/MockLaunchDarklyService.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,26 @@ | ||
import { OpenIdConfiguration, LoginResponse, AuthenticatedResult, ConfigAuthenticatedResult } from 'angular-auth-oidc-client'; | ||
import { LDFlagValue } from 'launchdarkly-js-client-sdk'; | ||
import { Observable, of } from 'rxjs'; | ||
|
||
class MockLoginResponse implements LoginResponse { | ||
constructor(isAuthenticated: boolean) { | ||
this.isAuthenticated = isAuthenticated; | ||
} | ||
|
||
isAuthenticated: boolean; | ||
userData: any; | ||
accessToken: string; | ||
idToken: string; | ||
configId: string; | ||
errorMessage?: string; | ||
} | ||
export class MockLaunchDarklyService { | ||
audioSearchFlag: boolean; | ||
|
||
setAudioSearchFlag(flag: boolean) { | ||
this.audioSearchFlag = flag; | ||
} | ||
getFlag<T>(flagKey: string, defaultValue: LDFlagValue = false): Observable<T> { | ||
return of(this.audioSearchFlag as T); | ||
} | ||
} |
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
Oops, something went wrong.