mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 15:15:24 +00:00
* feat: let the login page send the token back to the mobile app * feat: add host-scripts entry to the plugin sdk * feat: let plugins say how they show in the mobile app * feat: frame host for running one plugin view outside the shell * fix: build the SDK host modules in production mode * chore: note the SDK host build fix in the changelog * feat: list plugin engine ranges for the mobile app * feat: host color and icon columns that sync * chore: update translations and plugin pins * fix: test * fix: show source address when rejecting proxy auth * fix: deleting your own account removes all of its data * fix(deps): update body-parser to 2.4.0 (#1736) * fix: body-parser 보안 패치 반영 * chore: 자동 검사를 막던 기존 JSON 서식 정리 --------- Co-authored-by: renovys <180682734+renovys@users.noreply.github.com> * fix(sdk): decode command output as GBK when it is not valid UTF-8 (#1735) * fix: honor shared credentials on shared hosts (#1730) * fix: honor shared credentials on shared hosts and in personal SSH auth * fix: snapshot shared SSH auth from a credential shared with the host owner * fix: size DataView list columns by the table's own width (#1713) * fix: size DataView list columns by the table's own width The list grid was built from every column, so columns hidden below md/lg left empty tracks and the visible cells landed under the wrong headers. Each width now gets a template of only its visible columns (CSS variables + container queries on the table, so a narrow panel counts, not the window), the header uses the same gap as the rows, and rows use a minimum height so wrapped cells no longer overlap. * test: wait for the title bar offset effect before asserting The bar shows once getTitleBarVisible resolves, but --termix-titlebar-height is set in a later passive effect, so reading it right after findByText raced (3-5 of 40 runs under load, on main too). * chore: rerun CI against dev-26.10.6 * fix: unlock passphrase keys once per connect burst (#1737) * feat: give ssh transports the host origin and sync id (#1717) * fix: wake other clients after a sync push (Plugin-Sync#1) * feat: look up local row ids by sync id for the sync plugin (Plugin-Sync#4) * feat: rail items can show a status dot (Plugin-Sync#5) * fix: add the desktop shared copy banner text (#1709) * feat: sidebar preference for alternating rows (#1712) * fix: striped rows text * feat: shell can open a saved host's editor for plugins (Plugin-SSH-Terminal#36) * fix: show the logo in the macos menu bar (#1728) * fix: number shortcuts skip the home tab (#1724) * fix: show plugins that could not be downloaded as failed (#1714) * fix: pass the host id as text when opening its editor * fix: retry a plugin bundle that was not ready yet (#1708) * fix: let commonjs plugins fall back to core packages on the desktop * fix: let non docker installs switch nginx to https (#1711) * feat: remove a folder share from its hosts too (#1719) * chore: changelog for merged pull requests * fix: accept the release .sig when installing a plugin from a file * feat: folder logins for shared hosts, read only plugin sync, full desktop builds * fix: test * fix: stop dev runner restart loops and narrow plugin watchers * chore: update translations and plugin pins * chore: lint, format, and bump version to 26.10.6 --------- Co-authored-by: renovys <renovy@gmail.com> Co-authored-by: renovys <180682734+renovys@users.noreply.github.com> Co-authored-by: Sebastian Cao <cycsmail@gmail.com> Co-authored-by: Jonathan Rehuel Lewerissa <jonathan.rehuel16@gmail.com> Co-authored-by: Rhiz3K <33246262+Rhiz3K@users.noreply.github.com>
131 lines
4.0 KiB
TypeScript
131 lines
4.0 KiB
TypeScript
import { execFileSync } from "node:child_process";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
actionScript,
|
|
errLine,
|
|
isActiveScript,
|
|
listUnitsScript,
|
|
openRcActionScript,
|
|
parseKeys,
|
|
passwordSudoScript,
|
|
scriptError,
|
|
scriptShell,
|
|
SUDO_REFUSED_RE,
|
|
SUDO_WRONG_RE,
|
|
toBase64,
|
|
utf8Decode,
|
|
utf8Encode,
|
|
watchdog,
|
|
} from "@termix-ssh/plugin-sdk/host-scripts";
|
|
|
|
describe("text helpers", () => {
|
|
it("encodes base64 like Buffer does", () => {
|
|
for (const text of [
|
|
"",
|
|
"a",
|
|
"ab",
|
|
"abc",
|
|
"héllo wörld",
|
|
"emoji 🙂 here",
|
|
"line\nbreak",
|
|
]) {
|
|
expect(toBase64(text)).toBe(Buffer.from(text, "utf8").toString("base64"));
|
|
}
|
|
});
|
|
|
|
it("round trips UTF-8 and replaces bad bytes", () => {
|
|
const text = "plain, ünïcode, 日本, 🙂";
|
|
expect(utf8Decode(utf8Encode(text))).toBe(text);
|
|
expect(Array.from(utf8Encode(text))).toEqual(
|
|
Array.from(Buffer.from(text, "utf8")),
|
|
);
|
|
expect(utf8Decode([0x61, 0xff, 0x62])).toBe("a\ufffdb");
|
|
expect(utf8Decode([0xe6, 0x97])).toBe("\ufffd");
|
|
});
|
|
|
|
it("reads key=value lines", () => {
|
|
expect(parseKeys("a=1\nb = two=2\njunk\n")).toEqual({ a: "1", b: "two=2" });
|
|
});
|
|
});
|
|
|
|
describe("script shells", () => {
|
|
it("always reads the script from stdin", () => {
|
|
for (const mode of ["plain", "auto", "root"] as const) {
|
|
expect(scriptShell(mode)).toContain("bash -s");
|
|
}
|
|
expect(scriptShell("auto")).toContain("sudo -n true");
|
|
expect(scriptShell("root-only")).toContain("SCRIPT_ERR:");
|
|
});
|
|
|
|
it("collects error lines, old and new markers", () => {
|
|
expect(scriptError("x\nSCRIPT_ERR:one\nSERVICES_ERR:two\n")).toBe(
|
|
"one\ntwo",
|
|
);
|
|
expect(errLine("it's broken")).toBe(`echo 'SCRIPT_ERR:it'\\''s broken'`);
|
|
});
|
|
|
|
it("matches sudo refusals", () => {
|
|
expect(SUDO_REFUSED_RE.test("sudo: a password is required")).toBe(true);
|
|
expect(SUDO_WRONG_RE.test("sudo: 1 incorrect password attempt")).toBe(true);
|
|
});
|
|
|
|
it("keeps the sudo password out of the command line", () => {
|
|
const { command, stdin } = passwordSudoScript(
|
|
"systemctl restart 'a.service'\n",
|
|
"s3cr'et $(id)",
|
|
);
|
|
expect(command).not.toContain("s3cr");
|
|
expect(stdin.split("\n")[0]).toBe("IFS= read -r TERMIX_PW");
|
|
expect(stdin.split("\n")[1]).toBe("s3cr'et $(id)");
|
|
expect(stdin).toContain("sudo -k -S -p ''");
|
|
expect(stdin).not.toContain("systemctl restart");
|
|
expect(() => passwordSudoScript("x", "a\nb")).toThrow();
|
|
});
|
|
|
|
it.runIf(process.platform !== "win32")(
|
|
"runs the script and never runs the password",
|
|
() => {
|
|
const { stdin } = passwordSudoScript(
|
|
'echo "ran:$1${TERMIX_PW:-none}"\n',
|
|
"touch /tmp/should-not-exist",
|
|
);
|
|
// No sudo here: swap it for a fake that drops its own stdin line.
|
|
const fake = stdin.replace(
|
|
/printf '%s\\n' "\$P" \| sudo -k -S -p '' env PATH="\$PATH" [^\n]* bash -c "\$TERMIX_S"/,
|
|
'printf "%s\\n" "$P" | { IFS= read -r _; bash -c "$TERMIX_S"; }',
|
|
);
|
|
expect(fake).not.toBe(stdin);
|
|
const out = execFileSync(
|
|
"bash",
|
|
["-c", "sudo() { return 1; }; export -f sudo; exec bash -s"],
|
|
{
|
|
input: fake,
|
|
encoding: "utf8",
|
|
},
|
|
);
|
|
expect(out.trim()).toBe("ran:none");
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("unit scripts", () => {
|
|
it("quotes units and refuses bad names", () => {
|
|
expect(actionScript("a.service", "enable-now")).toContain(
|
|
"systemctl enable --now -- 'a.service'",
|
|
);
|
|
expect(() => actionScript("a;b.service", "start")).toThrow();
|
|
expect(isActiveScript(["a.service", "b.timer"])).toContain(
|
|
"-- 'a.service' 'b.timer'",
|
|
);
|
|
expect(() => listUnitsScript("bogus" as never)).toThrow();
|
|
expect(openRcActionScript("sshd", "enable")).toContain(
|
|
"rc-update add 'sshd' default",
|
|
);
|
|
expect(() => openRcActionScript("sshd", "mask")).toThrow();
|
|
});
|
|
|
|
it("stops a watched command once stdin closes", () => {
|
|
expect(watchdog("journalctl -f")).toContain("cat >/dev/null");
|
|
});
|
|
});
|