🌐 AI搜索 & 代理 主页
Skip to content

Commit 4a6066b

Browse files
author
Nik Samokhvalov
committed
fix(cli): require connection details for init
- Do not treat PGPASSWORD alone as a valid connection - Add regression test for missing connection
1 parent 935c5d8 commit 4a6066b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cli/lib/init.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ export function resolveAdminConnection(opts: {
189189
const conn = (opts.conn || "").trim();
190190
const dbUrlFlag = (opts.dbUrlFlag || "").trim();
191191

192-
const hasPsqlParts =
193-
!!(opts.host || opts.port || opts.username || opts.dbname || opts.adminPassword || opts.envPassword);
192+
// NOTE: passwords alone (PGPASSWORD / --admin-password) do NOT constitute a connection.
193+
// We require at least some connection addressing (host/port/user/db) if no positional arg / --db-url is provided.
194+
const hasConnDetails = !!(opts.host || opts.port || opts.username || opts.dbname);
194195

195196
if (conn && dbUrlFlag) {
196197
throw new Error("Provide either positional connection string or --db-url, not both");
@@ -207,7 +208,7 @@ export function resolveAdminConnection(opts: {
207208
return { clientConfig: cfg, display: describePgConfig(cfg) };
208209
}
209210

210-
if (!hasPsqlParts) {
211+
if (!hasConnDetails) {
211212
throw new Error(
212213
[
213214
"Connection is required.",

cli/test/init.test.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ test("resolveAdminConnection rejects invalid psql-like port", () => {
9191
);
9292
});
9393

94+
test("resolveAdminConnection rejects when only PGPASSWORD is provided (no connection details)", () => {
95+
assert.throws(() => init.resolveAdminConnection({ envPassword: "pw" }), /Connection is required/);
96+
});
97+
9498
test("print-sql redaction regex matches password literal with embedded quotes", async () => {
9599
const plan = await init.buildInitPlan({
96100
database: "mydb",

0 commit comments

Comments
 (0)