forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[User] Prevent disabled input change by password manager (elastic#204269
) Prevents username input from being edited by password manager extensions when `disabled` (cherry picked from commit d96168c)
- Loading branch information
1 parent
0f34a64
commit fd650f7
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
x-pack/platform/plugins/shared/security/public/management/users/edit_user/user_form.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import React from 'react'; | ||
|
||
import { coreMock } from '@kbn/core/public/mocks'; | ||
|
||
import type { UserFormProps, UserFormValues } from './user_form'; | ||
import { UserForm } from './user_form'; | ||
import { securityMock } from '../../../mocks'; | ||
import { Providers } from '../users_management_app'; | ||
|
||
const userMock: UserFormValues = { | ||
username: 'jdoe', | ||
full_name: '', | ||
email: '', | ||
roles: ['superuser'], | ||
}; | ||
|
||
describe('UserForm', () => { | ||
const coreStart = coreMock.createStart(); | ||
const authc = securityMock.createSetup().authc; | ||
const history = createMemoryHistory({ initialEntries: ['/edit/jdoe'] }); | ||
|
||
const onCancelMock = jest.fn(); | ||
const onSuccessMock = jest.fn(); | ||
|
||
let defaultProps: UserFormProps; | ||
|
||
beforeEach(() => { | ||
defaultProps = { | ||
isNewUser: true, | ||
isReservedUser: false, | ||
isCurrentUser: false, | ||
defaultValues: userMock, | ||
onCancel: onCancelMock, | ||
onSuccess: onSuccessMock, | ||
disabled: false, | ||
}; | ||
}); | ||
|
||
const renderUserForm = (props: Partial<UserFormProps> = {}) => { | ||
return render( | ||
<Providers services={coreStart} authc={authc} history={history}> | ||
<UserForm {...defaultProps} {...props} /> | ||
</Providers> | ||
); | ||
}; | ||
|
||
it('prevents editing username when disabled', async () => { | ||
// See https://github.com/elastic/kibana/issues/204268 | ||
|
||
renderUserForm({ disabled: true }); | ||
const usernameInput = screen.getByTestId<HTMLInputElement>('userFormUserNameInput'); | ||
fireEvent.change(usernameInput, { target: { value: 'foo' } }); | ||
expect(usernameInput.value).toBe('jdoe'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters