This commit is contained in:
2026-06-25 12:54:29 -05:00
parent 56e34475fc
commit 6c6514e70f
4 changed files with 101 additions and 31 deletions

View File

@@ -149,11 +149,11 @@ async function runHost(jobId, script, host, executionContext) {
return;
}
const secret = decryptSecret(host);
const wrapper = buildWrapper(script.content, host, executionContext);
const file = path.join(os.tmpdir(), `poshmanager-${jobId}-${host.id}.ps1`);
try {
const secret = decryptSecret(host);
const wrapper = buildWrapper(script.content, host, executionContext);
await fs.writeFile(file, wrapper, { mode: 0o600 });
await spawnPowerShell(jobId, host, file, secret, executionContext);
} catch (error) {

View File

@@ -20,12 +20,22 @@ db.prepare(`INSERT INTO runplans (id, name, script_id, visibility, owner_user_id
const jobId = 'job_test_1';
db.prepare(`INSERT INTO jobs (id, runplan_id, script_id, status, triggered_by, created_at)
VALUES (?, ?, ?, 'completed', ?, ?)`).run(jobId, runplanId, scriptId, owner, ts);
const scriptTestJobId = 'job_script_test_1';
db.prepare(`INSERT INTO jobs (id, runplan_id, script_id, status, triggered_by, created_at)
VALUES (?, NULL, ?, 'failed', ?, ?)`).run(scriptTestJobId, scriptId, owner, ts);
test('the triggering operator can list and read their job', () => {
assert.ok(listJobs(owner, false).some((j) => j.id === jobId));
assert.ok(getJob(jobId, owner, false));
});
test('script test jobs without a RunPlan stay visible to their triggering operator', () => {
assert.ok(listJobs(owner, false).some((j) => j.id === scriptTestJobId));
const job = getJob(scriptTestJobId, owner, false);
assert.equal(job.id, scriptTestJobId);
assert.equal(job.runplanId, null);
});
test('an unrelated user cannot see a personal job', () => {
assert.ok(!listJobs(stranger, false).some((j) => j.id === jobId));
assert.equal(getJob(jobId, stranger, false), null);