28 lines
2.0 KiB
JavaScript
28 lines
2.0 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {createRequire} from 'node:module';
|
|
import {mkdtempSync,mkdirSync,writeFileSync,rmSync,symlinkSync} from 'node:fs';
|
|
import {tmpdir} from 'node:os';
|
|
import path from 'node:path';
|
|
const {privateInspectorPaths}=createRequire(import.meta.url)('../apps/browser/inspection.cjs');
|
|
function fixture(t,packaged=false){
|
|
const root=mkdtempSync(path.join(tmpdir(),'safetynet-inspector-paths-'));
|
|
const python=path.join(root,packaged?'python/python.exe':'.runtime/windows/python/python.exe'),script=path.join(root,packaged?'inspector/server.py':'apps/inspector/server.py');
|
|
for(const file of [python,script]){mkdirSync(path.dirname(file),{recursive:true});writeFileSync(file,'synthetic fixture');}
|
|
t.after(()=>{assert.ok(path.resolve(root).startsWith(path.resolve(tmpdir())+path.sep));assert.ok(path.basename(root).startsWith('safetynet-inspector-paths-'));rmSync(root,{recursive:true,force:true});});
|
|
return {root,python,script};
|
|
}
|
|
test('inspector accepts only its own staged or packaged runtime and source',t=>{
|
|
for(const packaged of [false,true]){const f=fixture(t,packaged);assert.deepEqual(privateInspectorPaths(f.root,packaged,{}),{python:f.python,script:f.script});assert.deepEqual(privateInspectorPaths(f.root,packaged,{SAFETYNET_PYTHON:f.python,SAFETYNET_INSPECTOR_SCRIPT:f.script}),{python:f.python,script:f.script});}
|
|
});
|
|
test('external runtime and parser overrides are rejected without launching or granting access',t=>{
|
|
const f=fixture(t),other=fixture(t);
|
|
assert.equal(privateInspectorPaths(f.root,false,{SAFETYNET_PYTHON:other.python}),null);
|
|
assert.equal(privateInspectorPaths(f.root,false,{SAFETYNET_INSPECTOR_SCRIPT:other.script}),null);
|
|
assert.equal(privateInspectorPaths(path.join(f.root,'missing'),false,{}),null);
|
|
});
|
|
test('a linked installation root cannot redirect grants to another tree',t=>{
|
|
const f=fixture(t),link=path.join(f.root,'linked-root');symlinkSync(f.root,link,process.platform==='win32'?'junction':'dir');
|
|
assert.equal(privateInspectorPaths(link,false,{}),null);
|
|
});
|