335 lines
24 KiB
JavaScript
335 lines
24 KiB
JavaScript
/** CheerpJ Core contract tests, including the customer-provided iTAC Workplace JNLP. No proprietary JAR execution. */
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import vm from 'node:vm';
|
|
function fixtureNode(name,attributes='',children=[],content='') {
|
|
const getAttribute=k=>attributes.match(new RegExp('(?:^|\\s)'+k+'="([^"]*)"'))?.[1]??null;
|
|
const all=tag=>children.flatMap(c=>[...(c.localName===tag?[c]:[]),...(c.getElementsByTagName?.(tag)||[])]);
|
|
return {localName:name,nodeType:1,childNodes:children,textContent:content,getAttribute,hasAttribute:k=>getAttribute(k)!==null,getElementsByTagName:all};
|
|
}
|
|
class DOMParser {
|
|
parseFromString(xml){
|
|
const groups=[...xml.matchAll(/<resources\b([^>]*)>([\s\S]*?)<\/resources>/g)].map(m=>{
|
|
const html=m[2];
|
|
const jars=[...html.matchAll(/<jar\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('jar',x[1]));
|
|
const natives=[...html.matchAll(/<nativelib\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('nativelib',x[1]));
|
|
const java=[...html.matchAll(/<java\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('java',x[1]));
|
|
const properties=[...html.matchAll(/<property\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('property',x[1]));
|
|
return fixtureNode('resources',m[1],[...java,...jars,...natives,...properties]);
|
|
});
|
|
const args=[...xml.matchAll(/<argument>([^<]*)<\/argument>/g)].map(m=>fixtureNode('argument','',[],m[1]));
|
|
const appMatch=xml.match(/<application-desc\b([^>]*?)(?:\/>|>(?:[\s\S]*?)<\/application-desc>)/);
|
|
const app=appMatch?fixtureNode('application-desc',appMatch[1],args):null;
|
|
const rootMatch=xml.match(/<jnlp\b([^>]*)>/);
|
|
const root=fixtureNode(rootMatch?'jnlp':'error',rootMatch?.[1]||'',[...groups,...(app?[app]:[])]);
|
|
return {documentElement:root,getElementsByTagName:tag=>tag==='parsererror'?[]:root.getElementsByTagName(tag)};
|
|
}
|
|
}
|
|
const nativeSource=fs.readFileSync(new URL('../public/cheerpj/natives/jaas.js',import.meta.url),'utf8');
|
|
assert.match(nativeSource,/Java_com_sun_security_auth_module_UnixSystem_getUnixInfo/);
|
|
const source=fs.readFileSync(new URL('../public/cheerpj-runner.js',import.meta.url),'utf8')
|
|
.replace(/^import jaasNativeHandlers from '\.\/cheerpj\/natives\/jaas\.js';\n/, 'const jaasNativeHandlers=mockJaasNativeHandlers;\n');
|
|
let responseText='';
|
|
const origin='https://demo.example.org:8181';
|
|
async function launch(path,version=11,opts={},testOptions={}){
|
|
const sent=[],called=[];
|
|
const context={URL,DOMParser,mockJaasNativeHandlers:{Java_com_sun_security_auth_module_UnixSystem_getUnixInfo:async()=>{}},
|
|
location:{href:origin+'/backend/hmi/cheerpj-runner.html'+(testOptions.diagMode?'?diagnose='+testOptions.diagMode:(testOptions.sysparamOn?'?sysparam=on':testOptions.sysparamOff?'?sysparam=off':'')),origin,hostname:'demo.example.org'},
|
|
document:{body:{classList:{add:()=>{}}},getElementById:()=>({textContent:'',className:'',getBoundingClientRect:()=>({width:960,height:640})})},
|
|
window:{parent:{postMessage:m=>sent.push(m)},addEventListener:(type,fn)=>{if(type==='message')context._handler=fn},
|
|
cheerpjInit:async(opts)=>called.push(['init',opts]),cheerpjCreateDisplay:(w,h)=>{assert.equal(w,-1);assert.equal(h,-1);called.push('display')},
|
|
cheerpjRunMain:async (...args)=>{called.push(['runMain',...args]);return 0},
|
|
cheerpjRunJar:async (...args)=>{called.push(['runJar',...args]);return 0},
|
|
cheerpjRunLibrary:async cp=>{
|
|
called.push(['library',cp]);
|
|
return {java:{nio:{file:{
|
|
Paths:{get:async path=>{called.push(['tempPath',path]);return {value:path}}},
|
|
Files:{
|
|
createDirectories:async (path,attributes)=>{
|
|
called.push(['tempMkdir',path.value,attributes]);
|
|
if(testOptions.failTemp || testOptions.blockNested && path.value==='/files/itac-workplace/tmp')throw Error(testOptions.failTemp?'Speicherplatz erschöpft':'Verzeichnis durch vorhandene Datei blockiert');
|
|
return path;
|
|
},
|
|
isDirectory:async (path,options)=>{
|
|
called.push(['tempIsDir',path.value,options]);
|
|
return testOptions.notDirectory ? false : true;
|
|
},
|
|
createTempFile:async (path,prefix,suffix,attributes)=>{
|
|
called.push(['tempProbe',path.value,prefix,suffix,attributes]);
|
|
if(testOptions.failTemp || testOptions.readOnly || testOptions.probeBlockNested && path.value==='/files/itac-workplace/tmp' || testOptions.blockAllSubdirs && path.value!=='/files')throw Error(testOptions.failTemp?'Speicherplatz erschöpft':testOptions.readOnly?'Schreiben nicht erlaubt':'Schreibtest fehlgeschlagen');
|
|
return {value:path.value+'/hmi-tmp-check-1.tmp'};
|
|
},
|
|
deleteIfExists:async path=>{called.push(['tempProbeRemove',path.value]);return true;}
|
|
}
|
|
}},lang:{System:{setProperty:async (key,value)=>{called.push(['setProperty',key,value]);return '/files';}}}},
|
|
com:{itac:{util:{system:{SysParameter:{
|
|
widgetWorkbenchJaasFallbackLevel:async()=>{
|
|
called.push(['sysparamPatchVerify']);
|
|
if(testOptions.sysparamPatchOriginal)throw Error('no method: widgetWorkbenchJaasFallbackLevel');
|
|
if(testOptions.sysparamPatchSignerConflict)throw Error('signer information does not match signer information of other classes in same package');
|
|
return testOptions.sysparamPatchWrongLevel ? 2 : 1;
|
|
}
|
|
}}}},sun:{security:{auth:{module:{UnixSystem:class {
|
|
constructor(){
|
|
if(testOptions.jaasFail==='proxy'){
|
|
// Java Throwable proxies do not necessarily expose JS toString or
|
|
// Symbol.toPrimitive: String(proxy) would mask the original exception.
|
|
const proxy=Object.create(null);
|
|
proxy.getClass=async()=>({getName:async()=> 'java.lang.UnsatisfiedLinkError'});
|
|
proxy.getMessage=async()=> 'no jaas in java.library.path: Missing import: JVM_LoadLibrary';
|
|
proxy.getCause=async()=>null;
|
|
throw proxy;
|
|
}
|
|
if(testOptions.jaasFail==='opaque')throw Object.create(null);
|
|
if(testOptions.jaasFail)throw Error('no jaas in java.library.path: Missing import: JVM_LoadLibrary');
|
|
}
|
|
async getUsername(){
|
|
if(testOptions.jaasUserProxy){
|
|
const proxy=Object.create(null);
|
|
proxy.equals=async value=>value==='cheerpj-client';
|
|
return proxy;
|
|
}
|
|
return 'cheerpj-client';
|
|
}
|
|
}}}}},widgetworkbench:{cheerpj:{WorkplaceResizeBridge:{
|
|
startRuntimeMonitor:async (w,h,mode)=>{
|
|
called.push(['windowMonitorStart',w,h,mode]);
|
|
if(testOptions.monitorUnsupported)throw Error('Java code still running, check for a missing await');
|
|
return 1;
|
|
},
|
|
// The following methods are Java-internal only and MUST NOT be called
|
|
// from JS while the Workplace main method is running.
|
|
resize:async()=>{throw Error('forbidden parallel JS resize call');},
|
|
diagnoseWindows:async()=>{throw Error('forbidden parallel JS diagnostic call');},
|
|
rescueOffscreenDialogs:async()=>{throw Error('forbidden parallel JS rescue call');}
|
|
}}}}};
|
|
},
|
|
},
|
|
parent:{postMessage:m=>sent.push(m)},
|
|
fetch:async (u,options={})=>{
|
|
if(u==='/backend/hmi/cheerpj/sysparameter-jaas-fallback-java11.jar'){
|
|
called.push(['sysparamProbe',u,options.headers?.Range]);
|
|
const status=testOptions.sysparamPatchMissing?404:testOptions.sysparamPatchNoRange?200:206;
|
|
return {ok:status<400,status,url:origin+u};
|
|
}
|
|
if(u==='/backend/hmi/cheerpj-libs/javax.json-1.1.4.jar'){
|
|
called.push(['jsonpProbe',u,options.headers?.Range]);
|
|
const status=testOptions.providerMissing?404:testOptions.providerNoRange?200:206;
|
|
return {ok:status<400,status,url:origin+u};
|
|
}
|
|
if(u==='/backend/hmi/cheerpj/natives/jaas.js'){
|
|
called.push(['jaasModuleProbe',u]);
|
|
const status=testOptions.nativeMissing?404:200;
|
|
return {ok:status<400,status,url:origin+u};
|
|
}
|
|
if(u==='/backend/hmi/cheerpj/jaas-identity-bridge.jar'){
|
|
called.push(['jaasBridgeProbe',u,options.headers?.Range]);
|
|
const status=testOptions.bridgeMissing?404:testOptions.bridgeNoRange?200:206;
|
|
return {ok:status<400,status,url:origin+u};
|
|
}
|
|
return {ok:true,status:200,url:u,text:async()=>responseText};
|
|
},
|
|
setInterval,clearInterval,Error,Promise,ResizeObserver:class { observe(){} disconnect(){} },
|
|
};
|
|
vm.createContext(context);vm.runInContext('(function(){\n'+source+'\n})()',context);
|
|
context._handler({source:context.window.parent,origin,data:{type:'hmi-cheerpj-launch',requestId:'test-1',jnlpUrl:path,javaVersion:version,...opts}});
|
|
for(let i=0;i<60&&!sent.some(s=>s.state==='finished'||s.state==='error');i++) await new Promise(r=>setTimeout(r,8));
|
|
return {end:sent.at(-1),called,sent};
|
|
}
|
|
responseText=`<?xml version="1.0"?><jnlp codebase="${origin}/jar/"><resources><jar href="app.jar"/><jar href="lib.jar"/></resources><application-desc main-class="com.demo.Main"><argument>HELLO</argument></application-desc></jnlp>`;
|
|
let result=await launch(origin+'/jnlp/start.jnlp');
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.equal(result.called.at(-1)[1],'com.demo.Main');
|
|
assert.equal(result.called.at(-1)[2],'/app/jar/app.jar:/app/jar/lib.jar');
|
|
assert.equal(result.called.at(-1)[3],'HELLO');
|
|
result=await launch('https://other.example.org/evil.jnlp');
|
|
assert.equal(result.end?.state,'error');
|
|
responseText='<jnlp><resources><jar href="a.jar"/></resources><application-desc/></jnlp>';
|
|
result=await launch(origin+'/jnlp/demo.jnlp');
|
|
assert.equal(result.end?.state,'finished');
|
|
assert.equal(result.called.at(-1)[0],'runJar');
|
|
responseText='<!DOCTYPE jnlp [ <!ENTITY x SYSTEM "file:///etc/passwd"> ]><jnlp/>';
|
|
result=await launch(origin+'/jnlp/demo.jnlp');
|
|
assert.equal(result.end?.state,'error');
|
|
// The provided iTAC Workplace file: codebase rewritten to fixed authenticated local bridge.
|
|
responseText=fs.readFileSync(new URL('../../backend/src/main/resources/hmi/Workplace.jnlp',import.meta.url),'utf8')
|
|
.replace('codebase="https://partner.itacsoftware.com:8181/mes/webstart/clients"',
|
|
'codebase="/backend/api/hmi/v1/cheerpj/workplace/jars"');
|
|
// The server rewrites the JNLP to include a verified MES JVM property.
|
|
responseText=responseText.replace('<resources>',
|
|
'<resources><property name="itac.artes.clusternodes" value="https://demo.example.org:8181/mes"/>');
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true,displayMode:'fit'});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.deepEqual(Array.from(result.called.find(c=>Array.isArray(c)&&c[0]==='init')[1].javaProperties),
|
|
['itac.artes.clusternodes=https://demo.example.org:8181/mes',
|
|
'java.io.tmpdir=/files',
|
|
'os.name=CheerpJ Browser',
|
|
'user.name=cheerpj-client',
|
|
'java.library.path=/app/backend/hmi/cheerpj/natives']);
|
|
const initIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='init');
|
|
const mkdirIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='tempMkdir');
|
|
const propIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='setProperty');
|
|
const runIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='runMain');
|
|
assert.ok(initIndex>=0&&mkdirIndex>initIndex&&propIndex>mkdirIndex&&runIndex>propIndex,
|
|
'Java-Temp-Ordner muss vor dem Workplace-Start erzeugt werden.');
|
|
assert.equal(result.called[mkdirIndex][1],'/files/itac-workplace/tmp');
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='tempIsDir'), 'Keine fehleranfällige Java-Boolean-Umwandlung verwenden.');
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='setProperty'&&c[1]==='java.io.tmpdir'&&c[2]==='/files/itac-workplace/tmp'));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='tempProbe'&&c[1]==='/files/itac-workplace/tmp'));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='tempProbeRemove'));
|
|
|
|
assert.equal(result.called.filter(c=>Array.isArray(c)&&c[0]==='library').length,1,'CheerpJ Library Mode must run only once');
|
|
assert.ok(result.called.find(c=>Array.isArray(c)&&c[0]==='library')[1].includes('/app/jar/app.jar')===false);
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='library'&&c[1].endsWith('workplace-window-monitor-v3.jar')));
|
|
assert.equal(typeof result.called.find(c=>Array.isArray(c)&&c[0]==='init')[1].natives.Java_com_sun_security_auth_module_UnixSystem_getUnixInfo,'function');
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'&&c[2].endsWith('workplace-window-monitor-v3.jar')));
|
|
const workplaceCall=result.called.find(c=>Array.isArray(c)&&c[0]==='runMain');
|
|
assert.equal(workplaceCall[1],'com.itac.mes.suite.presentation.MesSuiteFrameWebstartLauncher');
|
|
assert.equal(workplaceCall[3],'itac.appid=Workplace');
|
|
assert.ok(result.called.find(c=>c[0]==='init')[1].javaProperties.includes('os.name=CheerpJ Browser'));
|
|
assert.ok(result.called.find(c=>c[0]==='init')[1].javaProperties.includes('user.name=cheerpj-client'));
|
|
|
|
assert.ok(result.called.some(c=>c[0]==='setProperty'&&c[1]==='os.name'&&c[2]==='CheerpJ Browser'));
|
|
assert.ok(result.called.some(c=>c[0]==='setProperty'&&c[1]==='user.name'&&c[2]==='cheerpj-client'));
|
|
assert.ok(result.called.findIndex(c=>c[0]==='setProperty'&&c[1]==='os.name')<runIndex);
|
|
|
|
assert.equal(workplaceCall[2].split(':').length,132);
|
|
assert.ok(!result.called.some(c=>c[0]==='sysparamPatchVerify'));
|
|
assert.ok(!result.called.some(c=>c[0]==='sysparamProbe'));
|
|
assert.match(workplaceCall[2],/\/app\/backend\/hmi\/cheerpj-libs\/javax\.json-1\.1\.4\.jar/);
|
|
assert.match(workplaceCall[2],/\/app\/backend\/hmi\/cheerpj\/jaas-identity-bridge\.jar/);
|
|
assert.ok(result.called.some(c=>c[0]==='jaasModuleProbe'));
|
|
assert.ok(result.called.some(c=>c[0]==='jaasBridgeProbe'&&c[2]==='bytes=0-0'));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='jsonpProbe'&&c[2]==='bytes=0-0'));
|
|
const probeIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='jsonpProbe');
|
|
assert.ok(probeIndex>=0&&probeIndex<runIndex,'JSON-P Range-Probe muss vor main() erfolgen.');
|
|
assert.match(result.sent.find(s=>s.state==='running')?.message||'',/RXTX/);
|
|
// JAAS-fallback isolation and fail-closed signed-JAR compatibility diagnostics.
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{sysparamOn:true,sysparamPatchMissing:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/SysParameter-JAAS-Fallback-JAR.*404/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{sysparamOn:true,sysparamPatchNoRange:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/SysParameter-JAAS-Fallback-JAR.*200/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{sysparamOn:true,sysparamPatchOriginal:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/no method: widgetWorkbenchJaasFallbackLevel/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{sysparamOn:true,sysparamPatchSignerConflict:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/signer information does not match/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{sysparamOn:true,sysparamPatchWrongLevel:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/Unerwartete SysParameter-Patchversion/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{sysparamOff:true});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.equal(result.called.filter(c=>c[0]==='sysparamProbe').length,0);
|
|
assert.equal(result.called.filter(c=>c[0]==='sysparamPatchVerify').length,0);
|
|
assert.ok(result.called.find(c=>c[0]==='runMain')[2].startsWith('/app/backend/api/hmi/v1/cheerpj/workplace/jars/'));
|
|
// New WindowGeometry checks: readonly by default; opt-in repair only on request.
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true,windowMode:'diagnose'});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='windowMonitorStart'&&c[1]===960&&c[2]===640&&c[3]==='diagnose'));
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&['resize','windowSnapshot','windowRescue'].includes(c[0])));
|
|
assert.ok(result.called.findIndex(c=>Array.isArray(c)&&c[0]==='windowMonitorStart')<result.called.findIndex(c=>Array.isArray(c)&&c[0]==='runMain'),
|
|
'Java-Monitor muss vor main() gestartet sein.');
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true,windowMode:'rescue'});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='windowMonitorStart'&&c[3]==='rescue'));
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&['resize','windowSnapshot','windowRescue'].includes(c[0])));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true,windowMode:'off'});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='windowMonitorStart'&&c[3]==='off'));
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&['resize','windowSnapshot','windowRescue'].includes(c[0])));
|
|
// If the optional Java monitor cannot be started, the vendor main must still run.
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true,windowMode:'diagnose'},{monitorUnsupported:true});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
|
|
assert.match(result.sent.find(s=>s.state==='running')?.message||'',/Fenstermonitor nicht verfügbar/);
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{diagMode:'jaas-only'});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.match(result.end.message,/JAAS UnixSystem erfolgreich initialisiert/);
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
|
|
assert.equal(result.called.filter(c=>Array.isArray(c)&&c[0]==='library').length,1);
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{diagMode:'jaas-only',jaasFail:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/JAAS-Laufzeittest fehlgeschlagen/);
|
|
assert.match(result.end.message,/JVM_LoadLibrary/);
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
|
|
// Java/CheerpJ proxy exceptions must retain their original diagnostic text.
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{diagMode:'jaas-only',jaasFail:'proxy'});
|
|
assert.equal(result.end?.state,'error',JSON.stringify(result.end));
|
|
assert.match(result.end.message,/java\.lang\.UnsatisfiedLinkError/);
|
|
assert.match(result.end.message,/JVM_LoadLibrary/);
|
|
assert.match(result.end.message,/UnixSystem-Konstruktor/);
|
|
assert.doesNotMatch(result.end.message,/Cannot convert object to primitive value/);
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{diagMode:'jaas-only',jaasFail:'opaque'});
|
|
assert.equal(result.end?.state,'error',JSON.stringify(result.end));
|
|
assert.match(result.end.message,/CheerpJ-Java-Exception/);
|
|
assert.doesNotMatch(result.end.message,/Cannot convert object to primitive value/);
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{diagMode:'jaas-only',jaasUserProxy:true});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{nativeMissing:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end?.message||'',/JAAS-Kompatibilitätsmodul.*404/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{bridgeMissing:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end?.message||'',/JAAS-Java-Hilfsklasse.*404/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{bridgeNoRange:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end?.message||'',/JAAS-Java-Hilfsklasse.*200/);
|
|
assert.ok(!result.called.some(c=>c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{providerMissing:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/JSON-P-Provider.*404/);
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{providerNoRange:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/JSON-P-Provider.*200/);
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{failTemp:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/Temp-Verzeichnis.*Speicherplatz erschöpft/);
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'),
|
|
'Workplace darf nicht ohne benutzbaren Temp-Ordner starten.');
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{notDirectory:true});
|
|
assert.equal(result.end?.state,'finished', 'isDirectory darf nicht mehr fälschlich den Start blockieren.');
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='tempProbe'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{blockNested:true});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='setProperty'&&c[2]==='/files/itac-workplace-tmp'));
|
|
assert.match(result.sent.find(s=>s.state==='running')?.message||'',/Ausweichverzeichnis/);
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{blockAllSubdirs:true});
|
|
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
|
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='setProperty'&&c[2]==='/files'));
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='tempMkdir'&&c[1]==='/files'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{readOnly:true});
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end.message,/Schreiben nicht erlaubt/);
|
|
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
|
|
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',8);
|
|
assert.equal(result.end?.state,'error');
|
|
assert.match(result.end?.message||'',/Java 11/);
|
|
// An HTTP host is supported when the JNLP and browser have exactly the same origin.
|
|
const httpUrl='http://mes.internal:8181';
|
|
const httpContext={ URL,location:{href:httpUrl+'/backend/hmi/cheerpj-runner.html',origin:httpUrl,hostname:'mes.internal'} };
|
|
const m=source.match(/const trusted=([\s\S]*?);\nfunction readManifest/);
|
|
assert.ok(m,'trusted URL helper present');
|
|
const resolveTrusted=vm.runInNewContext('('+m[1]+')',httpContext);
|
|
assert.equal(resolveTrusted('/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp').protocol,'http:');
|
|
assert.throws(()=>resolveTrusted('http://evil.example.com/x.jnlp'),/Origin/);
|
|
assert.throws(()=>resolveTrusted('https://mes.internal:8181/mes/x.jnlp'),/Origin/);
|
|
const backend=fs.readFileSync(new URL('../../backend/src/main/java/com/workbenchclassic/hmi/HmiWorkplaceProxyResource.java',import.meta.url),'utf8');
|
|
assert.match(backend,/HmiImsapiGateway\.targetOrigin\(request\)/);
|
|
assert.doesNotMatch(backend,/private static final String BASE = "https:\/\/partner/);
|
|
assert.ok(fs.statSync(new URL('../public/cheerpj/workplace-window-monitor-v3.jar',import.meta.url)).size>1000);
|
|
assert.doesNotMatch(source,/async function attachWorkplaceResize\(/, 'Remove concurrent JS resize loop');
|
|
assert.doesNotMatch(source,/async function attachWorkplaceWindowMonitor\(/, 'Remove concurrent JS diagnostic loop');
|
|
console.log('CheerpJ contracts: JNLP, HTTP same-origin, iTAC 129 JARs, Java11 JVM-internal WindowGeometry monitor diagnose/rescue/off, temp directory and startup ordering validated.');
|