feat(sqlserver): support legacy TLS compatibility
This commit is contained in:
30 files changed
+738
-117
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isSqlServerLegacyCompatibilityMode, requiresSqlServerLegacyCompatibilityComponent, setSqlServerLegacyCompatibilityMode } from "@/lib/connection/sqlServerLegacyCompatibility";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
function connectionConfig(urlParams?: string): ConnectionConfig {
|
||||
return {
|
||||
id: "sqlserver",
|
||||
name: "SQL Server",
|
||||
db_type: "sqlserver",
|
||||
driver_profile: "sqlserver",
|
||||
driver_label: "SQL Server",
|
||||
host: "127.0.0.1",
|
||||
port: 1433,
|
||||
username: "sa",
|
||||
password: "secret",
|
||||
database: "master",
|
||||
url_params: urlParams,
|
||||
ssl: false,
|
||||
ssh_enabled: false,
|
||||
read_only: false,
|
||||
one_time: false,
|
||||
transport_layers: [],
|
||||
agent_java_options: [],
|
||||
};
|
||||
}
|
||||
|
||||
describe("SQL Server legacy compatibility", () => {
|
||||
it("treats existing disabled encryption params as legacy compatibility opt-in", () => {
|
||||
expect(isSqlServerLegacyCompatibilityMode("sqlserverEncryption=disabled")).toBe(true);
|
||||
expect(isSqlServerLegacyCompatibilityMode("applicationName=dbx;encrypt=false")).toBe(true);
|
||||
expect(isSqlServerLegacyCompatibilityMode("?Encrypt=0&applicationName=dbx")).toBe(true);
|
||||
expect(isSqlServerLegacyCompatibilityMode("encrypt=true")).toBe(false);
|
||||
});
|
||||
|
||||
it("updates URL params without keeping conflicting encryption params", () => {
|
||||
expect(setSqlServerLegacyCompatibilityMode("applicationName=dbx;encrypt=true", true)).toBe("applicationName=dbx&sqlserverEncryption=disabled");
|
||||
expect(setSqlServerLegacyCompatibilityMode("applicationName=dbx;sqlserverEncryption=disabled", false)).toBe("applicationName=dbx");
|
||||
});
|
||||
|
||||
it("requires the hidden component only for SQL Server legacy compatibility connections", () => {
|
||||
expect(requiresSqlServerLegacyCompatibilityComponent(connectionConfig("sqlserverEncryption=disabled"))).toBe(true);
|
||||
expect(requiresSqlServerLegacyCompatibilityComponent(connectionConfig("encrypt=true"))).toBe(false);
|
||||
expect(
|
||||
requiresSqlServerLegacyCompatibilityComponent({
|
||||
...connectionConfig("sqlserverEncryption=disabled"),
|
||||
db_type: "mysql",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -75,6 +75,7 @@ export const installJdbcPluginLocal = forward("installJdbcPluginLocal");
|
||||
export const uninstallJdbcPlugin = forward("uninstallJdbcPlugin");
|
||||
export const listInstalledAgentsLocal = forward("listInstalledAgentsLocal");
|
||||
export const listInstalledAgents = forward("listInstalledAgents");
|
||||
export const isAgentInstalled = forward("isAgentInstalled");
|
||||
export const getDriverStoreUsage = forward("getDriverStoreUsage");
|
||||
export const clearDriverDownloadCache = forward("clearDriverDownloadCache");
|
||||
export const getDriverRuntimeSummary = forward("getDriverRuntimeSummary");
|
||||
|
||||
@@ -337,6 +337,10 @@ export async function listInstalledAgents(): Promise<AgentDriverInfo[]> {
|
||||
return get("/api/agents/installed");
|
||||
}
|
||||
|
||||
export async function isAgentInstalled(dbType: string): Promise<boolean> {
|
||||
return get(`/api/agents/installed/${encodeURIComponent(dbType)}`);
|
||||
}
|
||||
|
||||
export async function getDriverStoreUsage(): Promise<DriverStoreUsage> {
|
||||
return get("/api/agents/storage-usage");
|
||||
}
|
||||
|
||||
@@ -1122,6 +1122,10 @@ export async function listInstalledAgents(): Promise<AgentDriverInfo[]> {
|
||||
return invoke("list_installed_agents");
|
||||
}
|
||||
|
||||
export async function isAgentInstalled(dbType: string): Promise<boolean> {
|
||||
return invoke("is_agent_installed", { dbType });
|
||||
}
|
||||
|
||||
export async function getDriverStoreUsage(): Promise<DriverStoreUsage> {
|
||||
return invoke("get_driver_store_usage");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
export const SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY = "sqlserver-legacy";
|
||||
|
||||
const SQLSERVER_LEGACY_DISABLED_VALUES = new Set(["disabled", "disable", "false", "0", "off", "no"]);
|
||||
|
||||
export function isSqlServerLegacyCompatibilityMode(params: string | undefined): boolean {
|
||||
const normalized = (params || "").trim().replace(/^\?/, "").replace(/;/g, "&");
|
||||
if (!normalized) return false;
|
||||
const parsed = new URLSearchParams(normalized);
|
||||
for (const [key, value] of parsed.entries()) {
|
||||
const normalizedKey = key.trim().toLowerCase();
|
||||
if (normalizedKey === "sqlserverencryption" || normalizedKey === "encrypt") {
|
||||
// Accept JDBC-style `encrypt=false` from imported SQL Server URLs as the same opt-in.
|
||||
if (SQLSERVER_LEGACY_DISABLED_VALUES.has(value.trim().toLowerCase())) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function setSqlServerLegacyCompatibilityMode(params: string | undefined, enabled: boolean): string {
|
||||
const normalized = (params || "").trim().replace(/^\?/, "").replace(/;/g, "&");
|
||||
const parsed = new URLSearchParams(normalized);
|
||||
for (const key of Array.from(parsed.keys())) {
|
||||
const normalizedKey = key.trim().toLowerCase();
|
||||
if (normalizedKey === "sqlserverencryption" || normalizedKey === "encrypt") parsed.delete(key);
|
||||
}
|
||||
if (enabled) parsed.set("sqlserverEncryption", "disabled");
|
||||
return parsed.toString();
|
||||
}
|
||||
|
||||
export function requiresSqlServerLegacyCompatibilityComponent(config: ConnectionConfig): boolean {
|
||||
return config.db_type === "sqlserver" && isSqlServerLegacyCompatibilityMode(config.url_params);
|
||||
}
|
||||
Reference in new issue
Block a user