feat(connection): add dedicated ssh tunnel test button
This commit is contained in:
18 files changed
+228
-21
No files matched your search
@@ -230,7 +230,7 @@ type LegacyTransportFields = {
|
|||||||
};
|
};
|
||||||
type LegacyConnectionConfig = ConnectionConfig & LegacyTransportFields;
|
type LegacyConnectionConfig = ConnectionConfig & LegacyTransportFields;
|
||||||
type ConnectionForm = Omit<ConnectionConfig, "id">;
|
type ConnectionForm = Omit<ConnectionConfig, "id">;
|
||||||
type ConnectionTestState = ConnectionTestResult & { ok: boolean };
|
type ConnectionTestState = ConnectionTestResult & { ok: boolean; scope?: "connection" | "ssh" };
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@@ -276,6 +276,7 @@ function initialConnectionGroupId(): string | null {
|
|||||||
}
|
}
|
||||||
const tunnelProfileStore = useTunnelProfileStore();
|
const tunnelProfileStore = useTunnelProfileStore();
|
||||||
const isTesting = ref(false);
|
const isTesting = ref(false);
|
||||||
|
const isTestingSshTunnel = ref(false);
|
||||||
const isSaving = ref(false);
|
const isSaving = ref(false);
|
||||||
const testResult = ref<ConnectionTestState | null>(null);
|
const testResult = ref<ConnectionTestState | null>(null);
|
||||||
const testedConfigFingerprint = ref("");
|
const testedConfigFingerprint = ref("");
|
||||||
@@ -2651,6 +2652,7 @@ const databasePlaceholder = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const transportLayers = computed(() => form.value.transport_layers || []);
|
const transportLayers = computed(() => form.value.transport_layers || []);
|
||||||
|
const hasEnabledSshLayer = computed(() => transportLayers.value.some((layer) => layer.enabled !== false && layer.type === "ssh"));
|
||||||
const selectedTransportLayer = computed(() => {
|
const selectedTransportLayer = computed(() => {
|
||||||
const layers = transportLayers.value;
|
const layers = transportLayers.value;
|
||||||
return layers.find((layer) => layer.id === selectedTransportLayerId.value) || layers[0] || null;
|
return layers.find((layer) => layer.id === selectedTransportLayerId.value) || layers[0] || null;
|
||||||
@@ -3361,7 +3363,8 @@ const databaseInfoCompactLabel = computed(() =>
|
|||||||
);
|
);
|
||||||
const testResultMessage = computed(() => {
|
const testResultMessage = computed(() => {
|
||||||
if (!testResult.value) return "";
|
if (!testResult.value) return "";
|
||||||
return testResult.value.ok ? t("connection.testSuccess") : translateBackendError(t, testResult.value.message);
|
if (!testResult.value.ok) return translateBackendError(t, testResult.value.message);
|
||||||
|
return testResult.value.scope === "ssh" ? t("connection.sshTunnelTestSuccess") : t("connection.testSuccess");
|
||||||
});
|
});
|
||||||
const agentInstallPercent = computed(() => driverInstallProgressPercent(agentInstallProgress.value));
|
const agentInstallPercent = computed(() => driverInstallProgressPercent(agentInstallProgress.value));
|
||||||
const agentInstallProgressLabel = computed(() => {
|
const agentInstallProgressLabel = computed(() => {
|
||||||
@@ -3483,6 +3486,7 @@ watch(customDriverName, (value) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function testConnection() {
|
async function testConnection() {
|
||||||
|
if (isTestingSshTunnel.value) return;
|
||||||
if (!ensureConnectionHostResolvedFromUrl()) return;
|
if (!ensureConnectionHostResolvedFromUrl()) return;
|
||||||
|
|
||||||
const runId = ++testRunId;
|
const runId = ++testRunId;
|
||||||
@@ -3525,6 +3529,28 @@ async function testConnection() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function testSshTunnel() {
|
||||||
|
if (isTesting.value || isTestingSshTunnel.value) return;
|
||||||
|
|
||||||
|
const runId = ++testRunId;
|
||||||
|
isTestingSshTunnel.value = true;
|
||||||
|
testResult.value = null;
|
||||||
|
testResultCopied.value = false;
|
||||||
|
try {
|
||||||
|
const config = connectionConfigForSshTunnelTest(editingId.value || draftTestConnectionId.value);
|
||||||
|
const message = await api.testSshTunnel(config);
|
||||||
|
if (runId !== testRunId) return;
|
||||||
|
testResult.value = { ok: true, message, scope: "ssh" };
|
||||||
|
} catch (error) {
|
||||||
|
if (runId !== testRunId) return;
|
||||||
|
const message = errorMessage(error);
|
||||||
|
testResult.value = { ok: false, message, scope: "ssh" };
|
||||||
|
showConnectionError(message);
|
||||||
|
} finally {
|
||||||
|
if (runId === testRunId) isTestingSshTunnel.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clearEditedConnectionErrorAfterSuccessfulTest() {
|
function clearEditedConnectionErrorAfterSuccessfulTest() {
|
||||||
if (editingId.value) store.clearConnectionError(editingId.value);
|
if (editingId.value) store.clearConnectionError(editingId.value);
|
||||||
}
|
}
|
||||||
@@ -3708,6 +3734,24 @@ function generateConnectionName(): string {
|
|||||||
return `${label}_${rand}`;
|
return `${label}_${rand}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeTransportLayersForSubmit(config: LegacyConnectionConfig) {
|
||||||
|
config.transport_layers = (config.transport_layers || []).map(normalizeTransportLayer);
|
||||||
|
config.transport_layers = config.transport_layers.map((layer) => {
|
||||||
|
if (layer.type !== "ssh") return layer;
|
||||||
|
const normalized = normalizeSshTunnel(layer);
|
||||||
|
const timeout = Number(normalized.connect_timeout_secs);
|
||||||
|
normalized.connect_timeout_secs = Number.isFinite(timeout) && timeout > 0 ? timeout : 5;
|
||||||
|
return { type: "ssh", ...normalized };
|
||||||
|
});
|
||||||
|
validateTransportLayers(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectionConfigForSshTunnelTest(id: string): ConnectionConfig {
|
||||||
|
const config = { ...formValueForSubmit(), id } as LegacyConnectionConfig;
|
||||||
|
normalizeTransportLayersForSubmit(config);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
function connectionConfigForSubmit(id: string, generatedName = ""): ConnectionConfig {
|
function connectionConfigForSubmit(id: string, generatedName = ""): ConnectionConfig {
|
||||||
const config = { ...formValueForSubmit(), id } as LegacyConnectionConfig;
|
const config = { ...formValueForSubmit(), id } as LegacyConnectionConfig;
|
||||||
config.database_info = undefined;
|
config.database_info = undefined;
|
||||||
@@ -3751,18 +3795,10 @@ function connectionConfigForSubmit(id: string, generatedName = ""): ConnectionCo
|
|||||||
throw new Error(t("connection.spannerFieldsRequired"));
|
throw new Error(t("connection.spannerFieldsRequired"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.transport_layers = (config.transport_layers || []).map(normalizeTransportLayer);
|
normalizeTransportLayersForSubmit(config);
|
||||||
config.transport_layers = config.transport_layers.map((layer) => {
|
if (config.db_type === "oracle" && config.oracle_connection_type === "tns" && config.transport_layers?.some((layer) => layer.enabled !== false)) {
|
||||||
if (layer.type !== "ssh") return layer;
|
|
||||||
const normalized = normalizeSshTunnel(layer);
|
|
||||||
const timeout = Number(normalized.connect_timeout_secs);
|
|
||||||
normalized.connect_timeout_secs = Number.isFinite(timeout) && timeout > 0 ? timeout : 5;
|
|
||||||
return { type: "ssh", ...normalized };
|
|
||||||
});
|
|
||||||
if (config.db_type === "oracle" && config.oracle_connection_type === "tns" && config.transport_layers.some((layer) => layer.enabled !== false)) {
|
|
||||||
throw new Error(t("connection.oracleTnsTransportUnsupported"));
|
throw new Error(t("connection.oracleTnsTransportUnsupported"));
|
||||||
}
|
}
|
||||||
validateTransportLayers(config);
|
|
||||||
if (config.db_type === "oracle" && config.oracle_connection_type === "tns") {
|
if (config.db_type === "oracle" && config.oracle_connection_type === "tns") {
|
||||||
const alias = config.database?.trim() || "";
|
const alias = config.database?.trim() || "";
|
||||||
const tnsAdmin = normalizeOracleTnsAdminPath(oracleTnsAdminPath.value);
|
const tnsAdmin = normalizeOracleTnsAdminPath(oracleTnsAdminPath.value);
|
||||||
@@ -4364,6 +4400,7 @@ function isOracleSysUser(config: Pick<ConnectionConfig, "db_type" | "username">)
|
|||||||
function resetTestState() {
|
function resetTestState() {
|
||||||
testRunId += 1;
|
testRunId += 1;
|
||||||
isTesting.value = false;
|
isTesting.value = false;
|
||||||
|
isTestingSshTunnel.value = false;
|
||||||
testResult.value = null;
|
testResult.value = null;
|
||||||
clearTestedConnectionInfo();
|
clearTestedConnectionInfo();
|
||||||
showConnectionErrorDialog.value = false;
|
showConnectionErrorDialog.value = false;
|
||||||
@@ -8708,6 +8745,16 @@ function openExternalUrl(url: string) {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
<div v-if="hasEnabledSshLayer" class="grid grid-cols-4 items-center gap-4">
|
||||||
|
<span />
|
||||||
|
<div class="col-span-3">
|
||||||
|
<Button type="button" variant="outline" size="sm" :disabled="isTesting || isTestingSshTunnel || isSaving" @click="testSshTunnel">
|
||||||
|
<Loader2 v-if="isTestingSshTunnel" class="mr-1.5 h-3.5 w-3.5 animate-spin" />
|
||||||
|
<ShieldCheck v-else class="mr-1.5 h-3.5 w-3.5" />
|
||||||
|
{{ isTestingSshTunnel ? t("connection.sshTunnelTesting") : t("connection.sshTunnelTest") }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
@@ -8715,7 +8762,7 @@ function openExternalUrl(url: string) {
|
|||||||
|
|
||||||
<DialogFooter class="connection-dialog-footer flex min-w-0 shrink-0 items-center gap-2 sm:flex-nowrap">
|
<DialogFooter class="connection-dialog-footer flex min-w-0 shrink-0 items-center gap-2 sm:flex-nowrap">
|
||||||
<div class="connection-dialog-test-status mr-auto flex min-w-0 flex-1 basis-0 items-center gap-2 overflow-hidden">
|
<div class="connection-dialog-test-status mr-auto flex min-w-0 flex-1 basis-0 items-center gap-2 overflow-hidden">
|
||||||
<Button v-if="!editingId" variant="outline" class="shrink-0" :disabled="isSaving" @click="backToDatabasePicker">
|
<Button v-if="!editingId" variant="outline" class="shrink-0" :disabled="isSaving || isTestingSshTunnel" @click="backToDatabasePicker">
|
||||||
<ArrowLeft class="h-4 w-4" />
|
<ArrowLeft class="h-4 w-4" />
|
||||||
{{ t("connection.back") }}
|
{{ t("connection.back") }}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -8729,25 +8776,25 @@ function openExternalUrl(url: string) {
|
|||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<Button v-if="canChooseVisibleNacosNamespaces" variant="outline" class="shrink-0" :disabled="isTesting || isSaving || isLoadingVisibleNacosNamespaces || !hasRequiredConnectionTarget" @click="openVisibleNacosNamespacesPicker">
|
<Button v-if="canChooseVisibleNacosNamespaces" variant="outline" class="shrink-0" :disabled="isTesting || isTestingSshTunnel || isSaving || isLoadingVisibleNacosNamespaces || !hasRequiredConnectionTarget" @click="openVisibleNacosNamespacesPicker">
|
||||||
<Loader2 v-if="isLoadingVisibleNacosNamespaces" class="mr-1.5 h-4 w-4 animate-spin" />
|
<Loader2 v-if="isLoadingVisibleNacosNamespaces" class="mr-1.5 h-4 w-4 animate-spin" />
|
||||||
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
||||||
{{ t(nacosNamespacePickerTitleKey) }}
|
{{ t(nacosNamespacePickerTitleKey) }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button v-else-if="canChooseVisibleDatabases" variant="outline" class="shrink-0" :disabled="isTesting || isSaving || isLoadingVisibleDatabases || !hasRequiredConnectionTarget" @click="openVisibleDatabasesPicker">
|
<Button v-else-if="canChooseVisibleDatabases" variant="outline" class="shrink-0" :disabled="isTesting || isTestingSshTunnel || isSaving || isLoadingVisibleDatabases || !hasRequiredConnectionTarget" @click="openVisibleDatabasesPicker">
|
||||||
<Loader2 v-if="isLoadingVisibleDatabases" class="mr-1.5 h-4 w-4 animate-spin" />
|
<Loader2 v-if="isLoadingVisibleDatabases" class="mr-1.5 h-4 w-4 animate-spin" />
|
||||||
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
||||||
{{ hasVisibleObjectFilter ? visibleObjectSummary : visibleFilterUsesSchemas ? t("contextMenu.configureVisibleObjects") : t("contextMenu.selectVisibleDatabases") }}
|
{{ hasVisibleObjectFilter ? visibleObjectSummary : visibleFilterUsesSchemas ? t("contextMenu.configureVisibleObjects") : t("contextMenu.selectVisibleDatabases") }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button v-if="canChooseVisibleSchemas && !visibleFilterUsesSchemas && hasVisibleSchemaFilter" variant="outline" class="shrink-0" :disabled="isTesting || isSaving || isLoadingVisibleSchemas || !hasRequiredConnectionTarget" @click="openVisibleSchemasPicker">
|
<Button v-if="canChooseVisibleSchemas && !visibleFilterUsesSchemas && hasVisibleSchemaFilter" variant="outline" class="shrink-0" :disabled="isTesting || isTestingSshTunnel || isSaving || isLoadingVisibleSchemas || !hasRequiredConnectionTarget" @click="openVisibleSchemasPicker">
|
||||||
<Loader2 v-if="isLoadingVisibleSchemas" class="mr-1.5 h-4 w-4 animate-spin" />
|
<Loader2 v-if="isLoadingVisibleSchemas" class="mr-1.5 h-4 w-4 animate-spin" />
|
||||||
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
<ListFilter v-else class="mr-1.5 h-4 w-4" />
|
||||||
{{ visibleSchemaSummary }}
|
{{ visibleSchemaSummary }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="outline" class="shrink-0" :disabled="isTesting || isSaving" @click="testConnection">
|
<Button variant="outline" class="shrink-0" :disabled="isTesting || isTestingSshTunnel || isSaving" @click="testConnection">
|
||||||
{{ isTesting ? t("connection.testing") : t("connection.test") }}
|
{{ isTesting ? t("connection.testing") : t("connection.test") }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button class="shrink-0" @click="save" :disabled="isSaving || !hasRequiredConnectionTarget">
|
<Button class="shrink-0" @click="save" :disabled="isSaving || isTestingSshTunnel || !hasRequiredConnectionTarget">
|
||||||
{{ isSaving ? t("common.loading") : editingId || isJdbcConnection ? t("connection.save") : t("connection.saveAndConnect") }}
|
{{ isSaving ? t("common.loading") : editingId || isJdbcConnection ? t("connection.save") : t("connection.saveAndConnect") }}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@@ -1042,6 +1042,9 @@ export default {
|
|||||||
groupsDeleted: "{count} groups deleted",
|
groupsDeleted: "{count} groups deleted",
|
||||||
loadFailed: "Failed to load saved connections: {message}",
|
loadFailed: "Failed to load saved connections: {message}",
|
||||||
sshTunnel: "Tunnel / Proxy",
|
sshTunnel: "Tunnel / Proxy",
|
||||||
|
sshTunnelTest: "Test SSH tunnel",
|
||||||
|
sshTunnelTesting: "Testing SSH tunnel...",
|
||||||
|
sshTunnelTestSuccess: "SSH tunnel connection successful",
|
||||||
advancedTab: "Advanced",
|
advancedTab: "Advanced",
|
||||||
sshEnable: "Use tunnel / proxy",
|
sshEnable: "Use tunnel / proxy",
|
||||||
sshHost: "SSH Host",
|
sshHost: "SSH Host",
|
||||||
|
|||||||
@@ -830,6 +830,9 @@ export default withEnglishFallback({
|
|||||||
groupsDeleted: "Se eliminaron {count} grupos",
|
groupsDeleted: "Se eliminaron {count} grupos",
|
||||||
loadFailed: "Error al cargar las conexiones guardadas: {message}",
|
loadFailed: "Error al cargar las conexiones guardadas: {message}",
|
||||||
sshTunnel: "Túnel SSH / Proxy",
|
sshTunnel: "Túnel SSH / Proxy",
|
||||||
|
sshTunnelTest: "Probar túnel SSH",
|
||||||
|
sshTunnelTesting: "Probando túnel SSH...",
|
||||||
|
sshTunnelTestSuccess: "Conexión del túnel SSH correcta",
|
||||||
advancedTab: "Avanzado",
|
advancedTab: "Avanzado",
|
||||||
sshEnable: "Usar túnel SSH / proxy",
|
sshEnable: "Usar túnel SSH / proxy",
|
||||||
sshHost: "Host SSH",
|
sshHost: "Host SSH",
|
||||||
|
|||||||
@@ -828,6 +828,9 @@ export default withEnglishFallback({
|
|||||||
groupsDeleted: "Eliminati {count} gruppi",
|
groupsDeleted: "Eliminati {count} gruppi",
|
||||||
loadFailed: "Impossibile caricare le connessioni salvate: {message}",
|
loadFailed: "Impossibile caricare le connessioni salvate: {message}",
|
||||||
sshTunnel: "Tunnel SSH / Proxy",
|
sshTunnel: "Tunnel SSH / Proxy",
|
||||||
|
sshTunnelTest: "Testa tunnel SSH",
|
||||||
|
sshTunnelTesting: "Test tunnel SSH in corso...",
|
||||||
|
sshTunnelTestSuccess: "Connessione al tunnel SSH riuscita",
|
||||||
advancedTab: "Avanzate",
|
advancedTab: "Avanzate",
|
||||||
sshEnable: "Usa tunnel SSH / proxy",
|
sshEnable: "Usa tunnel SSH / proxy",
|
||||||
sshHost: "Host SSH",
|
sshHost: "Host SSH",
|
||||||
|
|||||||
@@ -794,6 +794,9 @@ export default withEnglishFallback({
|
|||||||
groupsDeleted: "{count} 個のグループを削除しました",
|
groupsDeleted: "{count} 個のグループを削除しました",
|
||||||
loadFailed: "保存された接続の読み込みに失敗しました: {message}",
|
loadFailed: "保存された接続の読み込みに失敗しました: {message}",
|
||||||
sshTunnel: "SSHトンネル / プロキシ",
|
sshTunnel: "SSHトンネル / プロキシ",
|
||||||
|
sshTunnelTest: "SSH トンネルをテスト",
|
||||||
|
sshTunnelTesting: "SSH トンネルをテスト中...",
|
||||||
|
sshTunnelTestSuccess: "SSH トンネル接続に成功しました",
|
||||||
advancedTab: "詳細",
|
advancedTab: "詳細",
|
||||||
sshEnable: "SSHトンネル/プロキシを使用する",
|
sshEnable: "SSHトンネル/プロキシを使用する",
|
||||||
sshHost: "SSHホスト",
|
sshHost: "SSHホスト",
|
||||||
|
|||||||
@@ -934,6 +934,9 @@ export default withEnglishFallback({
|
|||||||
groupsDeleted: "그룹 {count}개를 삭제했습니다",
|
groupsDeleted: "그룹 {count}개를 삭제했습니다",
|
||||||
loadFailed: "저장된 연결을 불러오는 데 실패했습니다: {message}",
|
loadFailed: "저장된 연결을 불러오는 데 실패했습니다: {message}",
|
||||||
sshTunnel: "터널 / 프록시",
|
sshTunnel: "터널 / 프록시",
|
||||||
|
sshTunnelTest: "SSH 터널 테스트",
|
||||||
|
sshTunnelTesting: "SSH 터널 테스트 중...",
|
||||||
|
sshTunnelTestSuccess: "SSH 터널 연결 성공",
|
||||||
advancedTab: "고급",
|
advancedTab: "고급",
|
||||||
sshEnable: "터널 / 프록시 사용",
|
sshEnable: "터널 / 프록시 사용",
|
||||||
sshHost: "SSH 호스트",
|
sshHost: "SSH 호스트",
|
||||||
|
|||||||
@@ -829,6 +829,9 @@ export default withEnglishFallback({
|
|||||||
groupsDeleted: "{count} grupos excluídos",
|
groupsDeleted: "{count} grupos excluídos",
|
||||||
loadFailed: "Falha ao carregar as conexões salvas: {message}",
|
loadFailed: "Falha ao carregar as conexões salvas: {message}",
|
||||||
sshTunnel: "Túnel SSH / Proxy",
|
sshTunnel: "Túnel SSH / Proxy",
|
||||||
|
sshTunnelTest: "Testar túnel SSH",
|
||||||
|
sshTunnelTesting: "Testando túnel SSH...",
|
||||||
|
sshTunnelTestSuccess: "Conexão do túnel SSH bem-sucedida",
|
||||||
advancedTab: "Avançado",
|
advancedTab: "Avançado",
|
||||||
sshEnable: "Usar túnel SSH / proxy",
|
sshEnable: "Usar túnel SSH / proxy",
|
||||||
sshHost: "Host SSH",
|
sshHost: "Host SSH",
|
||||||
|
|||||||
@@ -969,6 +969,9 @@ export default withEnglishFallback({
|
|||||||
groupsDeleted: "已删除 {count} 个分组",
|
groupsDeleted: "已删除 {count} 个分组",
|
||||||
loadFailed: "加载已保存连接失败:{message}",
|
loadFailed: "加载已保存连接失败:{message}",
|
||||||
sshTunnel: "隧道/代理",
|
sshTunnel: "隧道/代理",
|
||||||
|
sshTunnelTest: "测试 SSH 隧道",
|
||||||
|
sshTunnelTesting: "正在测试 SSH 隧道...",
|
||||||
|
sshTunnelTestSuccess: "SSH 隧道连接成功",
|
||||||
advancedTab: "高级",
|
advancedTab: "高级",
|
||||||
sshEnable: "使用隧道/代理连接",
|
sshEnable: "使用隧道/代理连接",
|
||||||
sshHost: "SSH 主机",
|
sshHost: "SSH 主机",
|
||||||
|
|||||||
@@ -828,6 +828,9 @@ export default withEnglishFallback({
|
|||||||
groupsDeleted: "已刪除 {count} 個群組",
|
groupsDeleted: "已刪除 {count} 個群組",
|
||||||
loadFailed: "載入已儲存連線失敗:{message}",
|
loadFailed: "載入已儲存連線失敗:{message}",
|
||||||
sshTunnel: "SSH 隧道/代理",
|
sshTunnel: "SSH 隧道/代理",
|
||||||
|
sshTunnelTest: "測試 SSH 隧道",
|
||||||
|
sshTunnelTesting: "正在測試 SSH 隧道...",
|
||||||
|
sshTunnelTestSuccess: "SSH 隧道連線成功",
|
||||||
advancedTab: "進階",
|
advancedTab: "進階",
|
||||||
sshEnable: "使用 SSH 隧道/代理連線",
|
sshEnable: "使用 SSH 隧道/代理連線",
|
||||||
sshHost: "SSH 主機",
|
sshHost: "SSH 主機",
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
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("ConnectionDialog SSH tunnel test", () => {
|
||||||
|
it("exposes a dedicated SSH tunnel test without running the database test", () => {
|
||||||
|
expect(dialogSource).toContain("async function testSshTunnel()");
|
||||||
|
expect(dialogSource).toContain("await api.testSshTunnel(config)");
|
||||||
|
expect(dialogSource).toContain('@click="testSshTunnel"');
|
||||||
|
expect(dialogSource).toContain('t("connection.sshTunnelTest")');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("builds the tunnel probe config without database-specific validation", () => {
|
||||||
|
const start = dialogSource.indexOf("function connectionConfigForSshTunnelTest");
|
||||||
|
const end = dialogSource.indexOf("function connectionConfigForSubmit", start);
|
||||||
|
const helperSource = dialogSource.slice(start, end);
|
||||||
|
|
||||||
|
expect(start).toBeGreaterThan(-1);
|
||||||
|
expect(end).toBeGreaterThan(start);
|
||||||
|
expect(helperSource).toContain("normalizeTransportLayersForSubmit(config)");
|
||||||
|
expect(helperSource).not.toContain("kingbaseDatabaseRequired");
|
||||||
|
expect(helperSource).not.toContain("dynamodbCredentialsRequired");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -52,6 +52,7 @@ function forward<K extends keyof Backend>(name: K): Backend[K] {
|
|||||||
|
|
||||||
// Connection
|
// Connection
|
||||||
export const testConnection = forward("testConnection");
|
export const testConnection = forward("testConnection");
|
||||||
|
export const testSshTunnel = forward("testSshTunnel");
|
||||||
export const testConnectionWithInfo = forward("testConnectionWithInfo");
|
export const testConnectionWithInfo = forward("testConnectionWithInfo");
|
||||||
export const connectDb = forward("connectDb");
|
export const connectDb = forward("connectDb");
|
||||||
export const connectionDatabaseInfo = forward("connectionDatabaseInfo");
|
export const connectionDatabaseInfo = forward("connectionDatabaseInfo");
|
||||||
|
|||||||
@@ -374,6 +374,10 @@ export async function testConnection(config: ConnectionConfig): Promise<string>
|
|||||||
return post("/api/connection/test", { config });
|
return post("/api/connection/test", { config });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function testSshTunnel(config: ConnectionConfig): Promise<string> {
|
||||||
|
return post("/api/connection/test-ssh-tunnel", { config });
|
||||||
|
}
|
||||||
|
|
||||||
export async function testConnectionWithInfo(config: ConnectionConfig): Promise<ConnectionTestResult> {
|
export async function testConnectionWithInfo(config: ConnectionConfig): Promise<ConnectionTestResult> {
|
||||||
const response = await fetch(apiUrl("/api/connection/test-info"), {
|
const response = await fetch(apiUrl("/api/connection/test-info"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -1068,6 +1068,10 @@ export async function testConnection(config: ConnectionConfig): Promise<string>
|
|||||||
return invokeBackend("test_connection", { config });
|
return invokeBackend("test_connection", { config });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function testSshTunnel(config: ConnectionConfig): Promise<string> {
|
||||||
|
return invokeBackend("test_ssh_tunnel", { config });
|
||||||
|
}
|
||||||
|
|
||||||
export async function testConnectionWithInfo(config: ConnectionConfig): Promise<ConnectionTestResult> {
|
export async function testConnectionWithInfo(config: ConnectionConfig): Promise<ConnectionTestResult> {
|
||||||
try {
|
try {
|
||||||
const result = await invoke<unknown>("test_connection_with_info", {
|
const result = await invoke<unknown>("test_connection_with_info", {
|
||||||
|
|||||||
@@ -306,6 +306,13 @@ pub struct AppState {
|
|||||||
pub mq_registry: crate::mq::MqAdminRegistry,
|
pub mq_registry: crate::mq::MqAdminRegistry,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn transport_layers_through_last_ssh(layers: &[TransportLayerConfig]) -> Result<&[TransportLayerConfig], String> {
|
||||||
|
let Some(last_ssh_index) = layers.iter().rposition(|layer| matches!(layer, TransportLayerConfig::Ssh(_))) else {
|
||||||
|
return Err("Connection has no enabled SSH tunnel layer".to_string());
|
||||||
|
};
|
||||||
|
Ok(&layers[..=last_ssh_index])
|
||||||
|
}
|
||||||
|
|
||||||
/// 活跃时间以进程内单调时钟的相对毫秒存储(AtomicU64):热路径每条查询都要
|
/// 活跃时间以进程内单调时钟的相对毫秒存储(AtomicU64):热路径每条查询都要
|
||||||
/// 更新它,读锁 + 原子写让并发查询不再在全局写锁上串行化。
|
/// 更新它,读锁 + 原子写让并发查询不再在全局写锁上串行化。
|
||||||
/// 基准偏移让测试能构造"过去"的时间点(否则进程刚启动时相对毫秒接近 0)。
|
/// 基准偏移让测试能构造"过去"的时间点(否则进程刚启动时相对毫秒接近 0)。
|
||||||
@@ -2829,6 +2836,34 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tests the enabled SSH chain without opening a database connection.
|
||||||
|
/// Layers before the final SSH hop are included because they may be
|
||||||
|
/// required to reach that hop; layers after it are unrelated to SSH auth.
|
||||||
|
pub async fn test_connection_ssh_tunnel(&self, config: &ConnectionConfig) -> Result<String, String> {
|
||||||
|
let resolved_layers = self.resolved_transport_layers(config).await?;
|
||||||
|
let test_layers = transport_layers_through_last_ssh(&resolved_layers)?;
|
||||||
|
let probe_id = format!("__connection_ssh_test__:{}", uuid::Uuid::new_v4());
|
||||||
|
let result = db::transport_layer_tunnel::start_transport_layers(
|
||||||
|
&probe_id,
|
||||||
|
test_layers,
|
||||||
|
"127.0.0.1",
|
||||||
|
1,
|
||||||
|
&self.tunnels,
|
||||||
|
&self.proxy_tunnels,
|
||||||
|
&self.http_tunnels,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
db::transport_layer_tunnel::stop_transport_layers(
|
||||||
|
&probe_id,
|
||||||
|
test_layers.len(),
|
||||||
|
&self.tunnels,
|
||||||
|
&self.proxy_tunnels,
|
||||||
|
&self.http_tunnels,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
result.map(|_| "SSH tunnel connection successful".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn connection_host_port(
|
pub async fn connection_host_port(
|
||||||
&self,
|
&self,
|
||||||
connection_id: &str,
|
connection_id: &str,
|
||||||
@@ -5890,9 +5925,9 @@ mod tests {
|
|||||||
mysql_pool_setup_queries, oceanbase_mysql_setup_queries, prestosql_jdbc_config_for_endpoint,
|
mysql_pool_setup_queries, oceanbase_mysql_setup_queries, prestosql_jdbc_config_for_endpoint,
|
||||||
redacted_connection_url_for_endpoint, redis_sentinel_transport_id, redis_sentinel_transport_prefix,
|
redacted_connection_url_for_endpoint, redis_sentinel_transport_id, redis_sentinel_transport_prefix,
|
||||||
sqlserver_legacy_agent_config, sqlserver_legacy_driver_error, sqlserver_uses_legacy_driver,
|
sqlserver_legacy_agent_config, sqlserver_legacy_driver_error, sqlserver_uses_legacy_driver,
|
||||||
task_client_session_id, upsert_connection_url_param, uses_bare_mysql_pool, uses_tcp_probe,
|
task_client_session_id, transport_layers_through_last_ssh, upsert_connection_url_param, uses_bare_mysql_pool,
|
||||||
validate_connection_url_params, validate_h2_database_path, AppState, MysqlMode, PoolKind, TxnConnection,
|
uses_tcp_probe, validate_connection_url_params, validate_h2_database_path, AppState, MysqlMode, PoolKind,
|
||||||
GAUSSDB_M_JDBC_DRIVER_CLASS, GAUSSDB_M_JDBC_DRIVER_PROFILE, PRESTOSQL_JDBC_DRIVER_CLASS,
|
TxnConnection, GAUSSDB_M_JDBC_DRIVER_CLASS, GAUSSDB_M_JDBC_DRIVER_PROFILE, PRESTOSQL_JDBC_DRIVER_CLASS,
|
||||||
};
|
};
|
||||||
use crate::agent_connection::{
|
use crate::agent_connection::{
|
||||||
agent_connect_params, mongo_legacy_error_with_auth_hint, mongo_uses_legacy_driver,
|
agent_connect_params, mongo_legacy_error_with_auth_hint, mongo_uses_legacy_driver,
|
||||||
@@ -6928,6 +6963,59 @@ mod tests {
|
|||||||
let _ = std::fs::remove_dir_all(dir);
|
let _ = std::fs::remove_dir_all(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ssh_tunnel_test_includes_prerequisites_through_final_ssh_hop() {
|
||||||
|
let before = TransportLayerConfig::Proxy(ProxyTunnelConfig {
|
||||||
|
id: "before".to_string(),
|
||||||
|
name: String::new(),
|
||||||
|
enabled: true,
|
||||||
|
proxy_type: ProxyType::Socks5,
|
||||||
|
host: "proxy.internal".to_string(),
|
||||||
|
port: 1080,
|
||||||
|
username: String::new(),
|
||||||
|
password: String::new(),
|
||||||
|
test_target: None,
|
||||||
|
profile_id: String::new(),
|
||||||
|
});
|
||||||
|
let ssh = TransportLayerConfig::Ssh(ssh_layer("ssh", ""));
|
||||||
|
let after = TransportLayerConfig::Proxy(ProxyTunnelConfig {
|
||||||
|
id: "after".to_string(),
|
||||||
|
name: String::new(),
|
||||||
|
enabled: true,
|
||||||
|
proxy_type: ProxyType::Http,
|
||||||
|
host: "downstream.internal".to_string(),
|
||||||
|
port: 8080,
|
||||||
|
username: String::new(),
|
||||||
|
password: String::new(),
|
||||||
|
test_target: None,
|
||||||
|
profile_id: String::new(),
|
||||||
|
});
|
||||||
|
let layers = vec![before.clone(), ssh.clone(), after];
|
||||||
|
|
||||||
|
assert_eq!(transport_layers_through_last_ssh(&layers).unwrap(), &[before, ssh]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ssh_tunnel_test_rejects_chain_without_ssh() {
|
||||||
|
let layers = vec![TransportLayerConfig::Proxy(ProxyTunnelConfig {
|
||||||
|
id: "proxy".to_string(),
|
||||||
|
name: String::new(),
|
||||||
|
enabled: true,
|
||||||
|
proxy_type: ProxyType::Socks5,
|
||||||
|
host: "proxy.internal".to_string(),
|
||||||
|
port: 1080,
|
||||||
|
username: String::new(),
|
||||||
|
password: String::new(),
|
||||||
|
test_target: None,
|
||||||
|
profile_id: String::new(),
|
||||||
|
})];
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
transport_layers_through_last_ssh(&layers).unwrap_err(),
|
||||||
|
"Connection has no enabled SSH tunnel layer"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_tunnel_profile_rejects_non_ssh_and_missing_host() {
|
async fn test_tunnel_profile_rejects_non_ssh_and_missing_host() {
|
||||||
let (state, dir) = test_app_state().await;
|
let (state, dir) = test_app_state().await;
|
||||||
|
|||||||
@@ -379,6 +379,7 @@ async fn main() {
|
|||||||
// Connection
|
// Connection
|
||||||
.route("/connection/test", post(routes::connection::test_connection))
|
.route("/connection/test", post(routes::connection::test_connection))
|
||||||
.route("/connection/test-info", post(routes::connection::test_connection_with_info))
|
.route("/connection/test-info", post(routes::connection::test_connection_with_info))
|
||||||
|
.route("/connection/test-ssh-tunnel", post(routes::connection::test_ssh_tunnel))
|
||||||
.route("/connection/connect", post(routes::connection::connect_db))
|
.route("/connection/connect", post(routes::connection::connect_db))
|
||||||
.route("/connection/database-info", post(routes::connection::connected_database_info))
|
.route("/connection/database-info", post(routes::connection::connected_database_info))
|
||||||
.route("/connection/database-info/save", post(routes::connection::save_connection_database_info))
|
.route("/connection/database-info/save", post(routes::connection::save_connection_database_info))
|
||||||
|
|||||||
@@ -373,6 +373,13 @@ pub async fn test_connection_with_info(
|
|||||||
run_temporary_connection_test(&state.app, body.config, true).await.map(Json).map_err(AppError::from)
|
run_temporary_connection_test(&state.app, body.config, true).await.map(Json).map_err(AppError::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn test_ssh_tunnel(
|
||||||
|
State(state): State<Arc<WebState>>,
|
||||||
|
Json(body): Json<ConnectRequest>,
|
||||||
|
) -> Result<Json<String>, AppError> {
|
||||||
|
state.app.test_connection_ssh_tunnel(&body.config.canonicalized()).await.map(Json).map_err(AppError::from)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn connect_db(
|
pub async fn connect_db(
|
||||||
State(state): State<Arc<WebState>>,
|
State(state): State<Arc<WebState>>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
|
|||||||
@@ -1112,6 +1112,11 @@ pub async fn test_connection_with_info(
|
|||||||
test_connection_with_info_inner(state.inner(), config).await
|
test_connection_with_info_inner(state.inner(), config).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn test_ssh_tunnel(state: State<'_, Arc<AppState>>, config: ConnectionConfig) -> Result<String, String> {
|
||||||
|
state.test_connection_ssh_tunnel(&config.canonicalized()).await
|
||||||
|
}
|
||||||
|
|
||||||
async fn test_connection_with_info_inner(
|
async fn test_connection_with_info_inner(
|
||||||
state: &Arc<AppState>,
|
state: &Arc<AppState>,
|
||||||
config: ConnectionConfig,
|
config: ConnectionConfig,
|
||||||
|
|||||||
@@ -1794,6 +1794,7 @@ pub fn run() {
|
|||||||
commands::cloud_sync::snippet_sync_download,
|
commands::cloud_sync::snippet_sync_download,
|
||||||
commands::connection::test_connection,
|
commands::connection::test_connection,
|
||||||
commands::connection::test_connection_with_info,
|
commands::connection::test_connection_with_info,
|
||||||
|
commands::connection::test_ssh_tunnel,
|
||||||
commands::connection::connect_db,
|
commands::connection::connect_db,
|
||||||
commands::connection::connection_final_proxy_port,
|
commands::connection::connection_final_proxy_port,
|
||||||
commands::connection::disconnect_db,
|
commands::connection::disconnect_db,
|
||||||
|
|||||||
Reference in new issue
Block a user