@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +2411 -2
- package/box/Dockerfile +69 -0
- package/box/agentrun-archil +168 -0
- package/box/build-daytona.py +26 -0
- package/box/build-e2b.mjs +32 -0
- package/box/build-modal.py +17 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +139 -0
- package/dist/browser.d.ts +151 -0
- package/dist/browser.js +305 -0
- package/dist/browserbase.d.ts +139 -0
- package/dist/browserbase.js +408 -0
- package/dist/child.d.ts +40 -0
- package/dist/child.js +127 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +136 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/archil.d.ts +68 -0
- package/dist/conformance/archil.js +152 -0
- package/dist/conformance/browserbase.d.ts +35 -0
- package/dist/conformance/browserbase.js +45 -0
- package/dist/conformance/cases/apps.d.ts +2 -0
- package/dist/conformance/cases/apps.js +155 -0
- package/dist/conformance/cases/browser.d.ts +4 -0
- package/dist/conformance/cases/browser.js +105 -0
- package/dist/conformance/cases/drift.d.ts +2 -0
- package/dist/conformance/cases/drift.js +64 -0
- package/dist/conformance/cases/exec.d.ts +2 -0
- package/dist/conformance/cases/exec.js +125 -0
- package/dist/conformance/cases/files.d.ts +2 -0
- package/dist/conformance/cases/files.js +294 -0
- package/dist/conformance/cases/health.d.ts +2 -0
- package/dist/conformance/cases/health.js +71 -0
- package/dist/conformance/cases/index.d.ts +9 -0
- package/dist/conformance/cases/index.js +37 -0
- package/dist/conformance/cases/input.d.ts +12 -0
- package/dist/conformance/cases/input.js +109 -0
- package/dist/conformance/cases/isolation.d.ts +21 -0
- package/dist/conformance/cases/isolation.js +98 -0
- package/dist/conformance/cases/lifetime.d.ts +2 -0
- package/dist/conformance/cases/lifetime.js +64 -0
- package/dist/conformance/cases/mount.d.ts +2 -0
- package/dist/conformance/cases/mount.js +252 -0
- package/dist/conformance/cases/process.d.ts +2 -0
- package/dist/conformance/cases/process.js +240 -0
- package/dist/conformance/cases/provider.d.ts +2 -0
- package/dist/conformance/cases/provider.js +302 -0
- package/dist/conformance/cases/screen.d.ts +9 -0
- package/dist/conformance/cases/screen.js +230 -0
- package/dist/conformance/cases/settings.d.ts +57 -0
- package/dist/conformance/cases/settings.js +142 -0
- package/dist/conformance/cases/touch.d.ts +2 -0
- package/dist/conformance/cases/touch.js +117 -0
- package/dist/conformance/cases/util.d.ts +7 -0
- package/dist/conformance/cases/util.js +8 -0
- package/dist/conformance/cdp.d.ts +13 -0
- package/dist/conformance/cdp.js +88 -0
- package/dist/conformance/cli.d.ts +29 -0
- package/dist/conformance/cli.js +231 -0
- package/dist/conformance/daytona-sweep.d.ts +18 -0
- package/dist/conformance/daytona-sweep.js +126 -0
- package/dist/conformance/daytona.d.ts +83 -0
- package/dist/conformance/daytona.js +107 -0
- package/dist/conformance/docker.d.ts +38 -0
- package/dist/conformance/docker.js +70 -0
- package/dist/conformance/drift-daemon.d.ts +8 -0
- package/dist/conformance/drift-daemon.js +41 -0
- package/dist/conformance/e2b-diagnose.d.ts +16 -0
- package/dist/conformance/e2b-diagnose.js +61 -0
- package/dist/conformance/e2b-sweep.d.ts +18 -0
- package/dist/conformance/e2b-sweep.js +132 -0
- package/dist/conformance/e2b.d.ts +74 -0
- package/dist/conformance/e2b.js +111 -0
- package/dist/conformance/fixture.d.ts +65 -0
- package/dist/conformance/fixture.js +98 -0
- package/dist/conformance/index.d.ts +8 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/kernel.d.ts +31 -0
- package/dist/conformance/kernel.js +40 -0
- package/dist/conformance/kind.d.ts +23 -0
- package/dist/conformance/kind.js +58 -0
- package/dist/conformance/modal-sweep.d.ts +22 -0
- package/dist/conformance/modal-sweep.js +213 -0
- package/dist/conformance/modal.d.ts +69 -0
- package/dist/conformance/modal.js +76 -0
- package/dist/conformance/orgo.d.ts +41 -0
- package/dist/conformance/orgo.js +69 -0
- package/dist/conformance/phone-harness.d.ts +61 -0
- package/dist/conformance/phone-harness.js +241 -0
- package/dist/conformance/png.d.ts +16 -0
- package/dist/conformance/png.js +132 -0
- package/dist/conformance/report.d.ts +2 -0
- package/dist/conformance/report.js +86 -0
- package/dist/conformance/runner.d.ts +11 -0
- package/dist/conformance/runner.js +585 -0
- package/dist/conformance/tar.d.ts +13 -0
- package/dist/conformance/tar.js +105 -0
- package/dist/conformance/types.d.ts +257 -0
- package/dist/conformance/types.js +24 -0
- package/dist/daemon-copy.d.ts +40 -0
- package/dist/daemon-copy.js +259 -0
- package/dist/daytona.d.ts +180 -0
- package/dist/daytona.js +1498 -0
- package/dist/desktop.d.ts +24 -0
- package/dist/desktop.js +68 -0
- package/dist/docker/egress-main.d.ts +1 -0
- package/dist/docker/egress-main.js +68 -0
- package/dist/docker/egress-proxy.d.ts +53 -0
- package/dist/docker/egress-proxy.js +450 -0
- package/dist/docker/egress-table.d.ts +39 -0
- package/dist/docker/egress-table.js +197 -0
- package/dist/docker/egress.d.ts +109 -0
- package/dist/docker/egress.js +318 -0
- package/dist/docker/image.d.ts +49 -0
- package/dist/docker/image.js +302 -0
- package/dist/docker/stage.d.ts +21 -0
- package/dist/docker/stage.js +290 -0
- package/dist/docker/volume.d.ts +24 -0
- package/dist/docker/volume.js +67 -0
- package/dist/docker.d.ts +156 -0
- package/dist/docker.js +1277 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +337 -0
- package/dist/e2b.js +1516 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +24 -0
- package/dist/files.d.ts +50 -0
- package/dist/files.js +208 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/isolation.d.ts +29 -0
- package/dist/isolation.js +71 -0
- package/dist/janitor.d.ts +50 -0
- package/dist/janitor.js +135 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.js +358 -0
- package/dist/kinds.d.ts +79 -0
- package/dist/kinds.js +133 -0
- package/dist/labels.d.ts +23 -0
- package/dist/labels.js +50 -0
- package/dist/modal.d.ts +302 -0
- package/dist/modal.js +1374 -0
- package/dist/mount-archil.d.ts +164 -0
- package/dist/mount-archil.js +471 -0
- package/dist/mount.d.ts +57 -0
- package/dist/mount.js +104 -0
- package/dist/orgo-channel.d.ts +96 -0
- package/dist/orgo-channel.js +391 -0
- package/dist/orgo.d.ts +139 -0
- package/dist/orgo.js +1006 -0
- package/dist/phone-harness.d.ts +185 -0
- package/dist/phone-harness.js +1420 -0
- package/dist/processes.d.ts +24 -0
- package/dist/processes.js +40 -0
- package/dist/protocol.d.ts +729 -0
- package/dist/protocol.js +54 -0
- package/dist/provider.d.ts +245 -0
- package/dist/provider.js +37 -0
- package/dist/providers.d.ts +68 -0
- package/dist/providers.js +25 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +2 -0
- package/dist/screen-watch.d.ts +150 -0
- package/dist/screen-watch.js +490 -0
- package/dist/test-connection.d.ts +17 -0
- package/dist/test-connection.js +26 -0
- package/dist/wait.d.ts +23 -0
- package/dist/wait.js +65 -0
- package/package.json +62 -4
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { healthCases } from "./health.js";
|
|
2
|
+
const PAGE = '<title>agentrun conformance</title><p id="x">42</p>';
|
|
3
|
+
const DATA_URL = `data:text/html,${encodeURIComponent(PAGE)}`;
|
|
4
|
+
const READ = 'document.title + " " + document.getElementById("x").textContent';
|
|
5
|
+
const EXPECTED = "agentrun conformance 42";
|
|
6
|
+
const refOf = ({ id, name }) => ({ id, name });
|
|
7
|
+
/** promise, or a failure naming what did not come within ms: a bound, never a claim about speed. */
|
|
8
|
+
async function bounded(promise, ms, what) {
|
|
9
|
+
let timer;
|
|
10
|
+
try {
|
|
11
|
+
return await Promise.race([promise, new Promise((_, reject) => (timer = setTimeout(() => reject(new Error(`${what} did not come within ${ms / 1000} s`)), ms)))]);
|
|
12
|
+
}
|
|
13
|
+
finally {
|
|
14
|
+
clearTimeout(timer);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** The browser's CDP URL, from a connection of the case's own; a secret, never put in an assertion's words. */
|
|
18
|
+
async function cdpUrl(t, ref) {
|
|
19
|
+
const connection = await t.connect(ref);
|
|
20
|
+
const url = connection.cdp?.url;
|
|
21
|
+
t.assert(typeof url === "string" && /^wss?:\/\//.test(url), "connect gives cdp.url, a ws:// or wss:// URL");
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
/** Fails the case when text carries the secret, without saying the secret. */
|
|
25
|
+
const noSecret = (t, text, secret, what) => t.assert(!text.includes(secret), `${what} carries the CDP URL`);
|
|
26
|
+
const browser = (name, run, extra = {}) => ({ id: `browser.${name}`, level: "core", group: "browser", needs: [], run, ...extra });
|
|
27
|
+
export const browserOnlyCases = [
|
|
28
|
+
browser("check-refuses", async (t) => {
|
|
29
|
+
const { maxLifetimeMs } = t.provider.capabilities();
|
|
30
|
+
t.deepEqual(t.provider.check(t.spec()), [], "check of the run's own spec");
|
|
31
|
+
const past = t.spec({ lifetimeMs: maxLifetimeMs + 1 });
|
|
32
|
+
const refusals = t.provider.check(past);
|
|
33
|
+
t.assert(refusals.some((r) => r.field === "lifetimeMs"), `check refuses lifetimeMs ${maxLifetimeMs + 1}, past maxLifetimeMs`);
|
|
34
|
+
const error = t.refused(await t.attempt(past), "create past maxLifetimeMs", ["refused"]);
|
|
35
|
+
t.assert(refusals.some(({ message }) => error.message.includes(message)), `create's refusal names what check() refused (${refusals.map((r) => r.message).join("; ")}), not: ${error.message}`);
|
|
36
|
+
}, { computer: "none" }),
|
|
37
|
+
browser("labels", async (t) => {
|
|
38
|
+
const byId = t.ok(await t.provider.attach({ id: t.ref.id }), "attach by id");
|
|
39
|
+
t.deepEqual(refOf(byId), refOf(t.ref), "attach by id finds the run's browser");
|
|
40
|
+
t.equal(byId.spec.kind, "browser", "attach reads the computer back as a browser");
|
|
41
|
+
const byLabels = t.ok(await t.provider.attach({ labels: t.runLabels }), `attach by labels ${JSON.stringify(t.runLabels)}`);
|
|
42
|
+
t.deepEqual(refOf(byLabels), refOf(t.ref), "attach by the run's labels finds the run's browser");
|
|
43
|
+
const listed = t.ok(await t.provider.list(t.runLabels), "list");
|
|
44
|
+
t.deepEqual(listed.map((info) => refOf(info.ref)), [refOf(t.ref)], "list by the run's labels: the run's browser alone");
|
|
45
|
+
const [info] = listed;
|
|
46
|
+
t.equal(info?.state, "running", "the listed browser's state");
|
|
47
|
+
for (const [key, value] of Object.entries(t.runLabels))
|
|
48
|
+
t.equal(info?.labels[key], value, `the listed browser's label ${key}, read back from the vendor`);
|
|
49
|
+
}),
|
|
50
|
+
browser("cdp", async (t) => {
|
|
51
|
+
t.equal(t.hello.kind, "browser", "hello's kind");
|
|
52
|
+
t.assert(t.hello.groups.includes("cdp"), "hello declares cdp");
|
|
53
|
+
const cdp = await t.cdp(await cdpUrl(t));
|
|
54
|
+
const version = await cdp.send("Browser.getVersion");
|
|
55
|
+
t.assert(typeof version.product === "string" && version.product !== "", `Browser.getVersion names a product, not ${JSON.stringify(version.product)}`);
|
|
56
|
+
const { targetId } = await cdp.send("Target.createTarget", { url: "about:blank" });
|
|
57
|
+
try {
|
|
58
|
+
const { sessionId } = await cdp.send("Target.attachToTarget", { targetId, flatten: true });
|
|
59
|
+
await cdp.send("Page.enable", {}, sessionId);
|
|
60
|
+
// Asked before the navigate, so a load that comes before navigate's answer is not missed.
|
|
61
|
+
const loaded = cdp.event("Page.loadEventFired", sessionId);
|
|
62
|
+
// Handled at once: a navigate that fails leaves before the await below, and the socket's close at the case's
|
|
63
|
+
// end then rejects the event, which must not go unhandled. The await still sees a rejection.
|
|
64
|
+
loaded.catch(() => undefined);
|
|
65
|
+
const navigated = await cdp.send("Page.navigate", { url: DATA_URL }, sessionId);
|
|
66
|
+
t.assert(navigated.errorText === undefined, `Page.navigate to a data: URL failed: ${navigated.errorText}`);
|
|
67
|
+
await bounded(loaded, t.patience, "Page.loadEventFired after the navigate to the data: page");
|
|
68
|
+
const evaluated = await cdp.send("Runtime.evaluate", { expression: READ, returnByValue: true }, sessionId);
|
|
69
|
+
t.equal(evaluated.result?.value, EXPECTED, "Runtime.evaluate on the data: page");
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await cdp.send("Target.closeTarget", { targetId }).catch(() => undefined);
|
|
73
|
+
}
|
|
74
|
+
}, { needs: ["cdp"] }),
|
|
75
|
+
browser("stream", async (t) => {
|
|
76
|
+
const stream = t.provider.stream;
|
|
77
|
+
if (stream === undefined)
|
|
78
|
+
return t.skip("the provider has no stream()");
|
|
79
|
+
const view = t.ok(await stream.call(t.provider, t.ref, {}, { signal: t.signal }), "stream");
|
|
80
|
+
t.assert(typeof view.url === "string" && /^https:\/\//.test(view.url), "stream gives the live view's URL, an https:// URL");
|
|
81
|
+
noSecret(t, JSON.stringify(t.ok(await t.provider.list(t.runLabels), "list")), view.url, "list, beside the stream");
|
|
82
|
+
}, { level: "full", needs: ["stream"] }),
|
|
83
|
+
// Last: it ends the run's one browser, which the runner releases again at the run's end (a second release, which must
|
|
84
|
+
// be ok).
|
|
85
|
+
browser("release", async (t) => {
|
|
86
|
+
const secret = await cdpUrl(t);
|
|
87
|
+
const before = await t.connect();
|
|
88
|
+
t.ok(await t.provider.release(t.ref, "delete"), "release");
|
|
89
|
+
t.ok(await t.provider.release(t.ref, "delete"), "a second release of the same browser");
|
|
90
|
+
const failures = {
|
|
91
|
+
"attach by id after release": await t.provider.attach({ id: t.ref.id }),
|
|
92
|
+
"attach by labels after release": await t.provider.attach({ labels: t.runLabels }),
|
|
93
|
+
"connect after release": await t.provider.connect(t.ref),
|
|
94
|
+
"ping after release": await before.client.call("ping", {}),
|
|
95
|
+
};
|
|
96
|
+
for (const [what, result] of Object.entries(failures)) {
|
|
97
|
+
const error = t.refused(result, what);
|
|
98
|
+
t.assert(error.message.trim() !== "", `${what}: the refusal is in words`);
|
|
99
|
+
noSecret(t, error.message, secret, what);
|
|
100
|
+
}
|
|
101
|
+
t.deepEqual(t.ok(await t.provider.list(t.runLabels), "list after release"), [], "list by the run's labels after release");
|
|
102
|
+
}),
|
|
103
|
+
];
|
|
104
|
+
/** What the CLI runs for a browser: the health cases (hello and ping from the provider, the kind consistent), then these. */
|
|
105
|
+
export const browserCases = [...healthCases, ...browserOnlyCases];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { CASE_LABEL } from "./util.js";
|
|
2
|
+
/** uname -m for each of Go's architecture names. */
|
|
3
|
+
const MACHINE = { amd64: "x86_64", arm64: "aarch64", "386": "i686", arm: "armv7l", riscv64: "riscv64", s390x: "s390x", ppc64le: "ppc64le" };
|
|
4
|
+
const drift = (name, run, extra = {}) => ({ id: `drift.${name}`, level: "core", group: "drift", needs: [], run, ...extra });
|
|
5
|
+
function sameDaemon(t, hello, where) {
|
|
6
|
+
t.equal(hello.version, t.provider.version, `${where}: the daemon's version is the provider's`);
|
|
7
|
+
const { kind, groups } = t.provider.capabilities();
|
|
8
|
+
t.equal(hello.kind, kind, `${where}: hello's kind is the provider's`);
|
|
9
|
+
for (const group of groups) {
|
|
10
|
+
t.assert(Array.isArray(hello.groups) && hello.groups.includes(group), `${where}: hello declares ${group}, which the provider declares`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The drift check's own words for a version mismatch (src/drift.ts, helloDrift). */
|
|
14
|
+
const VERSION_DRIFT = /hello: the daemon reports version (\S+), expected (\S+)/;
|
|
15
|
+
/**
|
|
16
|
+
* A refusal passes drift.version only when it is the version drift: the drift check's words, with two different
|
|
17
|
+
* versions. A create or connect refused for any other reason (a network mismatch, a vendor error that mentions a
|
|
18
|
+
* version) fails the case: it shows nothing about the version check.
|
|
19
|
+
*/
|
|
20
|
+
function versionDrift(t, message) {
|
|
21
|
+
const found = VERSION_DRIFT.exec(message);
|
|
22
|
+
t.assert(found !== null && found[1] !== found[2], `the refusal is the version drift ("hello: the daemon reports version X, expected Y"), not: ${message}`);
|
|
23
|
+
}
|
|
24
|
+
export const driftCases = [
|
|
25
|
+
drift("hello-matches", async (t) => {
|
|
26
|
+
sameDaemon(t, t.hello, "connect");
|
|
27
|
+
const again = await t.connect();
|
|
28
|
+
sameDaemon(t, again.hello, "a second connect");
|
|
29
|
+
}),
|
|
30
|
+
drift("arch", async (t) => {
|
|
31
|
+
const machine = (await t.exec(["uname", "-m"])).out.trim();
|
|
32
|
+
const expected = t.present(MACHINE[t.hello.arch], `hello's arch ${t.hello.arch} is one the suite knows (${Object.keys(MACHINE).join(", ")})`);
|
|
33
|
+
t.equal(machine, expected, `uname -m in a computer whose hello says ${t.hello.arch}`);
|
|
34
|
+
}, { needs: ["exec"] }),
|
|
35
|
+
drift("network", async (t) => {
|
|
36
|
+
const declared = t.spec().network;
|
|
37
|
+
t.deepEqual(t.ok(await t.provider.network(t.ref), "network read-back"), declared, "the network read back");
|
|
38
|
+
const listed = t.ok(await t.provider.list(t.runLabels), "list");
|
|
39
|
+
const info = t.present(listed.find((one) => one.ref.name === t.ref.name), `${t.ref.name} is listed by the run's label`);
|
|
40
|
+
t.deepEqual(info.network, declared, "the network list reads back");
|
|
41
|
+
}, { needs: ["network:none"] }),
|
|
42
|
+
drift("version", async (t) => {
|
|
43
|
+
const drifted = await t.drifted();
|
|
44
|
+
const labels = { ...t.runLabels, [CASE_LABEL]: "drift" };
|
|
45
|
+
const created = await t.attempt(t.spec({ labels }), drifted);
|
|
46
|
+
if (created.ok) {
|
|
47
|
+
let connected;
|
|
48
|
+
try {
|
|
49
|
+
connected = await drifted.connect(created.value);
|
|
50
|
+
if (connected.ok)
|
|
51
|
+
await connected.value.close();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await drifted.release(created.value, "delete");
|
|
55
|
+
}
|
|
56
|
+
versionDrift(t, t.refused(connected, "connect to a computer whose daemon reports another version", ["refused"]).message);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
versionDrift(t, t.refused(created, "create of a computer whose daemon reports another version", ["refused"]).message);
|
|
60
|
+
}
|
|
61
|
+
const left = t.ok(await t.provider.list(labels), "list").map((info) => info.ref.name);
|
|
62
|
+
t.deepEqual(left, [], "the computers of the drifted daemon left");
|
|
63
|
+
}, { computer: "none", timeoutMs: 600_000 }),
|
|
64
|
+
];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { alive } from "./util.js";
|
|
2
|
+
const NONE = "0000000000000000";
|
|
3
|
+
/**
|
|
4
|
+
* A program the daemon runs holds no capability in any set, the bounding and ambient sets included, so neither it nor
|
|
5
|
+
* a program it starts can gain one, root included; and no_new_privs is set. A field the kernel does not report fails.
|
|
6
|
+
*/
|
|
7
|
+
function noCapabilities(t, status) {
|
|
8
|
+
const field = (name) => new RegExp(`^${name}:\\s*(\\S+)\\s*$`, "m").exec(status)?.[1];
|
|
9
|
+
for (const set of ["CapEff", "CapPrm", "CapInh", "CapBnd", "CapAmb"])
|
|
10
|
+
t.equal(field(set), NONE, `${set} in /proc/self/status: no capabilities`);
|
|
11
|
+
t.equal(field("NoNewPrivs"), "1", "NoNewPrivs in /proc/self/status: set");
|
|
12
|
+
}
|
|
13
|
+
const exec = (name, run) => ({ id: `exec.${name}`, level: "core", group: "exec", needs: ["exec"], run });
|
|
14
|
+
export const execCases = [
|
|
15
|
+
exec("argv", async (t) => {
|
|
16
|
+
const ran = await t.exec(["echo", "$(id)", "`id`", "a;b", "*", "two words"]);
|
|
17
|
+
t.equal(ran.out, "$(id) `id` a;b * two words\n", "argv is never expanded in a shell");
|
|
18
|
+
}),
|
|
19
|
+
exec("streams", async (t) => {
|
|
20
|
+
const ran = await t.exec(["sh", "-c", "echo to-out; echo to-err >&2; echo more-out"]);
|
|
21
|
+
t.equal(ran.out, "to-out\nmore-out\n", "stdout");
|
|
22
|
+
t.equal(ran.err, "to-err\n", "stderr");
|
|
23
|
+
}),
|
|
24
|
+
exec("exit-code", async (t) => {
|
|
25
|
+
const ran = await t.exec(["sh", "-c", "exit 7"]);
|
|
26
|
+
t.equal(ran.exitCode, 7, "the exit code");
|
|
27
|
+
t.equal(ran.timedOut, false, "timedOut");
|
|
28
|
+
t.equal(ran.truncated, false, "truncated");
|
|
29
|
+
t.equal(ran.signal, undefined, "the signal");
|
|
30
|
+
t.equal((await t.exec(["true"])).exitCode, 0, "true's exit code");
|
|
31
|
+
}),
|
|
32
|
+
exec("cwd", async (t) => {
|
|
33
|
+
t.equal((await t.exec(["pwd"], { cwd: "/tmp" })).out, "/tmp\n", "pwd in cwd /tmp");
|
|
34
|
+
}),
|
|
35
|
+
exec("env", async (t) => {
|
|
36
|
+
const ran = await t.exec(["env"], { env: { GREETING: "hello there" } });
|
|
37
|
+
const vars = Object.fromEntries(ran.out
|
|
38
|
+
.split("\n")
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.map((line) => [line.slice(0, line.indexOf("=")), line.slice(line.indexOf("=") + 1)]));
|
|
41
|
+
t.equal(vars.GREETING, "hello there", "a variable the call adds");
|
|
42
|
+
// USER and LOGNAME name the account, so a uid with no name has neither.
|
|
43
|
+
const named = "USER" in vars ? ["LOGNAME", "USER"] : [];
|
|
44
|
+
t.deepEqual(Object.keys(vars).sort(), ["GREETING", "HOME", "PATH", ...named].sort(), "the environment: PATH, HOME, USER and LOGNAME when the user has a name, and env; nothing else");
|
|
45
|
+
t.equal(vars.LOGNAME, vars.USER, "LOGNAME and USER");
|
|
46
|
+
}),
|
|
47
|
+
exec("timeout", async (t) => {
|
|
48
|
+
const ran = await t.exec(["sh", "-c", "sleep 300 & echo $!; wait"], { timeoutMs: 1000 });
|
|
49
|
+
t.equal(ran.timedOut, true, "timedOut");
|
|
50
|
+
t.equal(ran.exitCode, null, "the exit code of a program ended by a signal");
|
|
51
|
+
t.equal(ran.signal, "TERM", "the signal that ended it");
|
|
52
|
+
const pid = Number(ran.out.trim());
|
|
53
|
+
t.assert(pid > 1, `the background sleep's pid, from ${JSON.stringify(ran.out)}`);
|
|
54
|
+
t.equal((await t.exec(["sh", "-c", alive([pid])])).out, "", "the background sleep after the timeout: gone");
|
|
55
|
+
}),
|
|
56
|
+
exec("abort", async (t) => {
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
setTimeout(() => controller.abort(), 500);
|
|
59
|
+
const ran = await t.client.call("exec.run", { argv: ["sleep", "301"], timeoutMs: 60_000 }, { signal: controller.signal });
|
|
60
|
+
t.refused(ran, "an aborted exec.run", ["aborted"]);
|
|
61
|
+
await t.until(async () => !(await t.exec(["sh", "-c", "cat /proc/[0-9]*/cmdline 2>/dev/null | tr '\\0' ' '"])).out.includes("sleep 301"), "sleep 301 ended after the abort");
|
|
62
|
+
}),
|
|
63
|
+
exec("truncation", async (t) => {
|
|
64
|
+
const ran = await t.exec(["head", "-c", "100000", "/dev/zero"], { maxOutput: 1000 });
|
|
65
|
+
t.equal(ran.truncated, true, "truncated");
|
|
66
|
+
t.equal(Buffer.byteLength(ran.out), 1000, "the bytes kept of stdout");
|
|
67
|
+
t.equal(ran.exitCode, 0, "the program's exit code: the rest was read and dropped, not cut off");
|
|
68
|
+
}),
|
|
69
|
+
exec("setsid-escapee", async (t) => {
|
|
70
|
+
const script = `p="$HOME/agentrun-conformance-fifo-$$"; mkfifo "$p"; setsid sh -c 'echo $$ > "$0"; exec sleep 302' "$p" >/dev/null 2>&1 </dev/null & read pid < "$p"; rm -f "$p"; echo $pid`;
|
|
71
|
+
const ran = await t.exec(["sh", "-c", script]);
|
|
72
|
+
t.equal(ran.exitCode, 0, `the script's exit code (stderr ${JSON.stringify(ran.err)})`);
|
|
73
|
+
const pid = Number(ran.out.trim());
|
|
74
|
+
t.assert(pid > 1, `the escapee's pid, from ${JSON.stringify(ran.out)}`);
|
|
75
|
+
t.equal((await t.exec(["sh", "-c", alive([pid])])).out, "", "a child that left the program's session, after the program ended: gone");
|
|
76
|
+
}),
|
|
77
|
+
// The run's spec asks for no user, so a computer's programs run as the provider's non-root default.
|
|
78
|
+
exec("unprivileged", async (t) => {
|
|
79
|
+
const uid = (await t.exec(["id", "-u"])).out.trim();
|
|
80
|
+
t.assert(uid !== "" && uid !== "0", `id -u: the computer's user is ${uid === "0" ? "root" : JSON.stringify(uid)}, though the spec did not ask for root`);
|
|
81
|
+
noCapabilities(t, (await t.exec(["cat", "/proc/self/status"])).out);
|
|
82
|
+
}),
|
|
83
|
+
exec("user", async (t) => {
|
|
84
|
+
const own = (await t.exec(["id", "-u"])).out.trim();
|
|
85
|
+
// A uid other than the computer's own, so a run that ignored user cannot pass for one that honoured it.
|
|
86
|
+
const target = own === "65534" ? "65533" : "65534";
|
|
87
|
+
const other = await t.client.call("exec.run", { argv: ["id", "-u"], user: target, timeoutMs: t.patience });
|
|
88
|
+
if (other.ok) {
|
|
89
|
+
const uid = Buffer.from(other.value.stdout, "base64").toString("utf8").trim();
|
|
90
|
+
t.equal(uid, target, `id -u in a run as uid ${target}, from a computer whose user is uid ${own}`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const error = t.refused(other, `a run as uid ${target}, which the daemon cannot switch to`, ["denied"]);
|
|
94
|
+
t.assert(error.message !== "", "the refusal is in words");
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
{
|
|
98
|
+
id: "exec.root-on-request",
|
|
99
|
+
level: "full",
|
|
100
|
+
group: "exec",
|
|
101
|
+
needs: ["exec", "user:root"],
|
|
102
|
+
computer: "none",
|
|
103
|
+
async run(t) {
|
|
104
|
+
const connected = await t.connect(await t.create({ user: "0" }));
|
|
105
|
+
const ran = (argv) => t.exec(argv, {}, connected.client);
|
|
106
|
+
t.equal((await ran(["id", "-u"])).out.trim(), "0", "id -u in a computer whose spec asked for user 0");
|
|
107
|
+
noCapabilities(t, (await ran(["cat", "/proc/self/status"])).out);
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "exec.user-uid",
|
|
112
|
+
level: "full",
|
|
113
|
+
group: "exec",
|
|
114
|
+
needs: ["exec", "user:uid"],
|
|
115
|
+
computer: "none",
|
|
116
|
+
async run(t) {
|
|
117
|
+
const connected = await t.connect(await t.create({ user: "65534" }));
|
|
118
|
+
const ran = (argv) => t.exec(argv, {}, connected.client);
|
|
119
|
+
t.equal((await ran(["id", "-u"])).out.trim(), "65534", "id -u in a computer whose spec asked for user 65534");
|
|
120
|
+
noCapabilities(t, (await ran(["cat", "/proc/self/status"])).out);
|
|
121
|
+
const home = await ran(["sh", "-c", 'echo ok > "$HOME/x" && cat "$HOME/x"']);
|
|
122
|
+
t.equal(home.out, "ok\n", `a write in HOME, as user 65534 (stderr ${JSON.stringify(home.err)})`);
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
];
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// files.* and tar.*: each call, a large file, a tar round trip, zip-slip refused, and pulls and pushes that end however
|
|
2
|
+
// they are left.
|
|
3
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
4
|
+
import { pullTar, pullTarStream, pushTar, readFile, writeFile } from "../../files.js";
|
|
5
|
+
import { MAX_LIST_ENTRIES } from "../../protocol.js";
|
|
6
|
+
import { describeEntry, tarOf, untar } from "../tar.js";
|
|
7
|
+
import { b64, decode, delay } from "./util.js";
|
|
8
|
+
// Most cases work in t.dir(), which finds HOME through exec.run: they need exec as well as files.
|
|
9
|
+
const files = (name, run, needs = ["files", "exec"]) => ({ id: `files.${name}`, level: "core", group: "files", needs, run });
|
|
10
|
+
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
11
|
+
const sorted = (entries) => entries
|
|
12
|
+
.filter((entry) => !["", ".", "./"].includes(entry.name))
|
|
13
|
+
.map(describeEntry)
|
|
14
|
+
.sort();
|
|
15
|
+
/**
|
|
16
|
+
* Every entry files.list gives for path, following its pages: a daemon may end a page early, and the next starts at the
|
|
17
|
+
* offset of the entries so far. A page that is truncated yet empty, or more pages than entries, fails the case.
|
|
18
|
+
*/
|
|
19
|
+
async function listAll(t, path, depth) {
|
|
20
|
+
const entries = [];
|
|
21
|
+
for (let pages = 1;; pages++) {
|
|
22
|
+
const page = await t.call("files.list", { path, depth, offset: entries.length });
|
|
23
|
+
entries.push(...page.entries);
|
|
24
|
+
if (!page.truncated)
|
|
25
|
+
return entries;
|
|
26
|
+
if (page.entries.length === 0 || pages > MAX_LIST_ENTRIES)
|
|
27
|
+
throw new Error(`files.list of ${path} at offset ${entries.length}: a truncated page with no entries, or no last page`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** A tree of more than 8 MiB, pushed once per run and shared by the cases that pull and push it. */
|
|
31
|
+
async function bigTree(t) {
|
|
32
|
+
const path = `${await t.home()}/agentrun-conformance-${Object.values(t.runLabels).join("-")}/big-tree`;
|
|
33
|
+
if ((await t.client.call("files.stat", { path })).ok)
|
|
34
|
+
return path;
|
|
35
|
+
const archive = tarOf([
|
|
36
|
+
{ name: "a.bin", type: "file", mode: 0o644, body: randomBytes(5 * 1024 * 1024) },
|
|
37
|
+
{ name: "sub/", type: "dir", mode: 0o755 },
|
|
38
|
+
{ name: "sub/b.bin", type: "file", mode: 0o644, body: randomBytes(3 * 1024 * 1024 + 99) },
|
|
39
|
+
{ name: "sub/run.sh", type: "file", mode: 0o755, body: Buffer.from("#!/bin/sh\necho copied\n") },
|
|
40
|
+
{ name: "run", type: "symlink", mode: 0o777, link: "sub/run.sh" },
|
|
41
|
+
]);
|
|
42
|
+
t.ok(await pushTar(t.client, `${path}.part`, archive), "pushing the big tree");
|
|
43
|
+
t.ok(await t.client.call("files.move", { from: `${path}.part`, to: path }), "moving the big tree into place");
|
|
44
|
+
return path;
|
|
45
|
+
}
|
|
46
|
+
/** Runs 8 pushes of archive on one client, all open at once: no source gives its bytes until every push has begun. */
|
|
47
|
+
function eightAtOnce(client, dir, archive) {
|
|
48
|
+
let arrived = 0;
|
|
49
|
+
let release = () => { };
|
|
50
|
+
const gate = new Promise((resolve) => (release = resolve));
|
|
51
|
+
const one = (i) => {
|
|
52
|
+
let here = false;
|
|
53
|
+
const arrive = () => {
|
|
54
|
+
if (here)
|
|
55
|
+
return;
|
|
56
|
+
here = true;
|
|
57
|
+
if (++arrived === 8)
|
|
58
|
+
release();
|
|
59
|
+
};
|
|
60
|
+
async function* source() {
|
|
61
|
+
arrive();
|
|
62
|
+
await gate;
|
|
63
|
+
yield archive;
|
|
64
|
+
}
|
|
65
|
+
return pushTar(client, `${dir}/${i}`, source()).finally(arrive);
|
|
66
|
+
};
|
|
67
|
+
return Promise.all(Array.from({ length: 8 }, (_, i) => one(i)));
|
|
68
|
+
}
|
|
69
|
+
export const filesCases = [
|
|
70
|
+
files("home", async (t) => {
|
|
71
|
+
const home = await t.home();
|
|
72
|
+
const uid = (await t.exec(["id", "-u"])).out.trim();
|
|
73
|
+
const stat = await t.call("files.stat", { path: home, follow: true });
|
|
74
|
+
t.deepEqual([stat.type, String(stat.uid)], ["dir", uid], `HOME, ${home}: a directory the computer's user owns`);
|
|
75
|
+
const path = `${home}/agentrun-conformance-home-${Object.values(t.runLabels).join("-")}.txt`;
|
|
76
|
+
t.deepEqual(await t.call("files.write", { path, data: b64("mine\n") }), { size: 5 }, "a write in HOME");
|
|
77
|
+
t.equal((await t.exec(["cat", path])).out, "mine\n", "the file, read by a program");
|
|
78
|
+
await t.call("files.remove", { path });
|
|
79
|
+
if (uid !== "0") {
|
|
80
|
+
const outside = `/agentrun-conformance-${Object.values(t.runLabels).join("-")}.txt`;
|
|
81
|
+
const refused = await t.client.call("files.write", { path: outside, data: b64("x") });
|
|
82
|
+
if (refused.ok)
|
|
83
|
+
await t.client.call("files.remove", { path: outside });
|
|
84
|
+
t.refused(refused, "a write by a user other than root into /, which root owns", ["denied"]);
|
|
85
|
+
}
|
|
86
|
+
}, ["files", "exec"]),
|
|
87
|
+
files("write-read", async (t) => {
|
|
88
|
+
const dir = await t.dir();
|
|
89
|
+
t.deepEqual(await t.call("files.write", { path: `${dir}/a.txt`, data: b64("alpha\n"), mode: 0o640 }), { size: 6 }, "files.write");
|
|
90
|
+
const read = await t.call("files.read", { path: `${dir}/a.txt` });
|
|
91
|
+
t.equal(decode(read.data), "alpha\n", "what files.read returns");
|
|
92
|
+
t.equal(read.eof, true, "eof");
|
|
93
|
+
t.equal(read.size, 6, "size");
|
|
94
|
+
t.deepEqual(await t.call("files.write", { path: `${dir}/a.txt`, data: b64("beta\n"), append: true }), { size: 11 }, "an append");
|
|
95
|
+
const part = await t.call("files.read", { path: `${dir}/a.txt`, offset: 6, length: 4 });
|
|
96
|
+
t.equal(decode(part.data), "beta", "a read at an offset");
|
|
97
|
+
}),
|
|
98
|
+
files("stat", async (t) => {
|
|
99
|
+
const dir = await t.dir();
|
|
100
|
+
await t.call("files.write", { path: `${dir}/a.txt`, data: b64("alpha\n"), mode: 0o640 });
|
|
101
|
+
const stat = await t.call("files.stat", { path: `${dir}/a.txt` });
|
|
102
|
+
t.equal(stat.type, "file", "type");
|
|
103
|
+
t.equal(stat.size, 6, "size");
|
|
104
|
+
t.equal(stat.mode, 0o640, "mode");
|
|
105
|
+
t.equal(String(stat.uid), (await t.exec(["id", "-u"])).out.trim(), "uid: the daemon's user owns what it writes");
|
|
106
|
+
t.equal(String(stat.gid), (await t.exec(["id", "-g"])).out.trim(), "gid: the daemon's group");
|
|
107
|
+
t.equal((await t.call("files.stat", { path: dir })).type, "dir", "a directory's type");
|
|
108
|
+
}, ["files", "exec"]),
|
|
109
|
+
files("list", async (t) => {
|
|
110
|
+
const dir = await t.dir();
|
|
111
|
+
await t.call("files.write", { path: `${dir}/a.txt`, data: b64("alpha\n") });
|
|
112
|
+
await t.call("files.mkdir", { path: `${dir}/sub` });
|
|
113
|
+
await t.call("files.write", { path: `${dir}/sub/b.txt`, data: b64("beta\n") });
|
|
114
|
+
const one = await listAll(t, dir, 1);
|
|
115
|
+
t.deepEqual(one.map((e) => [e.path, e.type]), [
|
|
116
|
+
[`${dir}/a.txt`, "file"],
|
|
117
|
+
[`${dir}/sub`, "dir"],
|
|
118
|
+
], "files.list at depth 1, every page");
|
|
119
|
+
const two = await listAll(t, dir, 2);
|
|
120
|
+
t.deepEqual(two.map((e) => e.path), [`${dir}/a.txt`, `${dir}/sub`, `${dir}/sub/b.txt`], "files.list at depth 2, every page, a directory before what it holds");
|
|
121
|
+
}),
|
|
122
|
+
files("mkdir", async (t) => {
|
|
123
|
+
const dir = await t.dir();
|
|
124
|
+
t.deepEqual(await t.call("files.mkdir", { path: `${dir}/x` }), {}, "files.mkdir");
|
|
125
|
+
t.refused(await t.client.call("files.mkdir", { path: `${dir}/x` }), "a directory already there", ["exists"]);
|
|
126
|
+
t.deepEqual(await t.call("files.mkdir", { path: `${dir}/x`, parents: true }), {}, "a directory already there, with parents");
|
|
127
|
+
t.deepEqual(await t.call("files.mkdir", { path: `${dir}/y/z`, parents: true }), {}, "missing parents");
|
|
128
|
+
t.refused(await t.client.call("files.mkdir", { path: `${dir}/p/q` }), "a missing parent without parents", ["not_found"]);
|
|
129
|
+
t.equal((await t.call("files.stat", { path: `${dir}/y/z` })).type, "dir", "the directory made with its parents");
|
|
130
|
+
}),
|
|
131
|
+
files("move", async (t) => {
|
|
132
|
+
const dir = await t.dir();
|
|
133
|
+
await t.call("files.write", { path: `${dir}/a.txt`, data: b64("alpha\n") });
|
|
134
|
+
await t.call("files.write", { path: `${dir}/c.txt`, data: b64("gamma\n") });
|
|
135
|
+
await t.call("files.move", { from: `${dir}/a.txt`, to: `${dir}/b.txt` });
|
|
136
|
+
t.equal(decode((await t.call("files.read", { path: `${dir}/b.txt` })).data), "alpha\n", "the moved file");
|
|
137
|
+
t.refused(await t.client.call("files.stat", { path: `${dir}/a.txt` }), "the old path", ["not_found"]);
|
|
138
|
+
t.refused(await t.client.call("files.move", { from: `${dir}/b.txt`, to: `${dir}/c.txt` }), "a move onto a file without overwrite", ["exists"]);
|
|
139
|
+
t.equal(decode((await t.call("files.read", { path: `${dir}/c.txt` })).data), "gamma\n", "the file a refused move left alone");
|
|
140
|
+
await t.call("files.move", { from: `${dir}/b.txt`, to: `${dir}/c.txt`, overwrite: true });
|
|
141
|
+
t.equal(decode((await t.call("files.read", { path: `${dir}/c.txt` })).data), "alpha\n", "the file a move with overwrite replaced");
|
|
142
|
+
}),
|
|
143
|
+
files("remove", async (t) => {
|
|
144
|
+
const dir = await t.dir();
|
|
145
|
+
await t.call("files.write", { path: `${dir}/tree/a.txt`, data: b64("alpha\n"), parents: true });
|
|
146
|
+
t.refused(await t.client.call("files.remove", { path: `${dir}/tree` }), "a directory with entries, without recursive", ["is_dir"]);
|
|
147
|
+
t.deepEqual(await t.call("files.remove", { path: `${dir}/tree`, recursive: true }), {}, "a recursive remove");
|
|
148
|
+
t.refused(await t.client.call("files.stat", { path: `${dir}/tree` }), "the removed directory", ["not_found"]);
|
|
149
|
+
await t.call("files.write", { path: `${dir}/b.txt`, data: b64("beta\n") });
|
|
150
|
+
await t.call("files.remove", { path: `${dir}/b.txt` });
|
|
151
|
+
t.refused(await t.client.call("files.stat", { path: `${dir}/b.txt` }), "the removed file", ["not_found"]);
|
|
152
|
+
}),
|
|
153
|
+
files("relative-path", async (t) => {
|
|
154
|
+
t.refused(await t.client.call("files.read", { path: "tmp/a.txt" }), "a relative path", ["invalid"]);
|
|
155
|
+
t.refused(await t.client.call("files.read", { path: "/tmp/agentrun-conformance-none/nothing" }), "a missing file", ["not_found"]);
|
|
156
|
+
}, ["files"]),
|
|
157
|
+
files("large-file", async (t) => {
|
|
158
|
+
const dir = await t.dir();
|
|
159
|
+
const bytes = randomBytes(3 * 1024 * 1024 + 17);
|
|
160
|
+
t.deepEqual(t.ok(await writeFile(t.client, `${dir}/big.bin`, bytes), "writeFile"), { size: bytes.length }, "the size written");
|
|
161
|
+
const back = t.ok(await readFile(t.client, `${dir}/big.bin`), "readFile");
|
|
162
|
+
t.assert(Buffer.from(back).equals(bytes), "the bytes read back are the bytes written");
|
|
163
|
+
t.equal((await t.exec(["sha256sum", `${dir}/big.bin`])).out.split(" ")[0], sha256(bytes), "sha256sum in the computer");
|
|
164
|
+
}, ["files", "exec"]),
|
|
165
|
+
files("read-only-file", async (t) => {
|
|
166
|
+
const dir = await t.dir();
|
|
167
|
+
const bytes = randomBytes(1536 * 1024);
|
|
168
|
+
t.deepEqual(t.ok(await writeFile(t.client, `${dir}/read-only.bin`, bytes, { mode: 0o400 }), "writeFile"), { size: bytes.length }, "the size written");
|
|
169
|
+
t.assert(Buffer.from(t.ok(await readFile(t.client, `${dir}/read-only.bin`), "readFile")).equals(bytes), "the bytes read back are the bytes written");
|
|
170
|
+
t.equal((await t.call("files.stat", { path: `${dir}/read-only.bin` })).mode, 0o400, "the mode set with the last chunk");
|
|
171
|
+
}),
|
|
172
|
+
files("tar-round-trip", async (t) => {
|
|
173
|
+
const dir = await t.dir();
|
|
174
|
+
const pushed = [
|
|
175
|
+
{ name: "./", type: "dir", mode: 0o755 },
|
|
176
|
+
{ name: "./run.sh", type: "file", mode: 0o755, body: Buffer.from("#!/bin/sh\necho ran from a pushed tar\n") },
|
|
177
|
+
{ name: "./nested/", type: "dir", mode: 0o750 },
|
|
178
|
+
{ name: "./nested/deeper/", type: "dir", mode: 0o755 },
|
|
179
|
+
{ name: "./nested/deeper/leaf.txt", type: "file", mode: 0o644, body: Buffer.from("leaf\n") },
|
|
180
|
+
{ name: "./nested/data.bin", type: "file", mode: 0o600, body: randomBytes(1536 * 1024) },
|
|
181
|
+
{ name: "./leaf-link", type: "symlink", mode: 0o777, link: "nested/deeper/leaf.txt" },
|
|
182
|
+
];
|
|
183
|
+
const target = `${dir}/pushed`;
|
|
184
|
+
t.ok(await pushTar(t.client, target, tarOf(pushed)), "pushTar");
|
|
185
|
+
t.equal((await t.exec([`${target}/run.sh`])).out, "ran from a pushed tar\n", "a pushed script runs");
|
|
186
|
+
const data = await t.call("files.stat", { path: `${target}/nested/data.bin` });
|
|
187
|
+
t.equal(data.mode, 0o600, "a pushed file's mode");
|
|
188
|
+
t.equal(String(data.uid), (await t.exec(["id", "-u"])).out.trim(), "a pushed file's owner: the computer's user, never the archive's uid 0");
|
|
189
|
+
t.equal((await t.call("files.stat", { path: `${target}/nested` })).mode, 0o750, "a pushed directory's mode");
|
|
190
|
+
const link = await t.call("files.stat", { path: `${target}/leaf-link` });
|
|
191
|
+
t.deepEqual([link.type, link.target], ["symlink", "nested/deeper/leaf.txt"], "a pushed symlink");
|
|
192
|
+
t.equal(decode((await t.call("files.read", { path: `${target}/leaf-link` })).data), "leaf\n", "a read through the pushed symlink");
|
|
193
|
+
const pulled = untar(t.ok(await pullTar(t.client, target), "pullTar"));
|
|
194
|
+
t.deepEqual(sorted(pulled), sorted(pushed), "the pulled tree, entry by entry");
|
|
195
|
+
}, ["files", "exec"]),
|
|
196
|
+
files("zip-slip-refused", async (t) => {
|
|
197
|
+
const dir = await t.dir();
|
|
198
|
+
const body = Buffer.from("x");
|
|
199
|
+
for (const [name, archive] of [
|
|
200
|
+
["a ../ entry", tarOf([{ name: "../escaped-dotdot", type: "file", mode: 0o644, body }])],
|
|
201
|
+
["an absolute entry", tarOf([{ name: `${dir}/escaped-absolute`, type: "file", mode: 0o644, body }])],
|
|
202
|
+
[
|
|
203
|
+
"an entry through a symlink out",
|
|
204
|
+
tarOf([
|
|
205
|
+
{ name: "out", type: "symlink", mode: 0o777, link: dir },
|
|
206
|
+
{ name: "out/escaped-symlink", type: "file", mode: 0o644, body },
|
|
207
|
+
]),
|
|
208
|
+
],
|
|
209
|
+
]) {
|
|
210
|
+
t.refused(await pushTar(t.client, `${dir}/target`, archive), `a push of ${name}`, ["denied"]);
|
|
211
|
+
}
|
|
212
|
+
for (const escaped of ["escaped-dotdot", "escaped-absolute", "escaped-symlink"]) {
|
|
213
|
+
t.refused(await t.client.call("files.stat", { path: `${dir}/${escaped}` }), `${dir}/${escaped}, outside the target`, ["not_found"]);
|
|
214
|
+
}
|
|
215
|
+
const inside = (await t.call("files.list", { path: `${dir}/target`, depth: 4 })).entries.map((e) => e.path);
|
|
216
|
+
t.assert(!inside.some((path) => path.includes("escaped")), `nothing escaped landed in the target: ${inside.join(", ")}`);
|
|
217
|
+
}),
|
|
218
|
+
files("tar-pipe", async (t) => {
|
|
219
|
+
const src = await bigTree(t);
|
|
220
|
+
const dst = `${await t.dir()}/copy`;
|
|
221
|
+
const one = await t.connect();
|
|
222
|
+
t.ok(await pushTar(one.client, dst, pullTarStream(one.client, src).chunks), "a pull piped into a push on one connection");
|
|
223
|
+
const listing = async (path) => sorted(untar(t.ok(await pullTar(t.client, path), `pulling ${path}`)));
|
|
224
|
+
t.deepEqual(await listing(dst), await listing(src), "the copy, entry by entry");
|
|
225
|
+
t.equal((await t.exec([`${dst}/run`])).out, "copied\n", "the copied script, through its copied symlink");
|
|
226
|
+
}, ["files", "exec"]),
|
|
227
|
+
files("push-refused", async (t) => {
|
|
228
|
+
const src = await bigTree(t);
|
|
229
|
+
const target = `${await t.dir()}/read-only-dir`;
|
|
230
|
+
await t.call("files.mkdir", { path: target, mode: 0o555 });
|
|
231
|
+
const one = await t.connect();
|
|
232
|
+
const { chunks, done } = pullTarStream(one.client, src);
|
|
233
|
+
t.refused(await pushTar(one.client, target, chunks), "a copy into a directory that refuses its writes", ["denied"]);
|
|
234
|
+
t.refused(await done, "the source pull of the refused copy");
|
|
235
|
+
const eight = Array.from({ length: 8 }, () => pullTarStream(one.client, src).chunks[Symbol.asyncIterator]());
|
|
236
|
+
const firsts = await Promise.all(eight.map((it) => it.next().then((step) => step.done, (error) => error.message)));
|
|
237
|
+
t.deepEqual(firsts, Array(8).fill(false), "8 pulls at once after it, on the same connection: each gave its first chunk");
|
|
238
|
+
await Promise.all(eight.map((it) => it.return?.()));
|
|
239
|
+
t.deepEqual((await t.call("files.list", { path: target })).entries, [], "what the refused copy left in the directory");
|
|
240
|
+
}),
|
|
241
|
+
files("fifo", async (t) => {
|
|
242
|
+
const dir = await t.dir();
|
|
243
|
+
await t.call("files.write", { path: `${dir}/a.txt`, data: b64("a") });
|
|
244
|
+
t.equal((await t.exec(["mkfifo", `${dir}/pipe`])).exitCode, 0, "mkfifo");
|
|
245
|
+
const one = await t.connect();
|
|
246
|
+
t.refused(await one.client.call("files.read", { path: `${dir}/pipe` }), "files.read of a FIFO, which must return, not wait for a writer", ["invalid"]);
|
|
247
|
+
t.refused(await one.client.call("files.write", { path: `${dir}/pipe`, data: b64("x") }), "files.write of a FIFO, which must return, not wait for a reader", [
|
|
248
|
+
"invalid",
|
|
249
|
+
]);
|
|
250
|
+
const pulled = untar(t.ok(await pullTar(one.client, dir), "a pull of a directory that holds a FIFO"));
|
|
251
|
+
t.deepEqual(sorted(pulled), sorted([{ name: "a.txt", type: "file", mode: 0o644, body: Buffer.from("a") }]), "the pull: the file, and no FIFO");
|
|
252
|
+
t.deepEqual(t.ok(await one.client.call("ping", {}), "ping"), {}, "ping after the FIFO calls");
|
|
253
|
+
}, ["files", "exec"]),
|
|
254
|
+
files("pull-unread", async (t) => {
|
|
255
|
+
const src = await bigTree(t);
|
|
256
|
+
const one = await t.connect();
|
|
257
|
+
const { chunks, done } = pullTarStream(one.client, src);
|
|
258
|
+
const iterator = chunks[Symbol.asyncIterator]();
|
|
259
|
+
t.equal((await iterator.next()).done, false, "the first chunk came");
|
|
260
|
+
await delay(1000);
|
|
261
|
+
t.deepEqual(t.ok(await one.client.call("ping", {}), "a ping beside an unread pull"), {}, "the ping");
|
|
262
|
+
t.equal(t.ok(await one.client.call("files.stat", { path: src }), "a stat beside an unread pull").type, "dir", "the stat");
|
|
263
|
+
await iterator.return?.();
|
|
264
|
+
t.refused(await done, "a pull left before its end");
|
|
265
|
+
}),
|
|
266
|
+
files("pull-abort", async (t) => {
|
|
267
|
+
const src = await bigTree(t);
|
|
268
|
+
const one = await t.connect();
|
|
269
|
+
const controller = new AbortController();
|
|
270
|
+
const { chunks, done } = pullTarStream(one.client, src, { signal: controller.signal });
|
|
271
|
+
const iterator = chunks[Symbol.asyncIterator]();
|
|
272
|
+
t.equal((await iterator.next()).done, false, "the first chunk came");
|
|
273
|
+
await delay(1000);
|
|
274
|
+
controller.abort();
|
|
275
|
+
t.refused(await done, "an aborted pull", ["aborted"]);
|
|
276
|
+
t.deepEqual(t.ok(await one.client.call("ping", {}), "a ping after the abort"), {}, "the ping");
|
|
277
|
+
const eight = Array.from({ length: 8 }, () => pullTarStream(one.client, src).chunks[Symbol.asyncIterator]());
|
|
278
|
+
const firsts = await Promise.all(eight.map((it) => it.next()));
|
|
279
|
+
t.deepEqual(firsts.map((step) => step.done), Array(8).fill(false), "8 pulls at once after the abort: each gave its first chunk");
|
|
280
|
+
await Promise.all(eight.map((it) => it.return?.()));
|
|
281
|
+
}),
|
|
282
|
+
files("push-abort", async (t) => {
|
|
283
|
+
const dir = await t.dir();
|
|
284
|
+
const one = await t.connect();
|
|
285
|
+
const controller = new AbortController();
|
|
286
|
+
async function* source() {
|
|
287
|
+
yield tarOf([{ name: "big.bin", type: "file", mode: 0o644, body: randomBytes(512 * 1024 - 1536) }]);
|
|
288
|
+
controller.abort();
|
|
289
|
+
}
|
|
290
|
+
t.refused(await pushTar(one.client, `${dir}/aborted`, source(), { signal: controller.signal }), "a push aborted after its source ended", ["aborted"]);
|
|
291
|
+
const eight = await eightAtOnce(one.client, `${dir}/eight`, tarOf([{ name: "one.txt", type: "file", mode: 0o644, body: Buffer.from("1") }]));
|
|
292
|
+
t.deepEqual(eight.map((r) => (r.ok ? "ok" : `${r.error.code}: ${r.error.message}`)), Array(8).fill("ok"), "8 pushes at once on the same connection");
|
|
293
|
+
}),
|
|
294
|
+
];
|