Skip to content

Commit bdf84df

Browse files
MarcoDotIOclaudemaria-rcks
authored
fix(cli): auth pairing create rejects a --base-url without http(s):// (pingdotgg#23343)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent efb940d commit bdf84df

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

‎apps/server/src/cli/auth.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
55
import * as Option from "effect/Option";
66
import * as References from "effect/References";
7+
import * as Schema from "effect/Schema";
78
import { Argument, Command, Flag, GlobalFlag } from "effect/cli";
89

910
import * as EnvironmentAuth from "../auth/EnvironmentAuth.ts";
@@ -68,6 +69,15 @@ const subjectFlag = Flag.String("subject").pipe(
6869
);
6970

7071
const baseUrlFlag = Flag.String("base-url").pipe(
72+
Flag.withSchema(
73+
Schema.URLFromString.pipe(
74+
Schema.check(
75+
Schema.makeFilter((url) => url.protocol === "http:" || url.protocol === "https:", {
76+
expected: "an http:// or https:// URL",
77+
}),
78+
),
79+
),
80+
),
7181
Flag.withDescription("Optional public base URL used to print a ready `/pair#token=...` link."),
7282
Flag.optional,
7383
);
@@ -99,7 +109,7 @@ const pairingCreateCommand = Command.make("create", {
99109
});
100110
const output = formatIssuedPairingCredential(issued, {
101111
json: flags.json,
102-
...(Option.isSome(flags.baseUrl) ? { baseUrl: flags.baseUrl.value } : {}),
112+
...(Option.isSome(flags.baseUrl) ? { baseUrl: flags.baseUrl.value.href } : {}),
103113
});
104114
yield* Console.log(output);
105115
}),

‎apps/server/src/cli/pair.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,63 @@ describe("auth scope options", () => {
488488
}),
489489
);
490490
});
491+
492+
describe("auth pairing create --base-url", () => {
493+
it.effect.each(["192.168.1.5:3773", "localhost:3773", "ftp://localhost:3773"])(
494+
"rejects %s before issuing a token",
495+
(baseUrl) =>
496+
Effect.gen(function* () {
497+
const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-cli-base-url-test-"));
498+
const error = yield* runCli([
499+
"auth",
500+
"pairing",
501+
"create",
502+
"--base-dir",
503+
baseDir,
504+
"--base-url",
505+
baseUrl,
506+
]).pipe(Effect.provide(layerCliRuntime), Effect.flip);
507+
508+
if (!CliError.isCliError(error) || error._tag !== "ShowHelp") {
509+
assert.fail(`Expected ShowHelp, got ${String(error)}`);
510+
}
511+
const flagError = error.errors[0];
512+
if (flagError?._tag !== "InvalidValue") {
513+
assert.fail(`Expected InvalidValue, got ${String(flagError?._tag)}`);
514+
}
515+
assert.equal(flagError.option, "base-url");
516+
assert.equal(flagError.value, baseUrl);
517+
518+
const listOutput = yield* captureStdout(
519+
runCli(["auth", "pairing", "list", "--base-dir", baseDir, "--json"]),
520+
);
521+
assert.deepEqual(JSON.parse(listOutput), []);
522+
}),
523+
);
524+
525+
it.effect.each(["http://192.168.1.5:3773", "https://example.com", "http:localhost:3773"])(
526+
"prints a pair URL for %s",
527+
(baseUrl) =>
528+
Effect.gen(function* () {
529+
const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-cli-base-url-test-"));
530+
const output = yield* captureStdout(
531+
runCli([
532+
"auth",
533+
"pairing",
534+
"create",
535+
"--base-dir",
536+
baseDir,
537+
"--base-url",
538+
baseUrl,
539+
"--json",
540+
]),
541+
);
542+
const issued = JSON.parse(output) as {
543+
readonly credential: string;
544+
readonly pairUrl: string;
545+
};
546+
547+
assert.equal(issued.pairUrl, `${new URL(baseUrl).origin}/pair#token=${issued.credential}`);
548+
}),
549+
);
550+
});

0 commit comments

Comments
 (0)