#1406 improve CSRF and CORS errors reporting (#1488)

This commit is contained in:
Mario Romano
2017-01-17 13:44:39 +00:00
committed by Vito
parent 10a76cc0f6
commit 14d399968c
7 changed files with 181 additions and 95 deletions

View File

@@ -264,6 +264,52 @@ describe('AlfrescoLogin', () => {
expect(element.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
});
it('should return CORS error when server CORS error occurs', () => {
component.providers = 'ECM';
expect(component.success).toBe(false);
expect(component.error).toBe(false);
usernameInput.value = 'fake-username-CORS-error';
passwordInput.value = 'fake-password';
usernameInput.dispatchEvent(new Event('input'));
passwordInput.dispatchEvent(new Event('input'));
fixture.detectChanges();
element.querySelector('button').click();
fixture.detectChanges();
expect(component.error).toBe(true);
expect(component.success).toBe(false);
expect(element.querySelector('#login-error')).toBeDefined();
expect(element.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CORS');
});
it('should return CSRF error when server CSRF error occurs', () => {
component.providers = 'ECM';
expect(component.success).toBe(false);
expect(component.error).toBe(false);
usernameInput.value = 'fake-username-CSRF-error';
passwordInput.value = 'fake-password';
usernameInput.dispatchEvent(new Event('input'));
passwordInput.dispatchEvent(new Event('input'));
fixture.detectChanges();
element.querySelector('button').click();
fixture.detectChanges();
expect(component.error).toBe(true);
expect(component.success).toBe(false);
expect(element.querySelector('#login-error')).toBeDefined();
expect(element.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CSRF');
});
it('should emit onSuccess event after the login has succeeded', () => {
spyOn(component.onSuccess, 'emit');
component.providers = 'ECM';