first commit

This commit is contained in:
Karl committed 2026-10-13 10:34:48 +02:00
commit ff482ebe23
251 files changed
+19126

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
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);
});