mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-29 18:13:55 -07:00
fix knownhosts issue
This commit is contained in:
parent
5f28d43dff
commit
e045f498a8
3 changed files with 42 additions and 4 deletions
|
|
@ -86,8 +86,6 @@ const KnownHosts = (props: any) => {
|
||||||
webClient.request.authentication.testConnection({ ...getHostPort(host) });
|
webClient.request.authentication.testConnection({ ...getHostPort(host) });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mirror the store's selectedHost into the form field. Also kick off a
|
|
||||||
// connection test so the user sees the green/red indicator on mount.
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedHost) {
|
if (!selectedHost) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { act, waitFor } from '@testing-library/react';
|
import { act, fireEvent, waitFor } from '@testing-library/react';
|
||||||
|
|
||||||
import { renderWithProviders, createMockWebClient, disconnectedState } from '../../__test-utils__';
|
import { renderWithProviders, createMockWebClient, disconnectedState } from '../../__test-utils__';
|
||||||
|
|
||||||
|
|
@ -166,6 +166,26 @@ describe('Login — logout cycle (same JS session)', () => {
|
||||||
await flushEffects();
|
await flushEffects();
|
||||||
expect(hoisted.mockWebClient.request.authentication.login).not.toHaveBeenCalled();
|
expect(hoisted.mockWebClient.request.authentication.login).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('submits with the restored host after a logout→remount without Required error', async () => {
|
||||||
|
const first = renderWithProviders(<Login />, { preloadedState: disconnectedState });
|
||||||
|
await flushEffects();
|
||||||
|
first.unmount();
|
||||||
|
|
||||||
|
const { getByRole, queryByText } = renderWithProviders(<Login />, {
|
||||||
|
preloadedState: disconnectedState,
|
||||||
|
});
|
||||||
|
await flushEffects();
|
||||||
|
|
||||||
|
fireEvent.click(getByRole('button', { name: /LoginForm\.label\.login/ }));
|
||||||
|
await flushEffects();
|
||||||
|
|
||||||
|
expect(queryByText(/required/i)).toBeNull();
|
||||||
|
expect(hoisted.mockWebClient.request.authentication.login).toHaveBeenCalledTimes(1);
|
||||||
|
expect(hoisted.mockWebClient.request.authentication.login.mock.calls[0][0]).toMatchObject({
|
||||||
|
userName: 'alice',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Login — refresh cycle', () => {
|
describe('Login — refresh cycle', () => {
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,8 @@ const LoginFormBody = ({
|
||||||
|
|
||||||
const LoginForm = (props: LoginFormProps) => {
|
const LoginForm = (props: LoginFormProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const knownHosts = useKnownHosts();
|
||||||
|
const settings = useSettings();
|
||||||
|
|
||||||
const validate = (values: any) => {
|
const validate = (values: any) => {
|
||||||
const errors: any = {};
|
const errors: any = {};
|
||||||
|
|
@ -193,8 +195,26 @@ const LoginForm = (props: LoginFormProps) => {
|
||||||
props.onSubmit({ userName, ...values });
|
props.onSubmit({ userName, ...values });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (knownHosts.status !== LoadingState.READY || settings.status !== LoadingState.READY) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedHost = knownHosts.value?.selectedHost;
|
||||||
|
const initialValues = {
|
||||||
|
selectedHost,
|
||||||
|
userName: selectedHost?.userName ?? '',
|
||||||
|
remember: Boolean(selectedHost?.remember),
|
||||||
|
autoConnect: Boolean(settings.value?.autoConnect),
|
||||||
|
password: '',
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleOnSubmit} validate={validate}>
|
<Form
|
||||||
|
onSubmit={handleOnSubmit}
|
||||||
|
validate={validate}
|
||||||
|
initialValues={initialValues}
|
||||||
|
keepDirtyOnReinitialize
|
||||||
|
>
|
||||||
{({ handleSubmit, form }) => (
|
{({ handleSubmit, form }) => (
|
||||||
<LoginFormBody {...props} form={form} handleSubmit={handleSubmit} />
|
<LoginFormBody {...props} form={form} handleSubmit={handleSubmit} />
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue