Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
91 lines
5.4 KiB
JavaScript
91 lines
5.4 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createRequire } from 'node:module';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
const require = createRequire(import.meta.url);
|
|
const { registerFilesIpc, TokenStore } = require('../app/main/files-main.js');
|
|
|
|
function fixture(t, extra = {}) {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'tp-file-bridge-'));
|
|
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
const upload = path.join(root, 'upload'); const download = path.join(root, 'download');
|
|
fs.mkdirSync(upload); fs.mkdirSync(download);
|
|
fs.writeFileSync(path.join(upload, 'Отчёт 日本.bin'), Buffer.from([0, 255, 13, 10, 91]));
|
|
const handlers = new Map(); const sent = []; let epoch = 1; let nextId = 0;
|
|
registerFilesIpc({
|
|
ipcMain: { handle: (name, fn) => handlers.set(name, fn) },
|
|
trustedSender: e => e.trusted === true,
|
|
dialog: { showOpenDialog: () => { throw new Error('No native dialogs in tests'); } },
|
|
shell: { openPath: () => { throw new Error('No OS shell in tests'); } },
|
|
getWindow: () => null,
|
|
request: async (id, cmd, args) => { sent.push({ id, cmd, args }); return { ok: true, result: cmd === 'file_config' ? {} : { transfer_id: ++nextId, direction: cmd === 'file_upload' ? 'upload' : 'download', state: 'queued' } }; },
|
|
validConnectionId: id => id === 'c1', getConnectionEpoch: () => epoch,
|
|
testOffscreen: true, testProfileDir: root, tr: key => key,
|
|
settingsPath: path.join(root, 'files-settings.json'),
|
|
env: { TEAMSPEACH_TEST_FILES_UPLOAD_DIR: upload, TEAMSPEACH_TEST_FILES_DOWNLOAD_DIR: download },
|
|
...extra,
|
|
});
|
|
return { root, upload, download, sent, epoch: n => { epoch = n; }, call: (name, ...args) => handlers.get(`files:${name}`)({ trusted: true }, ...args), handlers };
|
|
}
|
|
|
|
test('opaque capabilities preserve Unicode paths and never accept renderer host paths', async t => {
|
|
const f = fixture(t);
|
|
const picked = await f.call('choose-upload', 'c1');
|
|
assert.equal(picked.files.length, 1);
|
|
assert.equal(picked.files[0].name, 'Отчёт 日本.bin');
|
|
assert.equal(JSON.stringify(picked).includes(f.root), false);
|
|
const token = picked.files[0].token;
|
|
assert.equal((await f.call('upload', 'c1', { token, channelId: 3, dir: '/', overwrite: false, source: 'C:/private/ignored' })).ok, true);
|
|
assert.equal(f.sent.find(r => r.cmd === 'file_upload').args.source, path.join(f.upload, picked.files[0].name));
|
|
assert.equal(f.sent.find(r => r.cmd === 'file_upload').args.path, '/Отчёт 日本.bin');
|
|
assert.equal((await f.call('upload', 'c1', { token, channelId: 3, dir: '/../', overwrite: false })).ok, false);
|
|
const dest = await f.call('choose-download-dir', 'c1');
|
|
assert.equal((await f.call('download', 'c1', { token: dest.token, channelId: 3, path: '/x', subdirs: ['..'], overwrite: false })).ok, false);
|
|
assert.equal((await f.call('download', 'c1', { token: dest.token, channelId: 3, path: '/x', overwrite: false, dest_dir: 'C:/private/ignored' })).ok, true);
|
|
assert.equal(f.sent.find(r => r.cmd === 'file_download').args.dest_dir, f.download);
|
|
assert.equal((await f.call('open-folder', dest.token)).ok, false);
|
|
assert.equal((await f.call('release', token)).released, true);
|
|
assert.equal((await f.call('upload', 'c1', { token, channelId: 3, dir: '/', overwrite: false })).ok, false);
|
|
});
|
|
|
|
test('delayed chooser rejects reconnect into identical address and channel', async t => {
|
|
let finish;
|
|
const f = fixture(t, { testOffscreen: false, dialog: { showOpenDialog: () => new Promise(resolve => { finish = resolve; }) } });
|
|
const pending = f.call('choose-upload', 'c1');
|
|
f.epoch(2);
|
|
finish({ canceled: false, filePaths: [path.join(f.upload, 'Отчёт 日本.bin')] });
|
|
assert.equal((await pending).error.code, 'not_connected');
|
|
assert.equal(f.sent.length, 0);
|
|
const folder = f.call('choose-download-dir', 'c1');
|
|
f.epoch(null);
|
|
finish({ canceled: false, filePaths: [f.download] });
|
|
assert.equal((await folder).error.code, 'not_connected');
|
|
});
|
|
|
|
test('untrusted IPC cannot mint capabilities and tokens expire', async t => {
|
|
const f = fixture(t);
|
|
assert.equal((await f.handlers.get('files:choose-upload')({ trusted: false }, 'c1')).error.code, 'forbidden');
|
|
let now = 0; const store = new TokenStore(() => now);
|
|
const token = store.add({ kind: 'dir', path: '/fixture' });
|
|
assert.equal(store.get(token, 'file'), null);
|
|
now = 31 * 60 * 1000;
|
|
assert.equal(store.get(token, 'dir'), null);
|
|
});
|
|
|
|
test('approved default directory persists without accepting a renderer path', async t => {
|
|
const f = fixture(t);
|
|
assert.equal((await f.call('settings/set', { approvedDownloadDir: 'C:/private' })).ok, false);
|
|
assert.equal((await f.call('settings/choose-default')).ok, true);
|
|
assert.equal((await f.call('settings/set', { alwaysAsk: false, downloadSlots: 7, uploadSlots: 3, limitDownload: true, downloadMiB: 1.5 })).ok, true);
|
|
assert.equal((await f.call('settings/set', { downloadSlots: 8 })).ok, false);
|
|
const saved = JSON.parse(fs.readFileSync(path.join(f.root, 'files-settings.json'), 'utf8'));
|
|
assert.equal(saved.approvedDownloadDir, f.download);
|
|
assert.equal(saved.downloadSlots, 7);
|
|
const pub = await f.call('settings/get');
|
|
assert.equal(JSON.stringify(pub).includes(f.root), false);
|
|
assert.equal((await f.call('choose-download-dir', 'c1')).ok, true);
|
|
assert.equal((await f.call('settings/copy-default')).error.code, 'unavailable');
|
|
});
|