mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Protect against uncheck race condition
This commit is contained in:
@@ -55,6 +55,12 @@ export function SecurityWarningModal({ health }: SecurityWarningModalProps) {
|
||||
}
|
||||
}, [shouldWarn]);
|
||||
|
||||
useEffect(() => {
|
||||
if (health?.bots_disabled !== true) {
|
||||
setBotsDisabledLocally(false);
|
||||
}
|
||||
}, [health?.bots_disabled, health?.bots_disabled_source]);
|
||||
|
||||
if (!shouldWarn) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
@@ -95,4 +95,25 @@ describe('SecurityWarningModal', () => {
|
||||
expect(mocks.toast.success).toHaveBeenCalledWith('Bots disabled until restart');
|
||||
expect(screen.queryByText('Unprotected bot execution is enabled')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the warning again after temporary bot disable disappears on a later health update', async () => {
|
||||
const user = userEvent.setup();
|
||||
const { rerender } = render(<SecurityWarningModal health={baseHealth} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Disable Bots Until Server Restart' }));
|
||||
expect(screen.queryByText('Unprotected bot execution is enabled')).not.toBeInTheDocument();
|
||||
|
||||
rerender(
|
||||
<SecurityWarningModal
|
||||
health={{ ...baseHealth, bots_disabled: true, bots_disabled_source: 'until_restart' }}
|
||||
/>
|
||||
);
|
||||
expect(screen.queryByText('Unprotected bot execution is enabled')).not.toBeInTheDocument();
|
||||
|
||||
rerender(<SecurityWarningModal health={baseHealth} />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Unprotected bot execution is enabled')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user