Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

2.5 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { redactConnectionStringSecrets } from "@/lib/connection/connectionStringRedaction";

describe("shared connection string redaction", () => {
  it.each([
    ["oceanbase://admin@tenant@cluster:synthetic%40secret@[2001:db8::1]:2881/app?password=another-secret", "oceanbase://admin@tenant@cluster:***@[2001:db8::1]:2881/app?password=***"],
    ["OCEANBASE://admin@tenant:[email protected]:2881/app", "OCEANBASE://admin@tenant:***@db.example.com:2881/app"],
    ["oceanbase://admin@tenant:p@ss;secret@[2001:db8::1]:2881/app", "oceanbase://admin@tenant:***@[2001:db8::1]:2881/app"],
    ["oceanbase://admin@[email protected]:2881/app", "oceanbase://admin@[email protected]:2881/app"],
    ["redis://:[email protected]:6379/0", "redis://:***@cache.example.com:6379/0"],
    ["jdbc:mysql://db.example.com/app?pass%77ord=synthetic-secret&connectTimeout=5000", "jdbc:mysql://db.example.com/app?pass%77ord=***&connectTimeout=5000"],
    ["postgresql://db.example.com/app?sslpassword=key-secret&oauth_client_secret=client-secret", "postgresql://db.example.com/app?sslpassword=***&oauth_client_secret=***"],
    ["jdbc:sqlserver://db.example.com;password={head;tail};encrypt=true", "jdbc:sqlserver://db.example.com;password=***;encrypt=true"],
    ["postgresql://db.example.com/app?passcode=synthetic-secret&role=analyst", "postgresql://db.example.com/app?passcode=***&role=analyst"],
    ["postgresql://db.example.com/app?apikey=synthetic-secret", "postgresql://db.example.com/app?apikey=***"],
    ["postgresql://db.example.com/app?api_key=synthetic-secret", "postgresql://db.example.com/app?api_key=***"],
    ["postgresql://db.example.com/app?api%5Fkey=synthetic-secret", "postgresql://db.example.com/app?api%5Fkey=***"],
    ["postgresql://db.example.com/app?access_token=synthetic-secret", "postgresql://db.example.com/app?access_token=***"],
    ["postgresql://db.example.com/app?client_secret=synthetic-secret", "postgresql://db.example.com/app?client_secret=***"],
    ["postgresql://db.example.com/app?passphrase=synthetic-secret", "postgresql://db.example.com/app?passphrase=***"],
  ])("removes credentials from %s", (connectionString, expected) => {
    expect(redactConnectionStringSecrets(connectionString)).toBe(expected);
  });

  it("leaves unrelated and malformed-escaped non-secret parameters unchanged", () => {
    const url = "postgresql://db.example.com/app?application%ZZ=visible&sslmode=require";
    expect(redactConnectionStringSecrets(url)).toBe(url);
  });
});