mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-10-08 14:51:14 +00:00
[ACA-2211] auth guard: add support for withCredentials (#942)
* auth guard: add support for withCredentials * formatting fixes * remove fdescribe
This commit is contained in:
committed by
Cilibiu Bogdan
parent
bb5ce29445
commit
e0e2a61821
@@ -26,7 +26,7 @@
|
||||
import { AppAuthGuard } from './auth.guard';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
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 { Router } from '@angular/router';
|
||||
|
||||
@@ -34,6 +34,7 @@ describe('AppAuthGuard', () => {
|
||||
let auth: AuthenticationService;
|
||||
let guard: AppAuthGuard;
|
||||
let router: Router;
|
||||
let config: AppConfigService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -44,10 +45,31 @@ describe('AppAuthGuard', () => {
|
||||
auth = TestBed.get(AuthenticationService);
|
||||
guard = TestBed.get(AppAuthGuard);
|
||||
router = TestBed.get(Router);
|
||||
config = TestBed.get(AppConfigService);
|
||||
|
||||
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', () => {
|
||||
spyOn(auth, 'isEcmLoggedIn').and.returnValue(true);
|
||||
|
||||
|
@@ -38,13 +38,18 @@ export class AppAuthGuard extends AuthGuardEcm {
|
||||
constructor(
|
||||
private _auth: AuthenticationService,
|
||||
private _router: Router,
|
||||
config: AppConfigService
|
||||
private _config: AppConfigService
|
||||
) {
|
||||
super(_auth, _router, config);
|
||||
super(_auth, _router, _config);
|
||||
}
|
||||
|
||||
checkLogin(redirectUrl: string): boolean {
|
||||
if (this._auth.isEcmLoggedIn()) {
|
||||
const withCredentials = this._config.get<boolean>(
|
||||
'auth.withCredentials',
|
||||
false
|
||||
);
|
||||
|
||||
if (withCredentials || this._auth.isEcmLoggedIn()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user