From b738596edf53fd3918127d0f56eb0f421f3e13ec Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Tue, 27 Sep 2016 12:35:56 +0100 Subject: [PATCH 1/2] Fix isLoggedIn problem #818 --- .../AlfrescoAuthentication.service.spec.ts | 32 ++++++++++++++++++- .../AlfrescoAuthentication.service.ts | 4 +-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts index 73791070b5..4507d9542b 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts @@ -54,7 +54,7 @@ describe('AlfrescoAuthentication', () => { }); spyOn(localStorage, 'key').and.callFake(function (i) { let keys = Object.keys(store); - return keys[i] || null; + return keys[i]; }); jasmine.Ajax.install(); @@ -84,6 +84,21 @@ describe('AlfrescoAuthentication', () => { }); }); + it('should save only ECM ticket on localStorage', (done) => { + authService.login('fake-username', 'fake-password').subscribe(() => { + expect(authService.isLoggedIn()).toBe(true); + expect(authService.getTicketBpm()).toBeNull(); + expect(authService.getAlfrescoApi().bpmAuth.isLoggedIn()).toBeFalsy(); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 201, + contentType: 'application/json', + responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}}) + }); + }); + it('should return ticket undefined when the credentials are wrong', (done) => { authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( (res) => { @@ -164,6 +179,21 @@ describe('AlfrescoAuthentication', () => { }); }); + it('should save only BPM ticket on localStorage', (done) => { + authService.login('fake-username', 'fake-password').subscribe(() => { + expect(authService.isLoggedIn()).toBe(true); + expect(authService.getTicketEcm()).toBeNull(); + expect(authService.getAlfrescoApi().ecmAuth.isLoggedIn()).toBeFalsy(); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 201, + contentType: 'application/json', + responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}}) + }); + }); + it('should return ticket undefined when the credentials are wrong', (done) => { authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( (res) => { diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index 50313d5c89..fed60c3356 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -177,7 +177,7 @@ export class AlfrescoAuthenticationService { * The method save the ECM ticket in the localStorage */ public saveTicketEcm(): void { - if (this.alfrescoApi) { + if (this.alfrescoApi && this.alfrescoApi.getTicketEcm()) { localStorage.setItem('ticket-ECM', this.alfrescoApi.getTicketEcm()); } } @@ -186,7 +186,7 @@ export class AlfrescoAuthenticationService { * The method save the BPM ticket in the localStorage */ public saveTicketBpm(): void { - if (this.alfrescoApi) { + if (this.alfrescoApi && this.alfrescoApi.getTicketBpm()) { localStorage.setItem('ticket-BPM', this.alfrescoApi.getTicketBpm()); } } From 990257d57d278d6ba256a3e99985b9ed5f28816d Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Tue, 27 Sep 2016 12:41:14 +0100 Subject: [PATCH 2/2] Wrongly removed item --- .../src/services/AlfrescoAuthentication.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts index 4507d9542b..c43a10b753 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts @@ -54,7 +54,7 @@ describe('AlfrescoAuthentication', () => { }); spyOn(localStorage, 'key').and.callFake(function (i) { let keys = Object.keys(store); - return keys[i]; + return keys[i] || null; }); jasmine.Ajax.install();