mirror of
https://github.com/grafana/grafana.git
synced 2025-02-09 23:16:16 -06:00
Login: Adjust error message when user exceed login attempts (#70736)
* Adjust error message when user exceed login attempts * empty commit to add coauthors Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: L-M-K-B <48948963+L-M-K-B@users.noreply.github.com> Co-authored-by: tskarhed <1438972+tskarhed@users.noreply.github.com> --------- Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: L-M-K-B <48948963+L-M-K-B@users.noreply.github.com> Co-authored-by: tskarhed <1438972+tskarhed@users.noreply.github.com>
This commit is contained in:
parent
13dd821961
commit
ea361f5db4
@ -169,8 +169,12 @@ function getErrorMessage(err: FetchError<undefined | { messageId?: string; messa
|
||||
case 'password-auth.empty':
|
||||
case 'password-auth.failed':
|
||||
case 'password-auth.invalid':
|
||||
case 'login-attempt.blocked':
|
||||
return t('login.error.invalid-user-or-password', 'Invalid username or password');
|
||||
case 'login-attempt.blocked':
|
||||
return t(
|
||||
'login.error.blocked',
|
||||
'You have exceeded the number of login attempts for this user. Please try again later.'
|
||||
);
|
||||
default:
|
||||
return err.data?.message;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import { LoginPage } from './LoginPage';
|
||||
|
||||
const postMock = jest.fn();
|
||||
jest.mock('@grafana/runtime', () => ({
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
__esModule: true,
|
||||
getBackendSrv: () => ({
|
||||
post: postMock,
|
||||
@ -103,4 +104,48 @@ describe('Login Page', () => {
|
||||
|
||||
expect(screen.getByRole('link', { name: 'Sign in with Okta Test' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an error with incorrect password', async () => {
|
||||
postMock.mockRejectedValueOnce({
|
||||
data: {
|
||||
message: 'Invalid username or password',
|
||||
messageId: 'password-auth.failed',
|
||||
statusCode: 400,
|
||||
},
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
});
|
||||
|
||||
render(<LoginPage />);
|
||||
|
||||
await userEvent.type(screen.getByLabelText('Username input field'), 'admin');
|
||||
await userEvent.type(screen.getByLabelText('Password input field'), 'test');
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Login button' }));
|
||||
|
||||
expect(await screen.findByRole('alert', { name: 'Invalid username or password' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows a different error with failed login attempts', async () => {
|
||||
postMock.mockRejectedValueOnce({
|
||||
data: {
|
||||
message: 'Invalid username or password',
|
||||
messageId: 'login-attempt.blocked',
|
||||
statusCode: 401,
|
||||
},
|
||||
status: 401,
|
||||
statusText: 'Unauthorized',
|
||||
});
|
||||
|
||||
render(<LoginPage />);
|
||||
|
||||
await userEvent.type(screen.getByLabelText('Username input field'), 'admin');
|
||||
await userEvent.type(screen.getByLabelText('Password input field'), 'test');
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Login button' }));
|
||||
|
||||
expect(
|
||||
await screen.findByRole('alert', {
|
||||
name: 'You have exceeded the number of login attempts for this user. Please try again later.',
|
||||
})
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
@ -192,6 +192,7 @@
|
||||
},
|
||||
"login": {
|
||||
"error": {
|
||||
"blocked": "",
|
||||
"invalid-user-or-password": "",
|
||||
"unknown": ""
|
||||
}
|
||||
|
@ -192,6 +192,7 @@
|
||||
},
|
||||
"login": {
|
||||
"error": {
|
||||
"blocked": "You have exceeded the number of login attempts for this user. Please try again later.",
|
||||
"invalid-user-or-password": "Invalid username or password",
|
||||
"unknown": "Unknown error occurred"
|
||||
}
|
||||
|
@ -192,6 +192,7 @@
|
||||
},
|
||||
"login": {
|
||||
"error": {
|
||||
"blocked": "",
|
||||
"invalid-user-or-password": "",
|
||||
"unknown": ""
|
||||
}
|
||||
|
@ -192,6 +192,7 @@
|
||||
},
|
||||
"login": {
|
||||
"error": {
|
||||
"blocked": "",
|
||||
"invalid-user-or-password": "",
|
||||
"unknown": ""
|
||||
}
|
||||
|
@ -192,6 +192,7 @@
|
||||
},
|
||||
"login": {
|
||||
"error": {
|
||||
"blocked": "Ÿőū ĥävę ęχčęęđęđ ŧĥę ʼnūmþęř őƒ ľőģįʼn äŧŧęmpŧş ƒőř ŧĥįş ūşęř. Pľęäşę ŧřy äģäįʼn ľäŧęř.",
|
||||
"invalid-user-or-password": "Ĩʼnväľįđ ūşęřʼnämę őř päşşŵőřđ",
|
||||
"unknown": "Ůʼnĸʼnőŵʼn ęřřőř őččūřřęđ"
|
||||
}
|
||||
|
@ -192,6 +192,7 @@
|
||||
},
|
||||
"login": {
|
||||
"error": {
|
||||
"blocked": "",
|
||||
"invalid-user-or-password": "",
|
||||
"unknown": ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user