8 lines
1.8 KiB
JavaScript
8 lines
1.8 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import {readFileSync} from 'node:fs';import vm from 'node:vm';const source=readFileSync(new URL('../apps/browser/main.cjs',import.meta.url),'utf8'),start=source.indexOf('readClipboard:async limit=>')+'readClipboard:'.length,end=source.indexOf('writeClipboard:',start);const code=source.slice(start,end).trim().replace(/,$/,'');
|
|
function fixture(types,text='PUBLIC',size=6){const calls=[],blob={size,text:async()=>text},item={types,getType:async type=>{calls.push(type);if(type!=='text/plain')throw Error('HTML must not be read');return blob;}},read=vm.runInNewContext('('+code+')',{clipboard:{read:async()=>[item]}});return {read,calls};}
|
|
test('rich HTML clipboard exports only independently bounded inert plain text',async()=>{const f=fixture(['text/plain','text/html','electron application/osclipboard;format="HTML Format"']);assert.equal(await f.read(1024),'PUBLIC');assert.deepEqual(f.calls,['text/plain']);});
|
|
test('files images and unsupported rich clipboard formats remain denied',async()=>{for(const types of [['text/html'],['text/plain','image/png'],['text/plain','electron application/osclipboard;format="CF_HDROP"'],['text/plain','application/rtf']]){const f=fixture(types);await assert.rejects(f.read(1024));assert.deepEqual(f.calls,[]);}});
|
|
test('plain representation size is bounded before it is read',async()=>{const f=fixture(['text/plain','text/html'],'PUBLIC',2048);await assert.rejects(f.read(1024));assert.deepEqual(f.calls,['text/plain']);});
|
|
test('WebSocket handshake is denied even when an old central policy enables the unsupported flag',()=>{assert.match(source,/if\(details\.resourceType==='webSocket'\)\{audit\('dlp\.block','websocket-disabled'/);assert.doesNotMatch(source,/details\.resourceType==='webSocket'&&!policy\.browser\.allowWebSockets/);});
|
|
|