Initial commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { quoteShell, remote } from "../src/ssh.js";
|
||||
|
||||
test("shell quoting preserves literal input", () => {
|
||||
for (const value of ["", "hello", "a'b", "$(echo unsafe);\n*", "こんにちは"]) {
|
||||
assert.equal(execFileSync("sh", ["-c", `printf %s ${quoteShell(value)}`], { encoding: "utf8" }), value);
|
||||
}
|
||||
});
|
||||
|
||||
test("rejects option-like SSH destinations", () => {
|
||||
assert.throws(() => remote("-oProxyCommand=bad", "true"));
|
||||
assert.throws(() => remote("home extra", "true"));
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
import tempfile
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
spec = importlib.util.spec_from_file_location("desktop", Path(__file__).parents[1] / "vm/desktop.py")
|
||||
desktop = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(desktop)
|
||||
|
||||
|
||||
class ValidationTests(unittest.TestCase):
|
||||
def test_session_save(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
state = Path(directory)
|
||||
with patch.object(desktop, "STATE", state):
|
||||
desktop.save_session({"DISPLAY": ":0"})
|
||||
desktop.save_session({"DISPLAY": ":1"})
|
||||
path = state / "session.json"
|
||||
self.assertEqual(json.loads(path.read_text()), {"DISPLAY": ":1"})
|
||||
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
|
||||
self.assertEqual(len(list(state.iterdir())), 1)
|
||||
|
||||
def test_autostart(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
with patch.object(Path, "home", return_value=Path(directory)):
|
||||
desktop.install_autostart()
|
||||
desktop.install_autostart()
|
||||
entries = list((Path(directory) / ".config/autostart").iterdir())
|
||||
self.assertEqual(len(entries), 1)
|
||||
self.assertIn("--register-session\n", entries[0].read_text())
|
||||
self.assertIn("OnlyShowIn=XFCE;", entries[0].read_text())
|
||||
|
||||
def test_capture(self):
|
||||
self.assertEqual(desktop.validate({"actions": []}, 100, 100), [])
|
||||
|
||||
def test_bounds(self):
|
||||
for x in (-1, 100, True, "2"):
|
||||
with self.assertRaises(ValueError):
|
||||
desktop.validate({"actions": [{"type": "click", "x": x, "y": 0}]}, 100, 100)
|
||||
|
||||
def test_invalid_keys(self):
|
||||
with self.assertRaises(ValueError):
|
||||
desktop.validate({"actions": [{"type": "keys", "keys": ["--repeat"]}]}, 100, 100)
|
||||
|
||||
def test_wait_budget(self):
|
||||
with self.assertRaises(ValueError):
|
||||
desktop.validate({"actions": [{"type": "wait", "milliseconds": 3000}] * 2}, 100, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user