Files
upstream-jitsi-meet/tests/prosody/helpers/prosody_shell.js
upstream-mirror 1d2bfcac0c
Some checks failed
Prosody Plugin Tests / test (push) Failing after 10m11s
Close stale issues and PRs / stale (push) Failing after 1s
snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
2026-09-15 15:56:32 +05:00

37 lines
1.2 KiB
JavaScript

import { getContainer } from './container.js';
/**
* Runs a Prosody shell command inside the Docker container (Option I).
* Uses `prosodyctl shell` via stdin so the command executes against the live instance.
*
* Example commands:
* module:load("muc_hide_all", "conference.localhost")
* module:unload("muc_hide_all", "conference.localhost")
*
* @param {string} command Prosody shell command string
* @returns {Promise<string>} stdout from the shell
*/
export async function prosodyShell(command) {
const container = getContainer();
// Escape single quotes in the command before embedding in the shell string.
const escaped = command.replace(/'/g, '\'\\\'\'');
const { output, exitCode } = await container.exec([
'su', '-s', '/bin/sh', 'prosody', '-c',
`echo '${escaped}' | prosodyctl shell`
]);
if (exitCode !== 0) {
throw new Error(`prosodyctl shell failed (exit ${exitCode}):\n${output}`);
}
// prosodyctl shell exits 0 even when the Lua command throws; detect errors
// from the output text. Prosody prefixes error lines with '! '.
if (/^!/m.test(output)) {
throw new Error(`prosodyctl shell command error:\n${output}`);
}
return output;
}