[ACA-2211] auth guard: add support for withCredentials (#942)

* auth guard: add support for withCredentials

* formatting fixes

* remove fdescribe
This commit is contained in:
Denys Vuika
2019-02-14 06:45:37 +00:00
committed by Cilibiu Bogdan
parent bb5ce29445
commit e0e2a61821
2 changed files with 31 additions and 4 deletions

View File

@@ -26,7 +26,7 @@
import { AppAuthGuard } from './auth.guard'; import { AppAuthGuard } from './auth.guard';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../testing/app-testing.module'; import { AppTestingModule } from '../testing/app-testing.module';
import { AuthenticationService } from '@alfresco/adf-core'; import { AuthenticationService, AppConfigService } from '@alfresco/adf-core';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
@@ -34,6 +34,7 @@ describe('AppAuthGuard', () => {
let auth: AuthenticationService; let auth: AuthenticationService;
let guard: AppAuthGuard; let guard: AppAuthGuard;
let router: Router; let router: Router;
let config: AppConfigService;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -44,10 +45,31 @@ describe('AppAuthGuard', () => {
auth = TestBed.get(AuthenticationService); auth = TestBed.get(AuthenticationService);
guard = TestBed.get(AppAuthGuard); guard = TestBed.get(AppAuthGuard);
router = TestBed.get(Router); router = TestBed.get(Router);
config = TestBed.get(AppConfigService);
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
}); });
it('should fall through when withCredentials enabled', () => {
spyOn(auth, 'isEcmLoggedIn').and.returnValue(false);
config.config = {
auth: {
withCredentials: false
}
};
expect(guard.checkLogin(null)).toBe(false);
config.config = {
auth: {
withCredentials: true
}
};
expect(guard.checkLogin(null)).toBe(true);
});
it('should evaluate to [true] if logged in already', () => { it('should evaluate to [true] if logged in already', () => {
spyOn(auth, 'isEcmLoggedIn').and.returnValue(true); spyOn(auth, 'isEcmLoggedIn').and.returnValue(true);

View File

@@ -38,13 +38,18 @@ export class AppAuthGuard extends AuthGuardEcm {
constructor( constructor(
private _auth: AuthenticationService, private _auth: AuthenticationService,
private _router: Router, private _router: Router,
config: AppConfigService private _config: AppConfigService
) { ) {
super(_auth, _router, config); super(_auth, _router, _config);
} }
checkLogin(redirectUrl: string): boolean { checkLogin(redirectUrl: string): boolean {
if (this._auth.isEcmLoggedIn()) { const withCredentials = this._config.get<boolean>(
'auth.withCredentials',
false
);
if (withCredentials || this._auth.isEcmLoggedIn()) {
return true; return true;
} }