main
ts 85 lines 3.46 KB
Raw
1 import * as assert from "assert";
2
3 import {
4 buildCommand,
5 resolveTunnelInstallerURL,
6 validateRelayUrl,
7 } from "../command";
8
9 suite("Extension Test Suite", () => {
10 test("validateRelayUrl accepts only https URLs", () => {
11 assert.strictEqual(validateRelayUrl("https://relay.example.com"), undefined);
12 assert.strictEqual(validateRelayUrl("http://relay.example.com"), "Portal relay URLs must use https://");
13 assert.strictEqual(validateRelayUrl("not-a-url"), "Enter a valid https:// URL");
14 });
15
16 test("resolveTunnelInstallerURL maps supported platforms to release installers", () => {
17 assert.strictEqual(
18 resolveTunnelInstallerURL("darwin", "x64"),
19 "https://github.com/gosuda/portal-tunnel/releases/latest/download/install.sh"
20 );
21 assert.strictEqual(
22 resolveTunnelInstallerURL("win32", "arm64"),
23 "https://github.com/gosuda/portal-tunnel/releases/latest/download/install.ps1"
24 );
25 assert.strictEqual(resolveTunnelInstallerURL("linux", "ia32"), undefined);
26 assert.strictEqual(resolveTunnelInstallerURL("freebsd", "x64"), undefined);
27 });
28
29 test("buildCommand omits --name when empty and runs the unix release installer", () => {
30 const command = buildCommand({
31 host: "localhost:3000",
32 name: "",
33 relayList: "https://relay.example.com",
34 thumbnail: "",
35 tunnelInstallerURL: "https://github.com/gosuda/portal-tunnel/releases/latest/download/install.sh",
36 }, {
37 shellTarget: "unix",
38 platform: "linux",
39 arch: "x64",
40 });
41
42 assert.match(command, /curl -fsSL https:\/\/github\.com\/gosuda\/portal\/releases\/latest\/download\/install\.sh -o "\$PORTAL_INSTALLER"/);
43 assert.match(command, /sh "\$PORTAL_INSTALLER"/);
44 assert.match(command, /PORTAL_BIN="\$\(command -v portal 2>\/dev\/null \|\| true\)"/);
45 assert.match(command, /"\$PORTAL_BIN" expose localhost:3000 --relays https:\/\/relay\.example\.com/);
46 assert.ok(!command.includes("--name"));
47 });
48
49 test("buildCommand can use the default public registry without --relays", () => {
50 const command = buildCommand({
51 host: "localhost:3000",
52 name: "",
53 relayList: "",
54 thumbnail: "",
55 tunnelInstallerURL: "https://github.com/gosuda/portal-tunnel/releases/latest/download/install.sh",
56 }, {
57 shellTarget: "unix",
58 platform: "linux",
59 arch: "x64",
60 });
61
62 assert.match(command, /curl -fsSL https:\/\/github\.com\/gosuda\/portal\/releases\/latest\/download\/install\.sh -o "\$PORTAL_INSTALLER"/);
63 assert.ok(!command.includes("--relays"));
64 assert.ok(!command.includes("--name"));
65 assert.match(command, /"\$PORTAL_BIN" expose localhost:3000/);
66 });
67
68 test("buildCommand runs the PowerShell release installer on windows", () => {
69 const command = buildCommand({
70 host: "localhost:3000",
71 name: "my-app",
72 relayList: "https://relay.example.com",
73 thumbnail: "https://example.com/thumb.png",
74 tunnelInstallerURL: "https://github.com/gosuda/portal-tunnel/releases/latest/download/install.ps1",
75 }, {
76 shellTarget: "windows",
77 platform: "win32",
78 arch: "x64",
79 });
80
81 assert.match(command, /irm https:\/\/github\.com\/gosuda\/portal\/releases\/latest\/download\/install\.ps1 \| iex/);
82 assert.match(command, /\$PortalBin = Join-Path \$env:LOCALAPPDATA 'portal\\bin\\portal\.exe'/);
83 assert.match(command, /& \$PortalBin expose localhost:3000 --name my-app --relays https:\/\/relay\.example\.com --thumbnail https:\/\/example\.com\/thumb\.png/);
84 });
85 });