mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2139] extra cookie availability check (#2865)
* extra cookie availability check * code style and test fixes * unit tests
This commit is contained in:
committed by
Eugenio Romano
parent
900fd70d63
commit
49456b3fcd
@@ -15,7 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export class CookieServiceMock {
|
import { CookieService } from '../services/cookie.service';
|
||||||
|
|
||||||
|
export class CookieServiceMock extends CookieService {
|
||||||
|
|
||||||
getItem(key: string): string | null {
|
getItem(key: string): string | null {
|
||||||
return this[key] && this[key].data || null;
|
return this[key] && this[key].data || null;
|
||||||
|
@@ -75,7 +75,7 @@ describe('AuthenticationService', () => {
|
|||||||
jasmine.Ajax.uninstall();
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('remembe me', () => {
|
describe('remember me', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
preferences.authType = 'ECM';
|
preferences.authType = 'ECM';
|
||||||
@@ -139,6 +139,24 @@ describe('AuthenticationService', () => {
|
|||||||
preferences.authType = 'ECM';
|
preferences.authType = 'ECM';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should require remember me set for ECM check', () => {
|
||||||
|
spyOn(cookie, 'isEnabled').and.returnValue(true);
|
||||||
|
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
|
||||||
|
spyOn(apiService, 'getInstance').and.callThrough();
|
||||||
|
|
||||||
|
expect(authService.isEcmLoggedIn()).toBeFalsy();
|
||||||
|
expect(apiService.getInstance).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not require cookie service enabled for ECM check', () => {
|
||||||
|
spyOn(cookie, 'isEnabled').and.returnValue(false);
|
||||||
|
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
|
||||||
|
spyOn(apiService, 'getInstance').and.callThrough();
|
||||||
|
|
||||||
|
expect(authService.isEcmLoggedIn()).toBeFalsy();
|
||||||
|
expect(apiService.getInstance).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('[ECM] should return an ECM ticket after the login done', (done) => {
|
it('[ECM] should return an ECM ticket after the login done', (done) => {
|
||||||
authService.login('fake-username', 'fake-password').subscribe(() => {
|
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||||
expect(authService.isLoggedIn()).toBe(true);
|
expect(authService.isLoggedIn()).toBe(true);
|
||||||
@@ -284,6 +302,24 @@ describe('AuthenticationService', () => {
|
|||||||
preferences.authType = 'BPM';
|
preferences.authType = 'BPM';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should require remember me set for BPM check', () => {
|
||||||
|
spyOn(cookie, 'isEnabled').and.returnValue(true);
|
||||||
|
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
|
||||||
|
spyOn(apiService, 'getInstance').and.callThrough();
|
||||||
|
|
||||||
|
expect(authService.isBpmLoggedIn()).toBeFalsy();
|
||||||
|
expect(apiService.getInstance).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not require cookie service enabled for BPM check', () => {
|
||||||
|
spyOn(cookie, 'isEnabled').and.returnValue(false);
|
||||||
|
spyOn(authService, 'isRememberMeSet').and.returnValue(false);
|
||||||
|
spyOn(apiService, 'getInstance').and.callThrough();
|
||||||
|
|
||||||
|
expect(authService.isBpmLoggedIn()).toBeFalsy();
|
||||||
|
expect(apiService.getInstance).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('[BPM] should return an BPM ticket after the login done', (done) => {
|
it('[BPM] should return an BPM ticket after the login done', (done) => {
|
||||||
authService.login('fake-username', 'fake-password').subscribe(() => {
|
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||||
expect(authService.isLoggedIn()).toBe(true);
|
expect(authService.isLoggedIn()).toBe(true);
|
||||||
|
@@ -96,7 +96,7 @@ export class AuthenticationService {
|
|||||||
*
|
*
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
private isRememberMeSet(): boolean {
|
isRememberMeSet(): boolean {
|
||||||
return (this.cookie.getItem(REMEMBER_ME_COOKIE_KEY) === null) ? false : true;
|
return (this.cookie.getItem(REMEMBER_ME_COOKIE_KEY) === null) ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +200,10 @@ export class AuthenticationService {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isEcmLoggedIn(): boolean {
|
isEcmLoggedIn(): boolean {
|
||||||
return this.isRememberMeSet() && this.alfrescoApi.getInstance().ecmAuth && !!this.alfrescoApi.getInstance().ecmAuth.isLoggedIn();
|
if (this.cookie.isEnabled() && !this.isRememberMeSet()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.alfrescoApi.getInstance().ecmAuth && !!this.alfrescoApi.getInstance().ecmAuth.isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,7 +212,10 @@ export class AuthenticationService {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isBpmLoggedIn(): boolean {
|
isBpmLoggedIn(): boolean {
|
||||||
return this.isRememberMeSet() && this.alfrescoApi.getInstance().bpmAuth && !!this.alfrescoApi.getInstance().bpmAuth.isLoggedIn();
|
if (this.cookie.isEnabled() && !this.isRememberMeSet()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.alfrescoApi.getInstance().bpmAuth && !!this.alfrescoApi.getInstance().bpmAuth.isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -20,6 +20,16 @@ import { Injectable } from '@angular/core';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class CookieService {
|
export class CookieService {
|
||||||
|
|
||||||
|
isEnabled(): boolean {
|
||||||
|
// for certain scenarios Chrome may say 'true' but have cookies still disabled
|
||||||
|
if (navigator.cookieEnabled === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.cookie = 'test-cookie';
|
||||||
|
return document.cookie.indexOf('test-cookie') > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve cookie by key.
|
* Retrieve cookie by key.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user