#1281 Cannot login after logging out

This commit is contained in:
Eugenio Romano 2016-12-15 15:55:00 +00:00
parent 48fa09c56e
commit 03f805a804
2 changed files with 51 additions and 1 deletions

View File

@ -144,6 +144,32 @@ describe('AlfrescoAuthentication', () => {
});
});
it('ticket should be deleted only after logout request is accepted', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let logoutPromise = authService.logout();
expect(authService.getTicketEcm()).toBe('fake-post-ticket');
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 204
});
logoutPromise.subscribe(() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.isEcmLoggedIn()).toBe(false);
done();
});
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
});
});
it('should return false if the user is not logged in', () => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.isEcmLoggedIn()).toBe(false);
@ -200,6 +226,30 @@ describe('AlfrescoAuthentication', () => {
});
});
it('ticket should be deleted only after logout request is accepted', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let logoutPromise = authService.logout();
expect(authService.getTicketBpm()).toBe('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk');
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200
});
logoutPromise.subscribe(() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.isBpmLoggedIn()).toBe(false);
done();
});
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200
});
});
it('should return a ticket undefined after logout', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
authService.logout().subscribe(() => {

View File

@ -114,10 +114,10 @@ export class AlfrescoAuthenticationService {
* @returns {Observable<R>|Observable<T>}
*/
public logout() {
this.removeTicket();
return Observable.fromPromise(this.callApiLogout())
.map(res => <any> res)
.do(response => {
this.removeTicket();
this.logoutSubject.next(response);
return response;
})