Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.7 KB
Raw Blame
import assert from "node:assert/strict";
import { test } from "vitest";
import { applySshConfigHostAliasPrefill } from "../../apps/desktop/src/lib/connection/sshConfigHosts.ts";
import type { SshTunnelConfig } from "../../apps/desktop/src/types/database.ts";

function sshConfig(overrides: Partial<SshTunnelConfig> = {}): SshTunnelConfig {
  return {
    id: "ssh-1",
    host: "production",
    port: 22,
    user: "root",
    password: "",
    key_path: "",
    key_passphrase: "",
    connect_timeout_secs: 5,
    expose_lan: false,
    auth_method: "password",
    ...overrides,
  };
}

const hosts = [
  {
    alias: "production",
    host_name: "10.0.0.5",
    port: 2222,
    user: "deploy",
    identity_file: "~/.ssh/production_ed25519",
  },
];

test("prefills default SSH fields from a selected config alias", () => {
  const target = sshConfig();

  applySshConfigHostAliasPrefill(target, hosts);

  assert.equal(target.host, "production");
  assert.equal(target.port, 2222);
  assert.equal(target.user, "deploy");
  assert.equal(target.key_path, "~/.ssh/production_ed25519");
  assert.equal(target.auth_method, "key");
});

test("does not overwrite explicit SSH form values", () => {
  const target = sshConfig({ port: 2200, user: "admin", password: "secret", key_path: "~/.ssh/custom" });

  applySshConfigHostAliasPrefill(target, hosts);

  assert.equal(target.port, 2200);
  assert.equal(target.user, "admin");
  assert.equal(target.key_path, "~/.ssh/custom");
  assert.equal(target.auth_method, "password");
});

test("leaves the form unchanged when no config alias matches", () => {
  const target = sshConfig({ host: "unknown" });
  const before = structuredClone(target);

  applySshConfigHostAliasPrefill(target, hosts);

  assert.deepEqual(target, before);
});