feat(sqlserver): support legacy TLS compatibility
This commit is contained in:
30 files changed
+738
-117
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
function installLocalStorage() {
|
||||
const data = new Map<string, string>();
|
||||
vi.stubGlobal("localStorage", {
|
||||
getItem: vi.fn((key: string) => data.get(key) ?? null),
|
||||
setItem: vi.fn((key: string, value: string) => data.set(key, value)),
|
||||
removeItem: vi.fn((key: string) => data.delete(key)),
|
||||
});
|
||||
}
|
||||
|
||||
function sqlServerLegacyConnection(): ConnectionConfig {
|
||||
return {
|
||||
id: "sqlserver-1",
|
||||
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: "sqlserverEncryption=disabled",
|
||||
ssl: false,
|
||||
ssh_enabled: false,
|
||||
read_only: false,
|
||||
one_time: false,
|
||||
transport_layers: [],
|
||||
agent_java_options: [],
|
||||
};
|
||||
}
|
||||
|
||||
describe("connectionStore SQL Server legacy compatibility", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.unstubAllGlobals();
|
||||
installLocalStorage();
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
it("installs the legacy compatibility component before connecting saved legacy configs", async () => {
|
||||
const connectDb = vi.fn().mockResolvedValue("sqlserver-1");
|
||||
const installAgent = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
connectDb,
|
||||
installAgent,
|
||||
isAgentInstalled: vi.fn().mockResolvedValue(false),
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
await store.connect(sqlServerLegacyConnection());
|
||||
|
||||
expect(installAgent).toHaveBeenCalledWith("sqlserver-legacy");
|
||||
expect(connectDb).toHaveBeenCalledTimes(1);
|
||||
expect(installAgent.mock.invocationCallOrder[0]).toBeLessThan(connectDb.mock.invocationCallOrder[0]);
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,7 @@ import { collapseExpandedTreeNodes } from "@/lib/sidebar/sidebarTreeCollapse";
|
||||
import { findDatabaseTreeNode } from "@/lib/sidebar/treeRefreshTarget";
|
||||
import { shouldMarkDisconnected } from "@/lib/connection/connectionHealth";
|
||||
import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connection/connectionAttemptTimeout";
|
||||
import { requiresSqlServerLegacyCompatibilityComponent, SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY } from "@/lib/connection/sqlServerLegacyCompatibility";
|
||||
import { connectionUsesVisibleSchemaFilter, filterDatabaseNamesForConnection, filterSchemaNamesForConnection, filterVisibleDatabaseNames, normalizeVisibleDatabaseSelection } from "@/lib/database/visibleDatabases";
|
||||
import {
|
||||
buildObjectGroupPlaceholderNodes,
|
||||
@@ -1625,6 +1626,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
rebuildTreeNodes();
|
||||
}
|
||||
|
||||
async function ensureSqlServerLegacyCompatibilityComponentInstalled(config: ConnectionConfig) {
|
||||
if (!requiresSqlServerLegacyCompatibilityComponent(config)) return;
|
||||
if (await api.isAgentInstalled(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY)) return;
|
||||
await api.installAgent(SQLSERVER_LEGACY_COMPATIBILITY_DRIVER_KEY);
|
||||
}
|
||||
|
||||
async function setDefaultDatabase(connectionId: string, database: string) {
|
||||
const config = getConfig(connectionId);
|
||||
if (!config || config.database === database) return;
|
||||
@@ -1771,6 +1778,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const localAttempt = beginLocalConnectionAttempt(config.id);
|
||||
try {
|
||||
await beforeConnectHandler?.(config);
|
||||
await ensureSqlServerLegacyCompatibilityComponentInstalled(config);
|
||||
ensureLocalConnectionAttemptActive(config.id, localAttempt);
|
||||
const id = await withConnectionAttemptTimeout(api.connectDb(config, localAttempt), config);
|
||||
await ensureLocalConnectionAttemptActiveAfterConnectResult(config.id, localAttempt, id);
|
||||
|
||||
Reference in new issue
Block a user