Files
luci-app-owrt-remote/tests/test_tachyon_ui.cjs
T
kzolotarev95 927aec8ffe
OpenWrt IPK and APK / Validate source and resolve stable SDKs (push) Waiting to run
Fix Tachyon APK discovery and release package revision 122-r2
2026-11-22 00:07:08 +04:00

30 lines
1.8 KiB
JavaScript

const fs = require('node:fs');
const vm = require('node:vm');
const assert = require('node:assert/strict');
const source = fs.readFileSync('vps/owrt-remote-hub.py', 'utf8');
const start = source.indexOf('function renderTachyon(router) {{');
const end = source.indexOf('\nfunction render(list)', start);
const code = source.slice(start, end).replaceAll('{{', '{').replaceAll('}}', '}');
const escape = value => String(value).replace(/[&<>"']/g, ch => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[ch]));
const context = {escapeHtml: escape, escapeAttr: escape};
vm.createContext(context); vm.runInContext(code, context);
assert.equal(context.renderTachyon({}), '');
assert.equal(context.renderTachyon({tachyon: {installed: false}}), '');
const router = {permissions: {admin: true}, tachyon: {installed: true, version: '2.0.0~beta.8-1', online: true, url: '/tachyon/a/'}};
let html = context.renderTachyon(router);
assert(html.includes('Открыть Tachyon'));
assert(html.includes('target="_blank"'));
assert(html.includes('Online'));
assert(html.includes('href="/tachyon/a/"'));
assert(html.includes('tachyonMeta'));
assert(html.includes('tachyonAction'));
assert(context.renderTachyon({permissions:{admin:true}, tachyon:{installed:true, online:true, url:'/tachyon/a/'}}).includes('Tachyon</strong>'));
router.tachyon.online = false;
assert(context.renderTachyon(router).includes('Offline'));
router.permissions.admin = false;
assert(!context.renderTachyon(router).includes('<a '));
router.permissions.admin = true; router.tachyon.version = '<img onerror=alert(1)>';
assert(!context.renderTachyon(router).includes('<img '));
assert.equal(source.split(String.fromCharCode(36) + '{{renderTachyon(r)}}').length - 1, 2);
console.log('TACHYON_UI_OK: absent, installed, offline, access controls, escaping and both layouts');