Skip to content

Commit

Permalink
[7.x] Improve login UI error message. (#75655)
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin authored Aug 21, 2020
1 parent 65293aa commit c581671
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,58 @@ describe('LoginForm', () => {
expect(window.location.href).toBe(currentURL);
expect(coreStartMock.notifications.toasts.addError).toHaveBeenCalledWith(failureReason, {
title: 'Could not perform login.',
toastMessage: 'Oh no!',
});
});

it('shows error with message in the `body`', async () => {
const currentURL = `https://some-host/login?next=${encodeURIComponent(
'/some-base-path/app/kibana#/home?_g=()'
)}`;

const coreStartMock = coreMock.createStart({ basePath: '/some-base-path' });
coreStartMock.http.post.mockRejectedValue({
body: { message: 'Oh no! But with much more details!' },
message: 'Oh no!',
});

window.location.href = currentURL;
const wrapper = mountWithIntl(
<LoginForm
http={coreStartMock.http}
notifications={coreStartMock.notifications}
loginAssistanceMessage=""
selector={{
enabled: true,
providers: [
{ type: 'basic', name: 'basic', usesLoginForm: true },
{ type: 'saml', name: 'saml1', usesLoginForm: false },
],
}}
/>
);

expectPageMode(wrapper, PageMode.Selector);

wrapper.findWhere((node) => node.key() === 'saml1').simulate('click');

await act(async () => {
await nextTick();
wrapper.update();
});

expect(coreStartMock.http.post).toHaveBeenCalledTimes(1);
expect(coreStartMock.http.post).toHaveBeenCalledWith('/internal/security/login', {
body: JSON.stringify({ providerType: 'saml', providerName: 'saml1', currentURL }),
});

expect(window.location.href).toBe(currentURL);
expect(coreStartMock.notifications.toasts.addError).toHaveBeenCalledWith(
new Error('Oh no! But with much more details!'),
{ title: 'Could not perform login.', toastMessage: 'Oh no!' }
);
});

it('properly switches to login form', async () => {
const currentURL = `https://some-host/login?next=${encodeURIComponent(
'/some-base-path/app/kibana#/home?_g=()'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,15 @@ export class LoginForm extends Component<Props, State> {

window.location.href = location;
} catch (err) {
this.props.notifications.toasts.addError(err, {
title: i18n.translate('xpack.security.loginPage.loginSelectorErrorMessage', {
defaultMessage: 'Could not perform login.',
}),
});
this.props.notifications.toasts.addError(
err?.body?.message ? new Error(err?.body?.message) : err,
{
title: i18n.translate('xpack.security.loginPage.loginSelectorErrorMessage', {
defaultMessage: 'Could not perform login.',
}),
toastMessage: err?.message,
}
);

this.setState({ loadingState: { type: LoadingStateType.None } });
}
Expand Down

0 comments on commit c581671

Please sign in to comment.