Files
3x-ui/frontend/src/test/tunnel-rewriteport.test.ts
T
Rouzbeh† c93beef267 fix(inbounds): accept null rewritePort in tunnel settings (#5516) (#5525)
Clearing the Rewrite port field makes AntD InputNumber write null into the
form store. The tunnel schema declared rewritePort as PortSchema.optional(),
which accepts undefined but not null, so saving (or the JSON tab reflecting
null) failed validation with "settings.rewritePort — Invalid input".

Accept null and collapse it to undefined so the field is simply omitted from
the serialized payload, matching the behavior of deleting the key by hand.
The trailing .optional() keeps the key optional in the inferred type.

Closes #5516
2026-06-24 12:54:05 +02:00

27 lines
1008 B
TypeScript

import { describe, expect, it } from 'vitest';
import { TunnelInboundSettingsSchema } from '@/schemas/protocols/inbound/tunnel';
// Regression for issue #5516: AntD InputNumber writes null when the Rewrite
// port field is cleared, which used to crash validation with "Invalid input".
describe('TunnelInboundSettingsSchema rewritePort', () => {
it('accepts null (cleared field) and omits the port', () => {
const parsed = TunnelInboundSettingsSchema.parse({ rewritePort: null });
expect(parsed.rewritePort).toBeUndefined();
});
it('accepts a missing field', () => {
const parsed = TunnelInboundSettingsSchema.parse({});
expect(parsed.rewritePort).toBeUndefined();
});
it('preserves a valid port', () => {
const parsed = TunnelInboundSettingsSchema.parse({ rewritePort: 8443 });
expect(parsed.rewritePort).toBe(8443);
});
it('still rejects out-of-range ports', () => {
expect(() => TunnelInboundSettingsSchema.parse({ rewritePort: 70000 })).toThrow();
});
});