Skip to content

Commit 969e2a5

Browse files
committed
fix(shared): separate clone URL credentials at the final at sign
Consume SSH and HTTPS userinfo through the last @ in the authority and exclude @ from hostname captures. Preserve Azure mapping, path encoding, same-protocol URLs, and custom-port restrictions. Cover raw and encoded credentials, multiple @ characters, missing hosts, path @ characters, and Azure clone-service HTTPS fallback. The new tests reproduce five shared failures and one service failure on the prior PR head; all 22 shared and 19 service tests pass with the fix. Written and verified by OpenAI GPT-6 (Codex harness in ChatGPT Work).
1 parent 18fe6cf commit 969e2a5

3 files changed

Lines changed: 65 additions & 5 deletions

File tree

‎apps/server/src/sourceControl/SourceControlRepositoryService.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,19 @@ it.effect("reports both failures when the HTTPS retry fails too", () =>
321321
}),
322322
);
323323

324-
it.effect("retries an Azure SSH clone using its HTTPS host and repository path", () =>
324+
it.effect.each([
325+
"[email protected]:v3/Fabrikam/Project1/fab_repo",
326+
"ssh://user:pa@[email protected]/v3/Fabrikam/Project1/fab_repo",
327+
"ssh://us%40er:pa%[email protected]/v3/Fabrikam/Project1/fab_repo",
328+
])("retries Azure SSH URL %s using its HTTPS host and repository path", (remoteUrl) =>
325329
Effect.gen(function* () {
326330
const urls: Array<string> = [];
327331
const result = yield* cloneInTemporaryDirectory(rejectingSsh(urls, false), {
328-
remoteUrl: "[email protected]:v3/Fabrikam/Project1/fab_repo",
332+
remoteUrl,
329333
});
330334

331335
assert.deepStrictEqual(urls, [
332-
"[email protected]:v3/Fabrikam/Project1/fab_repo",
336+
remoteUrl,
333337
"https://dev.azure.com/Fabrikam/Project1/_git/fab_repo",
334338
]);
335339
assert.strictEqual(result.remoteUrl, "https://dev.azure.com/Fabrikam/Project1/_git/fab_repo");

‎packages/shared/src/cloneUrl.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,61 @@ import { describe, expect, it } from "vite-plus/test";
33
import { cloneUrlForProtocol, cloneUrlProtocol } from "./cloneUrl.ts";
44

55
describe("cloneUrlForProtocol", () => {
6+
it.each([
7+
["ordinary", "user:password"],
8+
["an embedded at sign", "user:pa@rt"],
9+
["multiple at signs", "user:pa@rt@word"],
10+
["encoded", "us%40er:pa%40ss%3Aword"],
11+
])("separates Azure hosts from credentials (%s)", (_label, userinfo) => {
12+
const https = `https://${userinfo}@dev.azure.com/org/Project%20One/_git/repo%40name`;
13+
const ssh = `ssh://${userinfo}@ssh.dev.azure.com/v3/org/Project%20One/repo%40name`;
14+
expect(cloneUrlProtocol(https)).toBe("https");
15+
expect(cloneUrlProtocol(ssh)).toBe("ssh");
16+
expect(cloneUrlForProtocol(https, "ssh")).toBe(
17+
"[email protected]:v3/org/Project%20One/repo%40name",
18+
);
19+
expect(cloneUrlForProtocol(ssh, "https")).toBe(
20+
"https://dev.azure.com/org/Project%20One/_git/repo%40name",
21+
);
22+
expect(cloneUrlForProtocol(https, "https")).toBe(https);
23+
expect(cloneUrlForProtocol(ssh, "ssh")).toBe(ssh);
24+
});
25+
26+
it.each([
27+
["https", "ssh", "dev.azure.com", "org/project/_git/repo"],
28+
["ssh", "https", "ssh.dev.azure.com", "v3/org/project/repo"],
29+
["https", "ssh", "host.example", "org/repo.git"],
30+
["ssh", "https", "host.example", "org/repo.git"],
31+
] as const)(
32+
"refuses credential-bearing %s URLs with custom ports on %s switches",
33+
(from, to, host, path) => {
34+
const url = `${from}://user:pa@rt@${host}:8443/${path}`;
35+
expect(cloneUrlForProtocol(url, to)).toBeNull();
36+
expect(cloneUrlForProtocol(url, from)).toBe(url);
37+
},
38+
);
39+
40+
it("drops all userinfo on generic hosts without consuming at signs in paths", () => {
41+
expect(cloneUrlForProtocol("https://user:pa@[email protected]/org/[email protected]", "ssh")).toBe(
42+
43+
);
44+
expect(cloneUrlForProtocol("ssh://user:pa@[email protected]/org/[email protected]", "https")).toBe(
45+
"https://github.com/org/[email protected]",
46+
);
47+
expect(cloneUrlForProtocol("https://github.com/org/[email protected]", "ssh")).toBe(
48+
49+
);
50+
});
51+
52+
it.each(["https://user:pa@rt@/org/repo", "ssh://user:pa@rt@/org/repo"])(
53+
"refuses a credential-bearing URL without a hostname (%s)",
54+
(url) => {
55+
expect(cloneUrlProtocol(url)).toBeNull();
56+
expect(cloneUrlForProtocol(url, "ssh")).toBeNull();
57+
expect(cloneUrlForProtocol(url, "https")).toBeNull();
58+
},
59+
);
60+
661
it.each([
762
"[email protected]:v3/Fabrikam/Project1/fab_repo",
863
"ssh://[email protected]/v3/Fabrikam/Project1/fab_repo",

‎packages/shared/src/cloneUrl.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export type CloneProtocol = "ssh" | "https";
22

33
const SCP_LIKE_URL = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/)(.+)$/;
4-
const SSH_URL = /^ssh:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;
5-
const HTTPS_URL = /^https?:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;
4+
// Userinfo may contain `@`; the last one before the first slash separates the host.
5+
const SSH_URL = /^ssh:\/\/(?:[^/\s]*@)?([^@:/\s]+)(:\d+)?\/(.+)$/;
6+
const HTTPS_URL = /^https?:\/\/(?:[^/\s]*@)?([^@:/\s]+)(:\d+)?\/(.+)$/;
67

78
function parseCloneUrl(
89
url: string,

0 commit comments

Comments
 (0)