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。

fix(connection): 为各类连接表单补齐保存密码开关

zipga438fdf21f92
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue
index 30fe670aed..8e109929ea 100644
--- a/apps/desktop/src/components/connection/ConnectionDialog.vue
+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue
@@ -8,6 +8,7 @@ import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
import PasswordInput from "@/components/ui/PasswordInput.vue";
+import SavePasswordCheckbox from "@/components/connection/SavePasswordCheckbox.vue";
import { Label } from "@/components/ui/label";
import { sidebarProductionBadgeScope } from "@/lib/sidebar/sidebarProductionBadge";
import type { ProductionBadgeScope } from "@/types/database";
@@ -7637,18 +7638,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
- <div class="grid grid-cols-4 items-center gap-4">
- <span />
- <div class="col-span-3 flex items-center gap-1.5 text-sm">
- <label class="flex items-center gap-2">
- <input v-model="form.save_password" type="checkbox" class="h-4 w-4 rounded border-border accent-primary" :aria-label="t('connection.savePassword')" />
- <span class="whitespace-nowrap">{{ t("connection.savePassword") }}</span>
- </label>
- <HelpTooltip :label="t('connection.savePassword')">
- {{ form.save_password ? t("connection.savePasswordHint") : t("connection.savePasswordSessionHint") }}
- </HelpTooltip>
- </div>
- </div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-start gap-4">
<Label :class="connectionLabelTopClass">{{ t("connection.jdbcDriverPaths") }}</Label>
<div class="col-span-3 space-y-2">
@@ -7787,6 +7777,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.sqliteCipherKey") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" :placeholder="t('connection.sqliteCipherKeyPlaceholder')" />
</div>
+ <SavePasswordCheckbox v-if="form.db_type === 'sqlite' && !sqliteUsesSsh" v-model="form.save_password" />
<div v-if="form.db_type === 'sqlite' && !sqliteUsesSsh" class="grid grid-cols-4 items-start gap-4">
<Label :class="connectionLabelTopClass">{{ t("connection.sqliteExtensions") }}</Label>
<div class="col-span-3 space-y-1">
@@ -7834,6 +7825,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}{{ form.db_type === "access" ? t("connection.optionalSuffix") : "" }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
</template>
</template>
@@ -8267,6 +8259,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" :placeholder="t('connection.databasePlaceholder')" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelSmallClass">{{ t("connection.redisKeySeparator") }}</Label>
<Input v-model="form.redis_key_separator" class="col-span-3 h-8 text-xs" placeholder=":" />
@@ -8302,6 +8295,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.consulToken") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" :placeholder="t('connection.consulTokenPlaceholder')" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ t("connection.consulDatacenter") }}</Label>
<Input v-model="consulDatacenter" class="col-span-3" placeholder="dc1" />
@@ -8407,6 +8401,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
</template>
<!-- ZooKeeper: host, connect string, user, password -->
@@ -8450,6 +8445,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
</template>
<!-- DynamoDB: endpoint, region, AWS credentials -->
@@ -8478,6 +8474,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.dynamodbSecretAccessKey") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelSmallClass">{{ t("connection.dynamodbSessionToken") }}</Label>
<PasswordInput v-model="form.connection_string" class="col-span-3" :placeholder="t('connection.dynamodbSessionTokenPlaceholder')" />
@@ -8582,6 +8579,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-if="mongoAuthMechanism !== 'MONGODB-OIDC'" v-model="form.save_password" />
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ t("connection.defaultDatabase") }}</Label>
<Input v-model="form.database" class="col-span-3" :placeholder="t('connection.databasePlaceholder')" />
@@ -8733,6 +8731,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-start gap-4">
<Label :class="connectionLabelSmallClass">{{ t("connection.victoriametricsApiPath") }}</Label>
<div class="col-span-3 space-y-1.5">
@@ -8789,6 +8788,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">Token</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
</template>
<template v-else-if="influxDbVersion === '3'">
<div class="grid grid-cols-4 items-center gap-4">
@@ -8799,6 +8799,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">Token</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
</template>
<template v-else>
<div class="grid grid-cols-4 items-center gap-4">
@@ -8809,6 +8810,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.password") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ t("connection.database") }}</Label>
<Input v-model="form.database" class="col-span-3" :placeholder="t('connection.databasePlaceholder')" />
@@ -8837,6 +8839,7 @@ function openExternalUrl(url: string) {
<PasswordInput v-model="form.password" class="col-span-3" placeholder="eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9..." />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-start gap-4">
<span />
<p class="col-span-3 text-xs text-muted-foreground">{{ t("connection.tursoTokenHint") }} <code class="px-1 py-0.5 rounded bg-muted text-xs">turso db tokens create &lt;database-name&gt;</code></p>
@@ -8926,6 +8929,7 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.salesforceAccessToken") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" :placeholder="t('connection.salesforceAccessTokenPlaceholder')" />
</div>
+ <SavePasswordCheckbox v-model="form.save_password" />
<div class="grid grid-cols-4 items-start gap-4">
<span />
<p class="col-span-3 text-xs leading-5 text-muted-foreground">{{ t("connection.salesforceAccessTokenHint") }}</p>
@@ -9296,18 +9300,7 @@ function openExternalUrl(url: string) {
<PasswordInput v-model="form.password" class="col-span-3" />
</div>
- <div v-if="form.db_type !== 'spanner'" class="grid grid-cols-4 items-center gap-4">
- <span />
- <div class="col-span-3 flex items-center gap-1.5 text-sm">
- <label class="flex items-center gap-2">
- <input v-model="form.save_password" type="checkbox" class="h-4 w-4 rounded border-border accent-primary" :aria-label="t('connection.savePassword')" />
- <span class="whitespace-nowrap">{{ t("connection.savePassword") }}</span>
- </label>
- <HelpTooltip :label="t('connection.savePassword')">
- {{ form.save_password ? t("connection.savePasswordHint") : t("connection.savePasswordSessionHint") }}
- </HelpTooltip>
- </div>
- </div>
+ <SavePasswordCheckbox v-if="form.db_type !== 'spanner'" v-model="form.save_password" />
<div v-if="form.db_type !== 'hbase' && form.db_type !== 'meilisearch' && form.db_type !== 'solr' && form.db_type !== 'spanner'" class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ databaseLabel }}</Label>
diff --git a/apps/desktop/src/components/connection/SavePasswordCheckbox.vue b/apps/desktop/src/components/connection/SavePasswordCheckbox.vue
new file mode 100644
index 0000000000..5f81f456c4
--- /dev/null
+++ b/apps/desktop/src/components/connection/SavePasswordCheckbox.vue
@@ -0,0 +1,23 @@
+<script setup lang="ts">
+import { useI18n } from "vue-i18n";
+import { HelpTooltip } from "@/components/ui/tooltip";
+
+const props = withDefaults(defineProps<{ modelValue?: boolean }>(), { modelValue: true });
+const emit = defineEmits<{ "update:modelValue": [value: boolean] }>();
+const { t } = useI18n();
+</script>
+
+<template>
+ <div class="grid grid-cols-4 items-center gap-4">
+ <span />
+ <div class="col-span-3 flex items-center gap-1.5 text-sm">
+ <label class="flex items-center gap-2">
+ <input :checked="props.modelValue" type="checkbox" class="h-4 w-4 rounded border-border accent-primary" :aria-label="t('connection.savePassword')" @change="emit('update:modelValue', ($event.target as HTMLInputElement).checked)" />
+ <span class="whitespace-nowrap">{{ t("connection.savePassword") }}</span>
+ </label>
+ <HelpTooltip :label="t('connection.savePassword')">
+ {{ props.modelValue ? t("connection.savePasswordHint") : t("connection.savePasswordSessionHint") }}
+ </HelpTooltip>
+ </div>
+ </div>
+</template>
diff --git a/apps/desktop/src/components/connection/__tests__/ConnectionDialog.savePassword.spec.ts b/apps/desktop/src/components/connection/__tests__/ConnectionDialog.savePassword.spec.ts
new file mode 100644
index 0000000000..93e999d407
--- /dev/null
+++ b/apps/desktop/src/components/connection/__tests__/ConnectionDialog.savePassword.spec.ts
@@ -0,0 +1,278 @@
+// @vitest-environment happy-dom
+
+import { createApp, defineComponent, h, nextTick, reactive, type App } from "vue";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import i18n from "@/i18n";
+import type { ConnectionConfig } from "@/types/database";
+
+const { store, settings, backend } = vi.hoisted(() => ({
+ store: {
+ connectionGroupOptions: [],
+ newConnectionGroupId: null,
+ selectedConnectionGroupId: null,
+ addConnection: vi.fn(),
+ updateConnection: vi.fn(),
+ connect: vi.fn(),
+ ensureConnected: vi.fn(),
+ addEphemeralConnection: vi.fn(),
+ removeConnection: vi.fn(),
+ startEditing: vi.fn(),
+ stopEditing: vi.fn(),
+ clearConnectionError: vi.fn(),
+ updateConnectionDatabaseInfo: vi.fn(),
+ applyGlobalTimeouts: vi.fn((config) => config),
+ getConfig: vi.fn(),
+ },
+ settings: {
+ editorSettings: { sidebarShowConnectionNotes: false, globalConnectTimeoutSecs: 10, globalQueryTimeoutSecs: 0 },
+ rememberedDatabaseForConnection: vi.fn(() => ""),
+ persistEditorSettings: vi.fn(),
+ updateEditorSettings: vi.fn(),
+ updateEditorSettingsAndPersist: vi.fn(),
+ },
+ backend: {
+ connectDb: vi.fn(),
+ disconnectDb: vi.fn(),
+ testConnectionWithInfo: vi.fn(),
+ listDatabases: vi.fn(),
+ listPlugins: vi.fn(),
+ listJdbcDrivers: vi.fn(),
+ listJdbcMavenBundles: vi.fn(),
+ listJdbcLocalBundles: vi.fn(),
+ listSshConfigHosts: vi.fn(),
+ listInstalledAgentsLocal: vi.fn(),
+ listenAgentInstallProgress: vi.fn(),
+ },
+}));
+
+vi.mock("@/stores/connectionStore", () => ({ useConnectionStore: () => store, CONNECTION_ATTEMPT_CANCELLED_MESSAGE: "cancelled" }));
+vi.mock("@/stores/settingsStore", async (original) => ({ ...(await original<typeof import("@/stores/settingsStore")>()), useSettingsStore: () => settings }));
+vi.mock("@/stores/tunnelProfileStore", () => ({ useTunnelProfileStore: () => ({ profiles: [], profileById: () => undefined, init: vi.fn() }) }));
+vi.mock("@/lib/backend/api", async (original) => ({ ...(await original<typeof import("@/lib/backend/api")>()), ...backend }));
+vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
+vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));
+
+vi.mock("@/components/ui/dialog", async () => {
+ const { defineComponent, h } = await import("vue");
+ const passthrough = defineComponent({
+ setup:
+ (_props, { slots }) =>
+ () =>
+ h("div", slots.default?.()),
+ });
+ const Dialog = defineComponent({
+ props: { open: Boolean },
+ emits: ["update:open"],
+ setup:
+ (props, { slots, emit }) =>
+ () =>
+ props.open ? h("section", [h("button", { "data-testid": "dismiss-dialog", onClick: () => emit("update:open", false) }, "Dismiss"), slots.default?.()]) : null,
+ });
+ return { Dialog, DialogContent: passthrough, DialogHeader: passthrough, DialogTitle: passthrough, DialogFooter: passthrough };
+});
+vi.mock("@/components/ui/button", async () => {
+ const { defineComponent, h } = await import("vue");
+ return {
+ Button: defineComponent({
+ inheritAttrs: false,
+ setup:
+ (_props, { attrs, slots }) =>
+ () =>
+ h("button", attrs, slots.default?.()),
+ }),
+ };
+});
+vi.mock("@/components/ui/input", async () => {
+ const { defineComponent, h } = await import("vue");
+ return {
+ Input: defineComponent({
+ props: ["modelValue"],
+ emits: ["update:modelValue"],
+ setup:
+ (props, { attrs, emit }) =>
+ () =>
+ h("input", { ...attrs, value: props.modelValue, onInput: (event: Event) => emit("update:modelValue", (event.target as HTMLInputElement).value) }),
+ }),
+ };
+});
+vi.mock("@/components/ui/PasswordInput.vue", async () => {
+ const { defineComponent, h } = await import("vue");
+ return {
+ default: defineComponent({
+ props: ["modelValue"],
+ setup:
+ (props, { attrs }) =>
+ () =>
+ h("input", { ...attrs, type: "password", value: props.modelValue }),
+ }),
+ };
+});
+vi.mock("@/components/ui/tabs", async () => {
+ const { defineComponent, h } = await import("vue");
+ const pass = defineComponent({
+ setup:
+ (_props, { slots }) =>
+ () =>
+ h("div", slots.default?.()),
+ });
+ const TabsContent = defineComponent({
+ props: ["value"],
+ setup:
+ (props, { slots }) =>
+ () =>
+ props.value === "connection" ? h("div", slots.default?.()) : null,
+ });
+ return { Tabs: pass, TabsContent, TabsList: pass, TabsTrigger: pass };
+});
+vi.mock("@/components/ui/tooltip", async () => {
+ const { defineComponent, h } = await import("vue");
+ const pass = defineComponent({
+ setup:
+ (_props, { slots }) =>
+ () =>
+ h("span", slots.default?.()),
+ });
+ return { HelpTooltip: pass, Tooltip: pass, TooltipContent: pass, TooltipTrigger: pass };
+});
+
+import ConnectionDialog from "@/components/connection/ConnectionDialog.vue";
+
+const mountedApps: App[] = [];
+
+function salesforceConnection(overrides: Partial<ConnectionConfig> = {}): ConnectionConfig {
+ return {
+ id: "sfdc-sandbox",
+ name: "Salesforce sandbox",
+ db_type: "salesforce",
+ driver_profile: "salesforce",
+ driver_label: "Salesforce",
+ host: "https://acme--qas1.sandbox.my.salesforce.com",
+ port: 443,
+ password: "saved-access-token",
+ ssl: true,
+ save_password: true,
+ ...overrides,
+ } as ConnectionConfig;
+}
+
+async function settle() {
+ for (let i = 0; i < 8; i++) await nextTick();
+}
+
+async function mountDialog(config: ConnectionConfig) {
+ const props = reactive({ open: true, editConfig: config });
+ store.getConfig.mockReturnValue(config);
+ const container = document.createElement("div");
+ document.body.append(container);
+ const app = createApp(
+ defineComponent({
+ setup: () => () =>
+ h(ConnectionDialog, {
+ ...props,
+ "onUpdate:open": (value: boolean) => {
+ props.open = value;
+ },
+ }),
+ }),
+ );
+ app.use(i18n);
+ mountedApps.push(app);
+ app.mount(container);
+ await settle();
+ return props;
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ i18n.global.locale.value = "en";
+ for (const fn of Object.values(backend)) fn.mockResolvedValue([]);
+ backend.listenAgentInstallProgress.mockResolvedValue(() => {});
+ store.updateConnection.mockResolvedValue(undefined);
+ store.addConnection.mockResolvedValue(undefined);
+});
+
+afterEach(() => {
+ for (const app of mountedApps.splice(0)) app.unmount();
+ document.body.innerHTML = "";
+});
+
+function redisConnection(overrides: Partial<ConnectionConfig> = {}): ConnectionConfig {
+ return {
+ id: "redis-1",
+ name: "Redis",
+ db_type: "redis",
+ host: "127.0.0.1",
+ port: 6379,
+ password: "secret",
+ save_password: true,
+ ...overrides,
+ } as ConnectionConfig;
+}
+
+function savePasswordCheckbox(): HTMLInputElement | null {
+ return document.querySelector<HTMLInputElement>('input[aria-label="Save password"]');
+}
+
+describe("ConnectionDialog save-password checkbox", () => {
+ it("renders on the Redis form and toggles form.save_password", async () => {
+ await mountDialog(redisConnection());
+
+ const checkbox = savePasswordCheckbox();
+ expect(checkbox, "Redis form should render the save-password checkbox").toBeTruthy();
+ expect(checkbox!.checked).toBe(true);
+
+ checkbox!.click();
+ await settle();
+
+ expect(savePasswordCheckbox()!.checked).toBe(false);
+ });
+
+ it("renders on the MongoDB form mode", async () => {
+ await mountDialog({
+ id: "mongo-1",
+ name: "MongoDB",
+ db_type: "mongodb",
+ host: "127.0.0.1",
+ port: 27017,
+ username: "dbx",
+ password: "secret",
+ save_password: true,
+ } as ConnectionConfig);
+
+ expect(savePasswordCheckbox(), "MongoDB form should render the save-password checkbox").toBeTruthy();
+ });
+
+ it("renders on the etcd form", async () => {
+ await mountDialog({
+ id: "etcd-1",
+ name: "etcd",
+ db_type: "etcd",
+ host: "127.0.0.1",
+ port: 2379,
+ username: "root",
+ password: "secret",
+ save_password: true,
+ } as ConnectionConfig);
+
+ expect(savePasswordCheckbox(), "etcd form should render the save-password checkbox").toBeTruthy();
+ });
+
+ it("renders on the Salesforce access-token form", async () => {
+ await mountDialog(salesforceConnection());
+
+ expect(savePasswordCheckbox(), "Salesforce token form should render the save-password checkbox").toBeTruthy();
+ });
+
+ it("does not render when the connection has no password field", async () => {
+ await mountDialog({
+ id: "spanner-1",
+ name: "Spanner",
+ db_type: "spanner",
+ host: "project/instance",
+ database: "db",
+ save_password: true,
+ } as ConnectionConfig);
+
+ expect(savePasswordCheckbox()).toBeNull();
+ });
+});