refactoring-backend #3
@@ -210,9 +210,9 @@ function JailConfigDetail({
|
||||
|
||||
const autoSavePayload = useMemo<JailConfigUpdate>(
|
||||
() => ({
|
||||
ban_time: Number(banTime) || jail.ban_time,
|
||||
find_time: Number(findTime) || jail.find_time,
|
||||
max_retry: Number(maxRetry) || jail.max_retry,
|
||||
ban_time: banTime.trim() === "" || Number.isNaN(Number(banTime)) ? jail.ban_time : Number(banTime),
|
||||
find_time: findTime.trim() === "" || Number.isNaN(Number(findTime)) ? jail.find_time : Number(findTime),
|
||||
max_retry: maxRetry.trim() === "" || Number.isNaN(Number(maxRetry)) ? jail.max_retry : Number(maxRetry),
|
||||
fail_regex: failRegex,
|
||||
ignore_regex: ignoreRegex,
|
||||
date_pattern: datePattern !== "" ? datePattern : null,
|
||||
|
||||
@@ -81,4 +81,148 @@ describe("JailsTab", () => {
|
||||
|
||||
expect(lastPayload).not.toHaveProperty("backend");
|
||||
});
|
||||
|
||||
it("preserves zero values for ban_time, find_time, and max_retry", () => {
|
||||
const autoSavePayloads: Array<Record<string, unknown>> = [];
|
||||
mockUseAutoSave.mockImplementation((value) => {
|
||||
autoSavePayloads.push(value as Record<string, unknown>);
|
||||
return { status: "idle", errorText: null, retry: vi.fn() };
|
||||
});
|
||||
|
||||
const jailWithNonZeroDefaults: JailConfig = {
|
||||
...basicJail,
|
||||
ban_time: 600,
|
||||
find_time: 600,
|
||||
max_retry: 5,
|
||||
};
|
||||
|
||||
mockUseJailConfigs.mockReturnValue({
|
||||
jails: [jailWithNonZeroDefaults],
|
||||
total: 1,
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: vi.fn(),
|
||||
updateJail: vi.fn(),
|
||||
reloadAll: vi.fn(),
|
||||
});
|
||||
|
||||
mockUseConfigActiveStatus.mockReturnValue({
|
||||
activeJails: new Set<string>(),
|
||||
activeFilters: new Set<string>(),
|
||||
activeActions: new Set<string>(),
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: vi.fn(),
|
||||
});
|
||||
|
||||
render(
|
||||
<FluentProvider theme={webLightTheme}>
|
||||
<JailsTab initialJail="sshd" />
|
||||
</FluentProvider>,
|
||||
);
|
||||
|
||||
expect(autoSavePayloads.length).toBeGreaterThan(0);
|
||||
const lastPayload = autoSavePayloads[autoSavePayloads.length - 1];
|
||||
|
||||
expect(lastPayload).toBeDefined();
|
||||
expect(lastPayload!.ban_time).toBe(600);
|
||||
expect(lastPayload!.find_time).toBe(600);
|
||||
expect(lastPayload!.max_retry).toBe(5);
|
||||
});
|
||||
|
||||
it("falls back to jail defaults for empty string input", () => {
|
||||
const autoSavePayloads: Array<Record<string, unknown>> = [];
|
||||
mockUseAutoSave.mockImplementation((value) => {
|
||||
autoSavePayloads.push(value as Record<string, unknown>);
|
||||
return { status: "idle", errorText: null, retry: vi.fn() };
|
||||
});
|
||||
|
||||
const jailWithDefaults: JailConfig = {
|
||||
...basicJail,
|
||||
ban_time: 600,
|
||||
find_time: 600,
|
||||
max_retry: 5,
|
||||
};
|
||||
|
||||
mockUseJailConfigs.mockReturnValue({
|
||||
jails: [jailWithDefaults],
|
||||
total: 1,
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: vi.fn(),
|
||||
updateJail: vi.fn(),
|
||||
reloadAll: vi.fn(),
|
||||
});
|
||||
|
||||
mockUseConfigActiveStatus.mockReturnValue({
|
||||
activeJails: new Set<string>(),
|
||||
activeFilters: new Set<string>(),
|
||||
activeActions: new Set<string>(),
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: vi.fn(),
|
||||
});
|
||||
|
||||
render(
|
||||
<FluentProvider theme={webLightTheme}>
|
||||
<JailsTab initialJail="sshd" />
|
||||
</FluentProvider>,
|
||||
);
|
||||
|
||||
expect(autoSavePayloads.length).toBeGreaterThan(0);
|
||||
const lastPayload = autoSavePayloads[autoSavePayloads.length - 1];
|
||||
|
||||
expect(lastPayload).toBeDefined();
|
||||
expect(lastPayload!.ban_time).toBe(600);
|
||||
expect(lastPayload!.find_time).toBe(600);
|
||||
expect(lastPayload!.max_retry).toBe(5);
|
||||
});
|
||||
|
||||
it("falls back to jail defaults for non-numeric input", () => {
|
||||
const autoSavePayloads: Array<Record<string, unknown>> = [];
|
||||
mockUseAutoSave.mockImplementation((value) => {
|
||||
autoSavePayloads.push(value as Record<string, unknown>);
|
||||
return { status: "idle", errorText: null, retry: vi.fn() };
|
||||
});
|
||||
|
||||
const jailWithDefaults: JailConfig = {
|
||||
...basicJail,
|
||||
ban_time: 600,
|
||||
find_time: 600,
|
||||
max_retry: 5,
|
||||
};
|
||||
|
||||
mockUseJailConfigs.mockReturnValue({
|
||||
jails: [jailWithDefaults],
|
||||
total: 1,
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: vi.fn(),
|
||||
updateJail: vi.fn(),
|
||||
reloadAll: vi.fn(),
|
||||
});
|
||||
|
||||
mockUseConfigActiveStatus.mockReturnValue({
|
||||
activeJails: new Set<string>(),
|
||||
activeFilters: new Set<string>(),
|
||||
activeActions: new Set<string>(),
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: vi.fn(),
|
||||
});
|
||||
|
||||
render(
|
||||
<FluentProvider theme={webLightTheme}>
|
||||
<JailsTab initialJail="sshd" />
|
||||
</FluentProvider>,
|
||||
);
|
||||
|
||||
expect(autoSavePayloads.length).toBeGreaterThan(0);
|
||||
const lastPayload = autoSavePayloads[autoSavePayloads.length - 1];
|
||||
|
||||
expect(lastPayload).toBeDefined();
|
||||
expect(lastPayload!.ban_time).toBe(600);
|
||||
expect(lastPayload!.find_time).toBe(600);
|
||||
expect(lastPayload!.max_retry).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user