| f532c426 Andy McCall ↶ |
1 |
import { test } from "node:test"; |
| 2 |
import assert from "node:assert/strict"; |
| 19639205 Andy McCall ↶ |
3 |
import { parsePlanQuery, parseResolveQuery, sameRemote } from "../out/handoff.mjs"; |
| f532c426 Andy McCall ↶ |
4 |
|
| 5 |
test("resolve links are read and checked", () => { |
| 6 |
const q = new URLSearchParams({ url: "https://hub.example:7343/andy/demo", bookmark: "feature/x", path: "src/a.txt" }).toString(); |
| 7 |
assert.deepEqual(parseResolveQuery(q), { url: "https://hub.example:7343/andy/demo", bookmark: "feature/x", path: "src/a.txt" }); |
| 8 |
assert.match(parseResolveQuery("bookmark=main&path=a"), /no repository URL/); |
| 9 |
assert.match(parseResolveQuery("url=https://h/r&bookmark=a..b&path=a"), /no valid bookmark/); |
| 10 |
assert.match(parseResolveQuery("url=https://h/r&bookmark=main&path=../etc/passwd"), /no valid path/); |
| 11 |
assert.match(parseResolveQuery("url=https://h/r&bookmark=main&path=.oxy/config"), /no valid path/); |
| 12 |
}); |
| 13 |
|
| 14 |
test("remotes match across a trailing slash and the host's case", () => { |
| 15 |
assert.ok(sameRemote("https://Hub.Example:7343/andy/demo/", "https://hub.example:7343/andy/demo")); |
| 16 |
assert.ok(!sameRemote("https://hub.example:7343/andy/demo", "https://hub.example:7343/andy/other")); |
| 17 |
assert.ok(!sameRemote("https://hub.example:7343/andy/demo", "http://hub.example:7343/andy/demo")); |
| 19639205 Andy McCall ↶ |
18 |
}); |
| 19 |
|
| 20 |
test("plan links are read and checked", () => { |
| 21 |
const c = "a".repeat(64), t = "b".repeat(64); |
| 22 |
const q = new URLSearchParams({ url: "https://hub.example:7343/andy/demo", bookmark: "feature", kind: "squash", change: c, target: t }).toString(); |
| 23 |
assert.deepEqual(parsePlanQuery(q), { url: "https://hub.example:7343/andy/demo", bookmark: "feature", kind: "squash", change: c, target: t }); |
| 24 |
assert.match(parsePlanQuery(q.replace("squash", "reorder")), /no squash or rebase/); |
| 25 |
assert.match(parsePlanQuery(q.replace(t, c)), /no two changes/); |
| 26 |
assert.match(parsePlanQuery(q.replace(c, "abc")), /no two changes/); |
| 27 |
assert.match(parsePlanQuery(q.replace("feature", "a..b")), /no valid bookmark/); |
| f532c426 Andy McCall ↶ |
28 |
}); |