Repository navigation
Expand file tree
/
Copy pathscripts.test.mjs
More file actions
40 lines (36 loc) · 2.26 KB
/
Copy pathscripts.test.mjs
File metadata and controls
40 lines (36 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {test} from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import path from 'node:path';
import {execFileSync, spawnSync} from 'node:child_process';
import {root, shellQuote, xml, installFile, wrapper, launchAgent, serviceEntries} from './scripts/install-util.mjs';
import {desktopScript, kcpassword} from './guest.mjs';
test('installer escaping preserves literal shell arguments and XML text', () => {
const value = "a path; printf NO '$HOME' & <x>";
assert.equal(execFileSync('/bin/sh', ['-c', 'printf %s ' + shellQuote(value)], {encoding: 'utf8'}), value);
assert.equal(xml('<x a="v">&\''), '<x a="v">&'');
const script = wrapper('cli.mjs', {environment: true});
assert(script.includes('--env-file-if-exists=')); assert(script.includes('export NODE_BIN='));
const plist = launchAgent(serviceEntries[0], '/private/example-state');
assert(plist.includes('<key>KeepAlive</key><true/>')); assert(plist.includes('controller.log'));
});
test('installer refuses to overwrite an unrelated existing file', async t => {
const dir = await fs.mkdtemp(path.join(root, '.test-install-'));
t.after(() => fs.rm(dir, {recursive: true, force: true}));
const file = path.join(dir, 'command');
await installFile(file, 'original\n');
await installFile(file, 'original\n');
await assert.rejects(installFile(file, 'different\n'), /Refusing to replace/);
assert.equal(await fs.readFile(file, 'utf8'), 'original\n');
});
test('setup help is side-effect-free and does not require a real VM or Lume', () => {
for (const file of ['init-template.mjs', 'host-install.mjs', 'host-services.mjs', 'client-install.mjs']) {
const result = spawnSync(process.execPath, [path.join(root, 'scripts', file), '--help'], {encoding: 'utf8', env: {...process.env, LUME_BIN: '/nonexistent-test-lume'}});
assert.equal(result.status, 0, file + ': ' + result.stderr); assert(result.stdout.length > 0);
}
});
test('opt-in auto-login does not enable a separate guest Screen Sharing listener', () => {
const script = desktopScript('spaceuser', 'fixture-only');
assert(script.includes('/etc/kcpassword')); assert(!script.includes('com.apple.screensharing'));
assert.equal(kcpassword('lume').toString('hex'), '11fc3f46d2bcddeaa3b91f7d');
});