dce32b96b7
- POST /api/run/drop-file pipes the body to its file as it arrives in every case — a member's (S3) through `write-as … replace` with the bytes on stdin — instead of buffering up to 20 MB in memory for a remote browser. - Remote limit (server mode, a LAN browser) 20 MB → 500 MB, as a Files upload. - A loopback browser in local mode has no cap any more, only the data dir's free space less a 1 GB reserve; ETOOBIG's max_bytes is what still fits, so the UI's "at most N MB" stays true. - drop-image keeps its 20 MB in-memory limit, now checked on its own. - fake-sudo gains a spawn for run-as.__setSpawnImpl.
35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
/**
|
|
* @file fake-sudo.js
|
|
* @description Test helper for the S3 suites: an `execImpl` for
|
|
* `run-as.__setExecImpl` (and a `spawn` for `__setSpawnImpl`) that plays
|
|
* `sudo -n -u <login> [VAR=v…] <bin> …` without root — it records the argv (so a test can assert nothing secret
|
|
* crossed sudo) and runs the real `scripts/server/write-as.sh` for
|
|
* `/opt/agenthub/libexec/write-as`, as this account.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const path = require("node:path");
|
|
const { execFileSync, spawn: spawnChild } = require("node:child_process");
|
|
|
|
const WRITE_AS = path.join(__dirname, "..", "..", "..", "scripts", "server", "write-as.sh");
|
|
|
|
/** `{ exec, spawn, calls }`: pass `exec` to `runAs.__setExecImpl` and `spawn`
|
|
* to `runAs.__setSpawnImpl`; `calls` = every sudo argv. */
|
|
function fakeSudo() {
|
|
const calls = [];
|
|
// The command sudo would run, as [file, args].
|
|
const unwrap = (cmd, argv) => {
|
|
calls.push([cmd, ...argv]);
|
|
if (cmd !== "sudo") return [cmd, argv];
|
|
let i = argv.indexOf("-u") + 2; // past the login
|
|
while (/^[A-Z_][A-Z0-9_]*=/.test(argv[i])) i++;
|
|
const [bin, ...rest] = argv.slice(i);
|
|
return bin === "/opt/agenthub/libexec/write-as" ? ["sh", [WRITE_AS, ...rest]] : [bin, rest];
|
|
};
|
|
const exec = (cmd, argv, opts = {}) => execFileSync(...unwrap(cmd, argv), opts);
|
|
const spawn = (cmd, argv, opts = {}) => spawnChild(...unwrap(cmd, argv), opts);
|
|
return { exec, spawn, calls };
|
|
}
|
|
|
|
module.exports = { fakeSudo };
|