mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-12-03 16:01:19 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c93e2eb99 |
No files matched your search
@@ -1149,6 +1149,7 @@ export const enVaultMessages: Messages = {
|
||||
'hostDetails.rdp.resolutionMode.fixed': 'Fixed Size',
|
||||
'hostDetails.rdp.width': 'Width',
|
||||
'hostDetails.rdp.height': 'Height',
|
||||
'hostDetails.rdp.dimensionHint': 'Enter a whole number from 200 to 8192.',
|
||||
'hostDetails.rdp.colorDepth': 'Color Depth',
|
||||
'hostDetails.rdp.audio': 'Audio Output',
|
||||
'hostDetails.rdp.audioDesc': 'Play remote desktop sound locally',
|
||||
|
||||
@@ -1151,6 +1151,7 @@ export const esVaultMessages: Messages = {
|
||||
'hostDetails.rdp.resolutionMode.fixed': 'Tamaño fijo',
|
||||
'hostDetails.rdp.width': 'Ancho',
|
||||
'hostDetails.rdp.height': 'Alto',
|
||||
'hostDetails.rdp.dimensionHint': 'Introduce un número entero entre 200 y 8192.',
|
||||
'hostDetails.rdp.colorDepth': 'Profundidad de color',
|
||||
'hostDetails.rdp.audio': 'Salida de audio',
|
||||
'hostDetails.rdp.audioDesc': 'Reproducir el audio del escritorio remoto localmente',
|
||||
|
||||
@@ -134,3 +134,9 @@ test("every locale outside the pending list is at full parity with en", () => {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("every locale explains the fixed RDP dimension limits", () => {
|
||||
for (const messages of [en, es, ru, zhCN, zhTW]) {
|
||||
assert.match(messages["hostDetails.rdp.dimensionHint"] ?? "", /200.*8192/);
|
||||
}
|
||||
});
|
||||
@@ -1167,6 +1167,7 @@ export const ruVaultMessages: Messages = {
|
||||
'hostDetails.rdp.resolutionMode.fixed': 'Фиксированный размер',
|
||||
'hostDetails.rdp.width': 'Ширина',
|
||||
'hostDetails.rdp.height': 'Высота',
|
||||
'hostDetails.rdp.dimensionHint': 'Введите целое число от 200 до 8192.',
|
||||
'hostDetails.rdp.colorDepth': 'Глубина цвета',
|
||||
'hostDetails.rdp.audio': 'Вывод звука',
|
||||
'hostDetails.rdp.audioDesc': 'Воспроизводить звук удалённого рабочего стола локально',
|
||||
|
||||
@@ -1113,6 +1113,7 @@ export const zhCNVaultMessages: Messages = {
|
||||
'hostDetails.rdp.resolutionMode.fixed': '固定尺寸',
|
||||
'hostDetails.rdp.width': '宽度',
|
||||
'hostDetails.rdp.height': '高度',
|
||||
'hostDetails.rdp.dimensionHint': '请输入 200 到 8192 之间的整数。',
|
||||
'hostDetails.rdp.colorDepth': '色深',
|
||||
'hostDetails.rdp.audio': '音频输出',
|
||||
'hostDetails.rdp.audioDesc': '在本地播放远程桌面声音',
|
||||
|
||||
@@ -1113,6 +1113,7 @@ export const zhTWVaultMessages: Messages = {
|
||||
'hostDetails.rdp.resolutionMode.fixed': '固定尺寸',
|
||||
'hostDetails.rdp.width': '寬度',
|
||||
'hostDetails.rdp.height': '高度',
|
||||
'hostDetails.rdp.dimensionHint': '請輸入 200 到 8192 之間的整數。',
|
||||
'hostDetails.rdp.colorDepth': '色彩深度',
|
||||
'hostDetails.rdp.audio': '音訊輸出',
|
||||
'hostDetails.rdp.audioDesc': '在本機播放遠端桌面音效',
|
||||
|
||||
@@ -132,6 +132,8 @@ export const HostDetailsConnectionSections: React.FC<HostDetailsConnectionSectio
|
||||
onCreateIdentity,
|
||||
companionCredentialDrafts,
|
||||
onCompanionCredentialDraftChange,
|
||||
resolutionDraft,
|
||||
onResolutionDraftChange,
|
||||
effectiveTelnetPort,
|
||||
effectiveTelnetUsername,
|
||||
effectiveTelnetPassword,
|
||||
@@ -395,6 +397,8 @@ export const HostDetailsConnectionSections: React.FC<HostDetailsConnectionSectio
|
||||
identities={identities}
|
||||
availableKeys={availableKeys}
|
||||
onCreateIdentity={onCreateIdentity}
|
||||
resolutionDraft={resolutionDraft}
|
||||
onResolutionDraftChange={onResolutionDraftChange}
|
||||
credentialDraft={companionCredentialDrafts?.rdp}
|
||||
onCredentialDraftChange={(draft) => onCompanionCredentialDraftChange?.("rdp", draft)}
|
||||
t={t}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import React from "react";
|
||||
import { act, create, type ReactTestRenderer } from "react-test-renderer";
|
||||
import { I18nProvider } from "../application/i18n/I18nProvider";
|
||||
import type { Host } from "../types";
|
||||
import HostDetailsPanel from "./HostDetailsPanel";
|
||||
import { installDomEnvironment } from "./test-support/renderReactDom";
|
||||
import { Button } from "./ui/button";
|
||||
import { Input } from "./ui/input";
|
||||
import { Select } from "./ui/select";
|
||||
import { TooltipProvider } from "./ui/tooltip";
|
||||
|
||||
for (const kind of ["standalone", "companion", "new"] as const) {
|
||||
test(`${kind} RDP keeps invalid resolution drafts visible and blocks saving`, async () => {
|
||||
const dom = installDomEnvironment();
|
||||
const previousRaf = globalThis.requestAnimationFrame;
|
||||
const previousCancelRaf = globalThis.cancelAnimationFrame;
|
||||
globalThis.requestAnimationFrame = (callback) => setTimeout(() => callback(0), 0) as unknown as number;
|
||||
globalThis.cancelAnimationFrame = (id) => clearTimeout(id);
|
||||
let renderer: ReactTestRenderer | undefined;
|
||||
const saved: Host[] = [];
|
||||
const host: Host = {
|
||||
id: "rdp-host", label: "Desktop", hostname: "desktop.example.com",
|
||||
username: "root", password: "password", authMethod: "password",
|
||||
protocol: kind === "companion" ? "ssh" : "rdp", tags: [], os: "windows",
|
||||
rdpConfig: {
|
||||
enabled: true, defaultConnect: true, resolutionMode: "fixed", width: 1920, height: 1080,
|
||||
},
|
||||
};
|
||||
try {
|
||||
await act(async () => {
|
||||
renderer = create(
|
||||
<I18nProvider locale="en"><TooltipProvider>
|
||||
<HostDetailsPanel
|
||||
initialData={kind === "new" ? undefined : host}
|
||||
initialProtocol="rdp"
|
||||
availableKeys={[]} identities={[]} groups={[]}
|
||||
terminalThemeId="default" terminalFontSize={14} layout="inline"
|
||||
onSave={(value) => saved.push(value)} onCancel={() => {}}
|
||||
/>
|
||||
</TooltipProvider></I18nProvider>,
|
||||
);
|
||||
});
|
||||
if (kind === "new") {
|
||||
await act(async () => {
|
||||
const hostname = renderer!.root.findAllByType(Input).find((input) =>
|
||||
input.props.placeholder === "IP or Hostname");
|
||||
assert.ok(hostname);
|
||||
hostname.props.onChange({ target: { value: host.hostname } });
|
||||
const mode = renderer!.root.findAllByType(Select).find((select) => select.props.value === "dynamic");
|
||||
assert.ok(mode);
|
||||
mode.props.onValueChange("fixed");
|
||||
});
|
||||
}
|
||||
const input = (dimension: string) => renderer!.root.findAllByType(Input).find((field) =>
|
||||
field.props.id?.endsWith(`-${dimension}`))!;
|
||||
const change = async (dimension: string, value: string) => {
|
||||
await act(async () => { input(dimension).props.onChange({ target: { value } }); });
|
||||
};
|
||||
const save = async () => {
|
||||
await act(async () => {
|
||||
const button = renderer!.root.findAllByType(Button).find((item) => item.props["aria-label"] === "Save");
|
||||
assert.ok(button);
|
||||
await button.props.onClick();
|
||||
});
|
||||
};
|
||||
assert.equal(input("width").props.value, "1920");
|
||||
for (const value of ["192", "19", "", "199", "8193", "3840.5", "abc"]) {
|
||||
await change("width", value);
|
||||
assert.equal(input("width").props.value, value);
|
||||
assert.equal(input("width").props["aria-invalid"], true);
|
||||
assert.match(JSON.stringify(renderer!.toJSON()), /Enter a whole number from 200 to 8192/);
|
||||
await save();
|
||||
assert.equal(saved.length, 0);
|
||||
assert.equal(input("width").props.value, value, "save must preserve the invalid draft");
|
||||
}
|
||||
await change("width", "3840");
|
||||
assert.equal(input("width").props.value, "3840");
|
||||
assert.equal(input("width").props["aria-invalid"], false);
|
||||
await change("height", "192");
|
||||
await save();
|
||||
assert.equal(saved.length, 0);
|
||||
assert.equal(input("height").props.value, "192");
|
||||
await change("height", "2160");
|
||||
await save();
|
||||
assert.equal(saved.length, 1);
|
||||
assert.equal(saved[0].rdpConfig?.width, 3840);
|
||||
assert.equal(saved[0].rdpConfig?.height, 2160);
|
||||
} finally {
|
||||
if (renderer) await act(async () => { renderer!.unmount(); });
|
||||
globalThis.requestAnimationFrame = previousRaf;
|
||||
globalThis.cancelAnimationFrame = previousCancelRaf;
|
||||
dom.cleanup();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -87,11 +87,13 @@ import {
|
||||
DEFAULT_VNC_CONFIG,
|
||||
DEFAULT_VNC_PORT,
|
||||
getHostEnabledProtocols,
|
||||
hasValidRdpFixedResolution,
|
||||
isRemoteDesktopProtocol,
|
||||
resolveHostDefaultConnectProtocol,
|
||||
sanitizeRdpConfig,
|
||||
sanitizeVncConfig,
|
||||
shouldPromptHostProtocolOnConnect,
|
||||
type RdpResolutionDraft,
|
||||
} from "../domain/remoteDesktop";
|
||||
import { PluginConnectionSection } from "./PluginConnectionSection";
|
||||
import { useHostConnectionTest } from "../application/state/useHostConnectionTest";
|
||||
@@ -248,6 +250,15 @@ const HostDetailsPanel: React.FC<HostDetailsPanelPropsWithResize> = ({
|
||||
},
|
||||
);
|
||||
|
||||
const hasRdpConfig = Boolean(form.rdpConfig);
|
||||
const [resolutionDraft, setResolutionDraft] = useState<RdpResolutionDraft>({});
|
||||
useEffect(() => {
|
||||
setResolutionDraft({});
|
||||
}, [form.id, hasRdpConfig]);
|
||||
const onResolutionDraftChange = (dimension: "width" | "height", value: string) => {
|
||||
setResolutionDraft((prev) => ({ ...prev, [dimension]: value }));
|
||||
};
|
||||
|
||||
const [activeSubPanel, setActiveSubPanel] = useState<SubPanel>("none");
|
||||
|
||||
const [credentialPopoverOpen, setCredentialPopoverOpen] = useState(false);
|
||||
@@ -909,6 +920,12 @@ const HostDetailsPanel: React.FC<HostDetailsPanelPropsWithResize> = ({
|
||||
if (savingHostRef.current) return;
|
||||
savingHostRef.current = true;
|
||||
try {
|
||||
if (!pluginProtocolActive && (form.protocol === "rdp" || form.rdpConfig?.enabled)
|
||||
&& !hasValidRdpFixedResolution(form.rdpConfig, resolutionDraft)) {
|
||||
setActiveProtocolTab("rdp");
|
||||
toast.error(t("hostDetails.rdp.dimensionHint"));
|
||||
return;
|
||||
}
|
||||
const flushed = isRemoteDesktopPrimary ? undefined : await totpFlushRef.current?.();
|
||||
if (flushed && !flushed.ok) return;
|
||||
const hostname = form.hostname.trim()
|
||||
@@ -1626,6 +1643,8 @@ const HostDetailsPanel: React.FC<HostDetailsPanelPropsWithResize> = ({
|
||||
t={t}
|
||||
form={form}
|
||||
setForm={setForm}
|
||||
resolutionDraft={resolutionDraft}
|
||||
onResolutionDraftChange={onResolutionDraftChange}
|
||||
totpFlushRef={totpFlushRef}
|
||||
update={update}
|
||||
groupDefaults={effectiveGroupDefaults}
|
||||
@@ -1689,6 +1708,8 @@ const HostDetailsPanel: React.FC<HostDetailsPanelPropsWithResize> = ({
|
||||
|
||||
{isRemoteDesktopPrimary && isCurrentTabEnabled && (activeProtocolTab === "rdp" || activeProtocolTab === "vnc") ? (
|
||||
<RemoteDesktopOptionsSection
|
||||
resolutionDraft={resolutionDraft}
|
||||
onResolutionDraftChange={onResolutionDraftChange}
|
||||
form={form}
|
||||
setForm={setForm}
|
||||
t={t}
|
||||
|
||||
@@ -48,6 +48,7 @@ import { Switch } from "../ui/switch";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
|
||||
import { HostDetailsSettingRow } from "./HostDetailsSection";
|
||||
import { IdentitySuggestInput } from "./IdentitySuggestInput";
|
||||
import { RdpResolutionFields, type RdpResolutionDraftProps } from "./RdpResolutionFields";
|
||||
|
||||
type Translate = (key: string, params?: Record<string, unknown>) => string;
|
||||
|
||||
@@ -65,7 +66,7 @@ interface CompanionRemoteDesktopSectionsProps {
|
||||
t: Translate;
|
||||
}
|
||||
|
||||
interface CompanionRemoteDesktopInlineFieldsProps extends CompanionRemoteDesktopSectionsProps {
|
||||
interface CompanionRemoteDesktopInlineFieldsProps extends CompanionRemoteDesktopSectionsProps, RdpResolutionDraftProps {
|
||||
protocol: "vnc" | "rdp";
|
||||
credentialDraft?: CompanionCredentialDraft;
|
||||
onCredentialDraftChange?: (draft: CompanionCredentialDraft | undefined) => void;
|
||||
@@ -83,6 +84,8 @@ export const CompanionRemoteDesktopInlineFields: React.FC<CompanionRemoteDesktop
|
||||
availableKeys = [],
|
||||
credentialDraft,
|
||||
onCredentialDraftChange,
|
||||
resolutionDraft,
|
||||
onResolutionDraftChange,
|
||||
t,
|
||||
}) => {
|
||||
const [vncPortInput, setVncPortInput] = useState<string>(() =>
|
||||
@@ -543,6 +546,16 @@ export const CompanionRemoteDesktopInlineFields: React.FC<CompanionRemoteDesktop
|
||||
</Select>
|
||||
</HostDetailsSettingRow>
|
||||
|
||||
{rdpNormalized.resolutionMode === "fixed" && (
|
||||
<RdpResolutionFields
|
||||
form={form}
|
||||
setForm={setForm}
|
||||
t={t}
|
||||
resolutionDraft={resolutionDraft}
|
||||
onResolutionDraftChange={onResolutionDraftChange}
|
||||
/>
|
||||
)}
|
||||
|
||||
<HostDetailsSettingRow
|
||||
icon={<ShieldCheck />}
|
||||
label={t("hostDetails.rdp.securityMode")}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import React, { useId, useState } from "react";
|
||||
import {
|
||||
DEFAULT_RDP_HEIGHT,
|
||||
DEFAULT_RDP_WIDTH,
|
||||
parseRdpDimensionDraft,
|
||||
type RdpResolutionDraft,
|
||||
} from "../../domain/remoteDesktop";
|
||||
import type { Host } from "../../types";
|
||||
import { Input } from "../ui/input";
|
||||
|
||||
export interface RdpResolutionDraftProps {
|
||||
resolutionDraft?: RdpResolutionDraft;
|
||||
onResolutionDraftChange?: (dimension: "width" | "height", value: string) => void;
|
||||
}
|
||||
|
||||
interface RdpResolutionFieldsProps extends RdpResolutionDraftProps {
|
||||
form: Host;
|
||||
setForm: React.Dispatch<React.SetStateAction<Host>>;
|
||||
t: (key: string) => string;
|
||||
}
|
||||
|
||||
export const RdpResolutionFields: React.FC<RdpResolutionFieldsProps> = ({
|
||||
form, setForm, t, resolutionDraft, onResolutionDraftChange,
|
||||
}) => {
|
||||
const [localDraft, setLocalDraft] = useState<RdpResolutionDraft>({});
|
||||
const id = useId();
|
||||
const draft = resolutionDraft ?? localDraft;
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{(["width", "height"] as const).map((dimension) => {
|
||||
const value = draft[dimension] ?? String(form.rdpConfig?.[dimension]
|
||||
?? (dimension === "width" ? DEFAULT_RDP_WIDTH : DEFAULT_RDP_HEIGHT));
|
||||
const invalid = parseRdpDimensionDraft(value) === undefined;
|
||||
const inputId = `${id}-${dimension}`;
|
||||
return (
|
||||
<div key={dimension} className="space-y-1">
|
||||
<div className="flex items-center justify-between gap-2 bg-transparent px-1 h-10">
|
||||
<label htmlFor={inputId} className="text-sm font-medium text-foreground shrink-0">
|
||||
{t(`hostDetails.rdp.${dimension}`)}
|
||||
</label>
|
||||
<Input
|
||||
id={inputId}
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
value={value}
|
||||
aria-invalid={invalid}
|
||||
aria-describedby={invalid ? `${inputId}-hint` : undefined}
|
||||
onChange={(e) => {
|
||||
const next = e.target.value;
|
||||
if (onResolutionDraftChange) onResolutionDraftChange(dimension, next);
|
||||
else setLocalDraft((prev) => ({ ...prev, [dimension]: next }));
|
||||
const parsed = parseRdpDimensionDraft(next);
|
||||
if (parsed !== undefined) {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
rdpConfig: { ...prev.rdpConfig, [dimension]: parsed },
|
||||
}));
|
||||
}
|
||||
}}
|
||||
className="h-8 w-20 text-sm text-center font-mono"
|
||||
/>
|
||||
</div>
|
||||
{invalid && (
|
||||
<p id={`${inputId}-hint`} className="px-1 text-xs text-destructive">
|
||||
{t("hostDetails.rdp.dimensionHint")}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -38,10 +38,11 @@ import { Input } from "../ui/input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
|
||||
import { Switch } from "../ui/switch";
|
||||
import { HostDetailsSection, HostDetailsSettingRow } from "./HostDetailsSection";
|
||||
import { RdpResolutionFields, type RdpResolutionDraftProps } from "./RdpResolutionFields";
|
||||
|
||||
type Translate = (key: string, params?: Record<string, unknown>) => string;
|
||||
|
||||
interface RemoteDesktopOptionsSectionProps {
|
||||
interface RemoteDesktopOptionsSectionProps extends RdpResolutionDraftProps {
|
||||
form: Host;
|
||||
setForm: React.Dispatch<React.SetStateAction<Host>>;
|
||||
t: Translate;
|
||||
@@ -51,6 +52,8 @@ export const RemoteDesktopOptionsSection: React.FC<RemoteDesktopOptionsSectionPr
|
||||
form,
|
||||
setForm,
|
||||
t,
|
||||
resolutionDraft,
|
||||
onResolutionDraftChange,
|
||||
}) => {
|
||||
const [advancedOpen, setAdvancedOpen] = useState(() =>
|
||||
Boolean(
|
||||
@@ -99,36 +102,13 @@ export const RemoteDesktopOptionsSection: React.FC<RemoteDesktopOptionsSectionPr
|
||||
</HostDetailsSettingRow>
|
||||
|
||||
{rdp.resolutionMode === "fixed" && (
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="flex items-center justify-between gap-2 bg-transparent px-1 h-10">
|
||||
<span className="text-sm font-medium text-foreground shrink-0">{t("hostDetails.rdp.width")}</span>
|
||||
<Input
|
||||
type="number"
|
||||
min={200}
|
||||
max={8192}
|
||||
value={rdp.width}
|
||||
onChange={(e) => {
|
||||
const n = Number.parseInt(e.target.value, 10);
|
||||
if (Number.isFinite(n)) updateRdp("width", n);
|
||||
}}
|
||||
className="h-8 w-20 text-sm text-center font-mono"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-2 bg-transparent px-1 h-10">
|
||||
<span className="text-sm font-medium text-foreground shrink-0">{t("hostDetails.rdp.height")}</span>
|
||||
<Input
|
||||
type="number"
|
||||
min={200}
|
||||
max={8192}
|
||||
value={rdp.height}
|
||||
onChange={(e) => {
|
||||
const n = Number.parseInt(e.target.value, 10);
|
||||
if (Number.isFinite(n)) updateRdp("height", n);
|
||||
}}
|
||||
className="h-8 w-20 text-sm text-center font-mono"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<RdpResolutionFields
|
||||
form={form}
|
||||
setForm={setForm}
|
||||
t={t}
|
||||
resolutionDraft={resolutionDraft}
|
||||
onResolutionDraftChange={onResolutionDraftChange}
|
||||
/>
|
||||
)}
|
||||
|
||||
<HostDetailsSettingRow
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
} from "../../domain/remoteDesktop";
|
||||
import type { Host } from "../../types";
|
||||
import { HostDetailsConnectionSections } from "../HostDetailsConnectionSections";
|
||||
import { CompanionRemoteDesktopSections } from "../host-details/CompanionRemoteDesktopSections";
|
||||
import { CompanionRemoteDesktopInlineFields, CompanionRemoteDesktopSections } from "../host-details/CompanionRemoteDesktopSections";
|
||||
import {
|
||||
resolvePrimaryProtocolSavePort,
|
||||
resolvePrimaryProtocolSwitchPort,
|
||||
@@ -316,3 +316,28 @@ test("buildHostForProtocolOverride keeps SSH identity for companion RDP/VNC and
|
||||
assert.equal(sshDispatch.host.protocol, "ssh");
|
||||
assert.equal(sshDispatch.host.rdpConfig?.defaultConnect, undefined);
|
||||
});
|
||||
|
||||
for (const resolutionMode of ["fixed", "dynamic", "fit"] as const) {
|
||||
test(`companion RDP shows dimensions only in fixed mode: ${resolutionMode}`, () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<TooltipProvider>
|
||||
<CompanionRemoteDesktopInlineFields
|
||||
protocol="rdp"
|
||||
form={makeHost({ rdpConfig: { enabled: true, resolutionMode, width: 1920, height: 1080 } })}
|
||||
setForm={() => {}}
|
||||
identities={[]}
|
||||
t={(key) => key}
|
||||
/>
|
||||
</TooltipProvider>,
|
||||
);
|
||||
for (const dimension of ["width", "height"]) {
|
||||
const label = new RegExp(`hostDetails\\.rdp\\.${dimension}`);
|
||||
if (resolutionMode === "fixed") assert.match(markup, label);
|
||||
else assert.doesNotMatch(markup, label);
|
||||
}
|
||||
if (resolutionMode === "fixed") {
|
||||
assert.match(markup, /inputMode="numeric"[^>]*value="1920"/);
|
||||
assert.match(markup, /inputMode="numeric"[^>]*value="1080"/);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
getAvailableRemoteDesktopProtocols,
|
||||
hasCompanionRdp,
|
||||
hasCompanionVnc,
|
||||
hasValidRdpFixedResolution,
|
||||
parseRdpDimensionDraft,
|
||||
isRdpProtocol,
|
||||
isRemoteDesktopProtocol,
|
||||
isVncProtocol,
|
||||
@@ -418,3 +420,25 @@ test('mapViewportToVirtualDesktopCoords maps full view and cropped single-monito
|
||||
{ x: 3839, y: 1079 },
|
||||
);
|
||||
});
|
||||
|
||||
test('fixed RDP resolution validation rejects invalid drafts before sanitization', () => {
|
||||
const config = { resolutionMode: 'fixed' as const, width: 1920, height: 1080 };
|
||||
for (const value of ['', ' ', '19', '192', '199', '8193', '3840.5', 'abc', 'Infinity']) {
|
||||
assert.equal(parseRdpDimensionDraft(value), undefined, value);
|
||||
assert.equal(hasValidRdpFixedResolution(config, { width: value }), false, value);
|
||||
assert.equal(hasValidRdpFixedResolution(config, { height: value }), false, value);
|
||||
}
|
||||
for (const value of ['200', '3840', '8192']) {
|
||||
assert.equal(parseRdpDimensionDraft(value), Number(value));
|
||||
assert.equal(hasValidRdpFixedResolution(config, { width: value, height: value }), true);
|
||||
}
|
||||
for (const dimension of [192, 8193, 3840.5, NaN]) {
|
||||
assert.equal(hasValidRdpFixedResolution({ ...config, width: dimension }), false);
|
||||
assert.equal(hasValidRdpFixedResolution({ ...config, height: dimension }), false);
|
||||
}
|
||||
assert.equal(hasValidRdpFixedResolution(config), true);
|
||||
assert.equal(hasValidRdpFixedResolution({ resolutionMode: 'fixed' }), true);
|
||||
for (const resolutionMode of ['dynamic', 'fit'] as const) {
|
||||
assert.equal(hasValidRdpFixedResolution({ ...config, resolutionMode }, { width: '' }), true);
|
||||
}
|
||||
});
|
||||
@@ -24,6 +24,25 @@ export const DEFAULT_RDP_COLOR_DEPTH: RdpColorDepth = 32;
|
||||
export const DEFAULT_RDP_RESOLUTION_MODE: RdpResolutionMode = 'dynamic';
|
||||
export const DEFAULT_RDP_SECURITY_MODE: RdpSecurityMode = 'auto';
|
||||
|
||||
// Editor drafts stay separate from the sanitized config until they are valid.
|
||||
export type RdpResolutionDraft = Partial<Record<'width' | 'height', string>>;
|
||||
|
||||
export const parseRdpDimensionDraft = (value: string): number | undefined => {
|
||||
if (!value.trim()) return undefined;
|
||||
const dimension = Number(value);
|
||||
return Number.isInteger(dimension) && dimension >= 200 && dimension <= 8192
|
||||
? dimension
|
||||
: undefined;
|
||||
};
|
||||
|
||||
export const hasValidRdpFixedResolution = (
|
||||
config: RdpConfig | undefined,
|
||||
draft: RdpResolutionDraft = {},
|
||||
): boolean => config?.resolutionMode !== 'fixed' || (
|
||||
parseRdpDimensionDraft(draft.width ?? String(config.width ?? DEFAULT_RDP_WIDTH)) !== undefined
|
||||
&& parseRdpDimensionDraft(draft.height ?? String(config.height ?? DEFAULT_RDP_HEIGHT)) !== undefined
|
||||
);
|
||||
|
||||
export const DEFAULT_VNC_SCALING_MODE: VncScalingMode = 'fit';
|
||||
export const DEFAULT_VNC_QUALITY = 6;
|
||||
export const DEFAULT_VNC_COMPRESSION_LEVEL = 2;
|
||||
|
||||
Reference in new issue
Block a user