fix(dameng): support SSL connection settings
This commit is contained in:
15 files changed
+308
-3
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("Dameng SSL connection form", () => {
|
||||
it("shows Dameng in the TLS tab with certificate directory and password fields", () => {
|
||||
expect(dialogSource).toContain('"questdb", "dameng", "redis"');
|
||||
expect(dialogSource).toContain("<template v-if=\"form.db_type === 'dameng'\">");
|
||||
expect(dialogSource).toContain('v-model="damengSslFilesPath"');
|
||||
expect(dialogSource).toContain('v-model="damengSslKeystorePassword"');
|
||||
expect(dialogSource).toContain('v-model="damengSslProtocol"');
|
||||
expect(dialogSource).toContain('t("connection.damengSslVerificationHint")');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseConnectionUrl } from "@/lib/connection/connectionUrl";
|
||||
|
||||
describe("Dameng connection URLs", () => {
|
||||
it("parses JDBC SSL parameters and enables the TLS form", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:dm://dm.example.com:5236/MAIN?sslFilesPath=/Users/test/dmcert&sslkeystorePass=secret");
|
||||
|
||||
expect(parsed).toMatchObject({
|
||||
dbType: "dameng",
|
||||
driverProfile: "dm",
|
||||
host: "dm.example.com",
|
||||
port: 5236,
|
||||
database: "MAIN",
|
||||
urlParams: "sslFilesPath=/Users/test/dmcert&sslkeystorePass=secret",
|
||||
ssl: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyDamengSslUrlParams, damengSslFormConfig } from "@/lib/database/damengSslOptions";
|
||||
|
||||
describe("Dameng SSL URL parameters", () => {
|
||||
it("reads SSL fields without changing parameter casing requirements", () => {
|
||||
expect(damengSslFormConfig("schema=APP&sslFilesPath=/Users/test/dmcert&sslkeystorePass=secret&sslProtocol=TLSv1.2")).toEqual({
|
||||
enabled: true,
|
||||
sslFilesPath: "/Users/test/dmcert",
|
||||
sslKeystorePassword: "secret",
|
||||
sslProtocol: "TLSv1.2",
|
||||
});
|
||||
});
|
||||
|
||||
it("updates SSL fields while preserving unrelated URL parameters", () => {
|
||||
expect(applyDamengSslUrlParams("?schema=APP;compatMode=oracle", true, "/opt/dm/cert", "changeit", "TLSv1.2")).toBe("schema=APP&compatMode=oracle&sslFilesPath=/opt/dm/cert&sslkeystorePass=changeit&sslProtocol=TLSv1.2");
|
||||
});
|
||||
|
||||
it("removes only managed SSL fields when SSL is disabled", () => {
|
||||
expect(applyDamengSslUrlParams("schema=APP&sslFilesPath=/opt/dm/cert&sslkeystorePass=secret&sslProtocol=TLSv1.2&foo=", false, "", "", "")).toBe("schema=APP&foo=");
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ConnectionConfig, DatabaseType } from "@/types/database";
|
||||
import { h2JdbcUrlHasPasswordParam, h2JdbcUrlHasUserParam, parseH2JdbcUrl } from "@/lib/database/h2Connection";
|
||||
import { damengSslFormConfig } from "@/lib/database/damengSslOptions";
|
||||
|
||||
export interface ParsedConnectionUrl {
|
||||
name?: string;
|
||||
@@ -226,6 +227,10 @@ function extractMysqlCredentialParams(params: string): { username?: string; pass
|
||||
}
|
||||
|
||||
function urlParamsRequireTls(dbType: DatabaseType, params: string): boolean {
|
||||
if (dbType === "dameng") {
|
||||
return damengSslFormConfig(params).enabled;
|
||||
}
|
||||
|
||||
if (dbType === "mysql") {
|
||||
const requireSsl = queryParamValue(params, "require_ssl")?.toLowerCase();
|
||||
if (requireSsl === "true" || requireSsl === "1" || requireSsl === "yes") return true;
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
export interface DamengSslFormConfig {
|
||||
enabled: boolean;
|
||||
sslFilesPath: string;
|
||||
sslKeystorePassword: string;
|
||||
sslProtocol: string;
|
||||
}
|
||||
|
||||
interface DamengUrlParam {
|
||||
key: string;
|
||||
value: string;
|
||||
raw: string;
|
||||
}
|
||||
|
||||
const SSL_FILES_PATH_KEY = "sslfilespath";
|
||||
const SSL_KEYSTORE_PASSWORD_KEY = "sslkeystorepass";
|
||||
const SSL_PROTOCOL_KEY = "sslprotocol";
|
||||
|
||||
export function damengSslFormConfig(urlParams?: string): DamengSslFormConfig {
|
||||
const params = parseDamengUrlParams(urlParams);
|
||||
const sslFilesPath = getDamengUrlParam(params, SSL_FILES_PATH_KEY);
|
||||
const sslKeystorePassword = getDamengUrlParam(params, SSL_KEYSTORE_PASSWORD_KEY);
|
||||
const sslProtocol = getDamengUrlParam(params, SSL_PROTOCOL_KEY);
|
||||
|
||||
return {
|
||||
enabled: params.some((param) => isManagedDamengSslParam(param.key)),
|
||||
sslFilesPath,
|
||||
sslKeystorePassword,
|
||||
sslProtocol,
|
||||
};
|
||||
}
|
||||
|
||||
export function applyDamengSslUrlParams(urlParams: string | undefined, enabled: boolean, sslFilesPath: string, sslKeystorePassword: string, sslProtocol: string): string {
|
||||
const parts = parseDamengUrlParams(urlParams)
|
||||
.filter((param) => !isManagedDamengSslParam(param.key))
|
||||
.map((param) => param.raw);
|
||||
|
||||
if (enabled) {
|
||||
const normalizedFilesPath = sslFilesPath.trim();
|
||||
const normalizedProtocol = sslProtocol.trim();
|
||||
if (normalizedFilesPath) parts.push(`sslFilesPath=${normalizedFilesPath}`);
|
||||
if (sslKeystorePassword) parts.push(`sslkeystorePass=${sslKeystorePassword}`);
|
||||
if (normalizedProtocol) parts.push(`sslProtocol=${normalizedProtocol}`);
|
||||
}
|
||||
|
||||
return parts.join("&");
|
||||
}
|
||||
|
||||
function parseDamengUrlParams(urlParams?: string): DamengUrlParam[] {
|
||||
return (urlParams || "")
|
||||
.trim()
|
||||
.replace(/^[?&;]+/, "")
|
||||
.replace(/[?&;]+$/, "")
|
||||
.split(/[&;]/)
|
||||
.map((part) => part.trim())
|
||||
.filter(Boolean)
|
||||
.map((raw) => {
|
||||
const equals = raw.indexOf("=");
|
||||
if (equals < 0) return { key: raw, value: "", raw };
|
||||
return {
|
||||
key: raw.slice(0, equals).trim(),
|
||||
value: raw.slice(equals + 1).trim(),
|
||||
raw,
|
||||
};
|
||||
})
|
||||
.filter((param) => !!param.key);
|
||||
}
|
||||
|
||||
function getDamengUrlParam(params: DamengUrlParam[], key: string): string {
|
||||
return params.find((param) => param.key.toLowerCase() === key)?.value || "";
|
||||
}
|
||||
|
||||
function isManagedDamengSslParam(key: string): boolean {
|
||||
const normalizedKey = key.trim().toLowerCase();
|
||||
return normalizedKey === SSL_FILES_PATH_KEY || normalizedKey === SSL_KEYSTORE_PASSWORD_KEY || normalizedKey === SSL_PROTOCOL_KEY;
|
||||
}
|
||||
Reference in new issue
Block a user