Skip to content

Commit

Permalink
[ACA-2211] auth guard: add support for withCredentials (#942)
Browse files Browse the repository at this point in the history
* auth guard: add support for withCredentials

* formatting fixes

* remove fdescribe
  • Loading branch information
DenysVuika authored and pionnegru committed Feb 14, 2019
1 parent bb5ce29 commit e0e2a61
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
24 changes: 23 additions & 1 deletion src/app/guards/auth.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
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';

describe('AppAuthGuard', () => {
let auth: AuthenticationService;
let guard: AppAuthGuard;
let router: Router;
let config: AppConfigService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -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);

Expand Down
11 changes: 8 additions & 3 deletions src/app/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e0e2a61

Please sign in to comment.