дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
The General tab of a named database preset lists its built-in driver and the local JDBC profiles associated with that preset, so a local driver no longer requires switching the type to Custom JDBC; the type and tree icon stay. Manage Drivers and Go to Driver open the profile manager scoped to that type. A connection refuses a profile associated with another preset, and a JDBC password is kept apart from a Snowflake key-pair passphrase when switching transports. Closes #4564 Co-authored-by: principalwater <[email protected]>
85 рядки
3.7 KiB
TypeScript
85 рядки
3.7 KiB
TypeScript
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { SourceDialog } from "./SourceDialog";
|
|
|
|
const ipc = vi.hoisted(() => ({ call: vi.fn() }));
|
|
vi.mock("@/platform/ipc", async (importOriginal) => {
|
|
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
|
// The commands `call` receives must not reach Tauri's invoke, which jsdom lacks.
|
|
const request =
|
|
(name: string) =>
|
|
(...args: unknown[]) => [name, ...args];
|
|
return {
|
|
...real,
|
|
call: ipc.call,
|
|
commands: {
|
|
...real.commands,
|
|
dbJdbcDrivers: request("dbJdbcDrivers"),
|
|
dbTest: request("dbTest"),
|
|
dbTestTunnel: request("dbTestTunnel"),
|
|
},
|
|
};
|
|
});
|
|
|
|
const savePassword = () => screen.getByRole("checkbox", { name: "Save password" }) as HTMLInputElement;
|
|
|
|
ipc.call.mockResolvedValue([]);
|
|
|
|
describe("new data source", () => {
|
|
it("does not save the database password unless asked to", () => {
|
|
render(<SourceDialog initial={null} />);
|
|
expect(savePassword().checked).toBe(false);
|
|
});
|
|
|
|
it("does not save the SSH tunnel password unless asked to", () => {
|
|
render(<SourceDialog initial={null} />);
|
|
fireEvent.click(screen.getByRole("tab", { name: "SSH/SSL" }));
|
|
fireEvent.click(screen.getByRole("checkbox", { name: "Use SSH tunnel" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "SSH authentication type" }));
|
|
fireEvent.click(within(screen.getByRole("listbox")).getByText("Password"));
|
|
expect(savePassword().checked).toBe(false);
|
|
});
|
|
|
|
it("names the secret of a Snowflake source after its authentication method", () => {
|
|
render(
|
|
<SourceDialog
|
|
initial={null}
|
|
preset={{
|
|
driver: "snowflake",
|
|
host: "",
|
|
snowflake: { warehouse: "", role: "", auth: "keyPair", privateKeyFile: "" },
|
|
}}
|
|
/>,
|
|
);
|
|
expect(screen.getByText("Account:")).toBeTruthy();
|
|
expect(screen.queryByRole("tab", { name: "SSH/SSL" })).toBeNull();
|
|
expect(screen.getByLabelText("Private key:")).toBeTruthy();
|
|
expect((screen.getByLabelText("Passphrase:") as HTMLInputElement).type).toBe("password");
|
|
expect(savePassword().checked).toBe(false);
|
|
fireEvent.click(screen.getByRole("button", { name: "Snowflake authentication" }));
|
|
fireEvent.click(within(screen.getByRole("listbox")).getByText("Password"));
|
|
expect(screen.queryByLabelText("Private key:")).toBeNull();
|
|
expect((screen.getByLabelText("Password:") as HTMLInputElement).type).toBe("password");
|
|
for (const field of ["Schema:", "Warehouse:", "Role:"]) expect(screen.getByLabelText(field)).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe("Test SSH Tunnel", () => {
|
|
it("tests the tunnel typed in the SSH/SSL tab, without the database login", async () => {
|
|
ipc.call.mockImplementation(async ([op]) => (op === "dbTestTunnel" ? "dev@bastion:22 reaches 127.0.0.1:5432" : []));
|
|
render(<SourceDialog initial={null} preset={{ driver: "postgres", host: "127.0.0.1" }} />);
|
|
fireEvent.click(screen.getByRole("tab", { name: "SSH/SSL" }));
|
|
const button = () => screen.getByRole("button", { name: "Test SSH Tunnel" }) as HTMLButtonElement;
|
|
expect(button().disabled).toBe(true);
|
|
fireEvent.click(screen.getByRole("checkbox", { name: "Use SSH tunnel" }));
|
|
expect(button().disabled).toBe(true);
|
|
fireEvent.change(screen.getByLabelText("Host:", { selector: "#db-ssh-host" }), { target: { value: "bastion" } });
|
|
fireEvent.click(button());
|
|
await waitFor(() =>
|
|
expect(screen.getByRole("status").textContent).toBe("SSH tunnel works: dev@bastion:22 reaches 127.0.0.1:5432"),
|
|
);
|
|
expect(ipc.call).toHaveBeenCalledWith(["dbTestTunnel", expect.anything(), null]);
|
|
ipc.call.mockClear();
|
|
});
|
|
});
|