Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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