-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathgit-ssh-url.test.ts
More file actions
91 lines (81 loc) · 2.63 KB
/
Copy pathgit-ssh-url.test.ts
File metadata and controls
91 lines (81 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { describe, expect, it } from "vitest";
import { parseGitUrl } from "../src/utils/git.ts";
describe("Git URL Parsing", () => {
describe("protocol URLs (accepted without git: prefix)", () => {
it("should parse HTTPS URL", () => {
const result = parseGitUrl("https://github.com/user/repo");
expect(result).toMatchObject({
host: "github.com",
path: "user/repo",
repo: "https://github.com/user/repo",
});
});
it("should parse ssh:// URL", () => {
const result = parseGitUrl("ssh://git@github.com/user/repo");
expect(result).toMatchObject({
host: "github.com",
path: "user/repo",
repo: "ssh://git@github.com/user/repo",
});
});
it("should parse protocol URL with ref", () => {
const result = parseGitUrl("https://github.com/user/repo@v1.0.0");
expect(result).toMatchObject({
host: "github.com",
path: "user/repo",
ref: "v1.0.0",
repo: "https://github.com/user/repo",
});
});
});
describe("shorthand URLs (accepted only with git: prefix)", () => {
it("should parse git@host:path with git: prefix", () => {
const result = parseGitUrl("git:git@github.com:user/repo");
expect(result).toMatchObject({
host: "github.com",
path: "user/repo",
repo: "git@github.com:user/repo",
});
});
it("should parse host/path shorthand with git: prefix", () => {
const result = parseGitUrl("git:github.com/user/repo");
expect(result).toMatchObject({
host: "github.com",
path: "user/repo",
repo: "https://github.com/user/repo",
});
});
it("should parse shorthand with ref and git: prefix", () => {
const result = parseGitUrl("git:git@github.com:user/repo@v1.0.0");
expect(result).toMatchObject({
host: "github.com",
path: "user/repo",
ref: "v1.0.0",
repo: "git@github.com:user/repo",
});
});
});
it("should reject unsafe git install path inputs", () => {
for (const source of [
"git:git@evil.example:../../victim/repo",
"https://evil.example/..%2F..%2Fvictim/repo",
"https://evil.example/..%2F..%2Fvictim/repo%",
"git:git@evil.example:/absolute/repo",
"git:git@evil.example:user\\repo/name",
"git:git@evil.example:user/repo\0name",
]) {
expect(parseGitUrl(source)).toBeNull();
}
});
describe("unsupported without git: prefix", () => {
it("should reject git@host:path without git: prefix", () => {
expect(parseGitUrl("git@github.com:user/repo")).toBeNull();
});
it("should reject host/path shorthand without git: prefix", () => {
expect(parseGitUrl("github.com/user/repo")).toBeNull();
});
it("should reject user/repo shorthand", () => {
expect(parseGitUrl("user/repo")).toBeNull();
});
});
});