Workplace Widget 5.10.23
This commit is contained in:
27
hmi-frontend/tests/cheerpj-jaas-native.mjs
Normal file
27
hmi-frontend/tests/cheerpj-jaas-native.mjs
Normal file
@@ -0,0 +1,27 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import jaas from '../public/cheerpj/natives/jaas.js';
|
||||
|
||||
const call = jaas.Java_com_sun_security_auth_module_UnixSystem_getUnixInfo;
|
||||
assert.equal(typeof call, 'function');
|
||||
const unixSystem = { identity: null };
|
||||
let invocations = 0;
|
||||
const lib = { com: { widgetworkbench: { cheerpj: {
|
||||
JaasIdentityBridge: {
|
||||
populate: async (instance) => {
|
||||
assert.strictEqual(instance, unixSystem);
|
||||
instance.identity = 'cheerpj-client';
|
||||
invocations++;
|
||||
return 'cheerpj-client';
|
||||
},
|
||||
},
|
||||
}}}};
|
||||
await call(lib, unixSystem);
|
||||
assert.equal(invocations, 1);
|
||||
assert.equal(unixSystem.identity, 'cheerpj-client');
|
||||
await assert.rejects(call(null, unixSystem), /missing native context/);
|
||||
await assert.rejects(call({}, unixSystem), /Cannot read|not on the Workplace classpath/);
|
||||
await assert.rejects(call({com:{widgetworkbench:{cheerpj:{JaasIdentityBridge:{populate:async()=> 'root'}}}}},unixSystem), /unexpected identity/);
|
||||
const jar = new URL('../public/cheerpj/jaas-identity-bridge.jar', import.meta.url);
|
||||
assert.ok(fs.statSync(jar).size > 1000);
|
||||
console.log('CheerpJ JAAS native helper contracts: isolated implementation, no vendor modification, synthetic username only.');
|
||||
@@ -25,46 +25,115 @@ class DOMParser {
|
||||
return {documentElement:root,getElementsByTagName:tag=>tag==='parsererror'?[]:root.getElementsByTagName(tag)};
|
||||
}
|
||||
}
|
||||
const source=fs.readFileSync(new URL('../public/cheerpj-runner.js',import.meta.url),'utf8');
|
||||
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,
|
||||
location:{href:origin+'/backend/hmi/cheerpj-runner.html',origin,hostname:'demo.example.org'},
|
||||
// A trusted, same-origin WidgetWorkbench parent responds to a one-shot request.
|
||||
const parentProxy={postMessage:m=>{
|
||||
sent.push(m);
|
||||
if(m.type==='hmi-cheerpj-credential-request'){
|
||||
const reply=testOptions.handoff
|
||||
? {type:'hmi-cheerpj-credentials',requestId:m.requestId,...testOptions.handoff}
|
||||
: {type:'hmi-cheerpj-credentials-unavailable',requestId:m.requestId};
|
||||
queueMicrotask(()=>context._handler({source:parentProxy,origin,data:reply}));
|
||||
}
|
||||
}};
|
||||
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:''),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},
|
||||
window:{parent:parentProxy,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]);
|
||||
if(cp==='')return {java:{nio:{file:{
|
||||
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)throw Error('Speicherplatz erschöpft');
|
||||
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;
|
||||
return testOptions.notDirectory ? false : true;
|
||||
},
|
||||
createTempFile:async (path,prefix,suffix,attributes)=>{
|
||||
called.push(['tempProbe',path.value,prefix,suffix,attributes]);
|
||||
if(testOptions.readOnly)throw Error('Schreiben nicht erlaubt');
|
||||
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;}
|
||||
}
|
||||
}}}};
|
||||
return {com:{widgetworkbench:{cheerpj:{WorkplaceResizeBridge:{resize:async (w,h)=>{called.push(['resize',w,h]);return 1}}}}}};
|
||||
}},lang:{System:{setProperty:async (key,value)=>{called.push(['setProperty',key,value]);return '/files';}}}},
|
||||
com:{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:{WorkplaceCredentialBridge:{
|
||||
offer:async(user,pass,client)=>{called.push(['credentialOffer',user==='tester',pass==='secret123',client]);return testOptions.offerRejected?0:1;}
|
||||
},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=>({ok:true,status:200,url:u,text:async()=>responseText}),
|
||||
setInterval,clearInterval,Error,Promise,ResizeObserver:class { observe(){} disconnect(){} },
|
||||
parent:parentProxy,
|
||||
fetch:async (u,options={})=>{
|
||||
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/workplace-credential-bridge.jar'){
|
||||
called.push(['credentialBridgeProbe',u,options.headers?.Range]);
|
||||
return {ok:true,status:testOptions.credentialBridgeMissing?404:206,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,setTimeout,clearTimeout,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}});
|
||||
@@ -97,33 +166,117 @@ result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp'
|
||||
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/itac-workplace/tmp']);
|
||||
'java.io.tmpdir=/files',
|
||||
'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&&runIndex>mkdirIndex,
|
||||
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'&&c[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.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='library'&&c[1].endsWith('workplace-resize-bridge-v2.jar')));
|
||||
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'&&c[2].endsWith('workplace-resize-bridge-v2.jar')));
|
||||
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-v4.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-v4.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.equal(workplaceCall[2].split(':').length,130);
|
||||
assert.equal(workplaceCall[2].split(':').length,133);
|
||||
assert.match(workplaceCall[2],/workplace-credential-bridge\.jar/);
|
||||
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/);
|
||||
// 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,'error');
|
||||
assert.match(result.end.message,/kein Verzeichnis/);
|
||||
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
|
||||
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/);
|
||||
@@ -143,5 +296,38 @@ 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-resize-bridge-v2.jar',import.meta.url)).size>1000);
|
||||
console.log('CheerpJ contracts: JNLP, HTTP same-origin, iTAC 129 JARs, writable virtual temp directory and startup ordering validated.');
|
||||
assert.ok(fs.statSync(new URL('../public/cheerpj/workplace-window-monitor-v4.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.');
|
||||
|
||||
// V5.10.23: a trusted parent can offer credentials exactly once, before main().
|
||||
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"')
|
||||
.replace('<resources>', '<resources><property name="itac.artes.clusternodes" value="'+origin+'/mes"/>');
|
||||
const credentials={username:'tester',password:'secret123',client:'any'};
|
||||
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,
|
||||
{workplace:true,browserCredentials:true},{handoff:credentials});
|
||||
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
|
||||
assert.equal(result.sent.filter(m=>m.type==='hmi-cheerpj-credential-request').length,1);
|
||||
assert.ok(result.called.some(c=>c[0]==='credentialBridgeProbe'&&c[2]==='bytes=0-0'));
|
||||
assert.ok(result.called.some(c=>c[0]==='credentialOffer'&&c[1]&&c[2]&&c[3]==='any'));
|
||||
assert.ok(result.called.findIndex(c=>c[0]==='credentialOffer')<result.called.findIndex(c=>c[0]==='runMain'));
|
||||
assert.ok(result.called.findIndex(c=>c[0]==='credentialOffer')<result.called.findIndex(c=>c[0]==='windowMonitorStart'));
|
||||
const directNatives=result.called.find(c=>Array.isArray(c)&&c[0]==='init')[1].natives;
|
||||
assert.equal(typeof directNatives.Java_com_widgetworkbench_cheerpj_WorkplaceCredentialBridge_nativeReport,'function');
|
||||
await directNatives.Java_com_widgetworkbench_cheerpj_WorkplaceCredentialBridge_nativeReport(null,null,1);
|
||||
assert.ok(result.sent.some(m=>m.type==='hmi-cheerpj-auth-result'&&m.code===1));
|
||||
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,
|
||||
{workplace:true,browserCredentials:true});
|
||||
assert.equal(result.end?.state,'finished');
|
||||
assert.ok(!result.called.some(c=>c[0]==='credentialOffer'));
|
||||
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,
|
||||
{workplace:true,browserCredentials:true},{handoff:credentials,credentialBridgeMissing:true});
|
||||
assert.equal(result.end?.state,'finished');
|
||||
assert.ok(!result.called.some(c=>c[0]==='credentialOffer'));
|
||||
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,
|
||||
{workplace:true,browserCredentials:true},{handoff:credentials,offerRejected:true});
|
||||
assert.equal(result.end?.state,'finished');
|
||||
console.info('V5.10.23 one-shot credential handoff, JNI auth result, unavailable bridge, offer failure: passed.');
|
||||
|
||||
50
hmi-frontend/tests/cheerpj-window-runtime.mjs
Normal file
50
hmi-frontend/tests/cheerpj-window-runtime.mjs
Normal file
@@ -0,0 +1,50 @@
|
||||
/** Standalone Workplace launch and CheerpJ runtime allowlist regression checks. */
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const read = rel => fs.readFileSync(new URL(rel, import.meta.url), 'utf8');
|
||||
const html = read('../public/cheerpj-runner.html');
|
||||
const js = read('../public/cheerpj-runner.js').replace(/^import jaasNativeHandlers from '\.\/cheerpj\/natives\/jaas\.js';\n/, 'const jaasNativeHandlers=mockJaasNativeHandlers;\n');
|
||||
const widget = read('../src/widgets/CheerpJWidget.vue');
|
||||
const css = read('../src/style.css');
|
||||
assert.match(html, /requested === '4\.3' \? '4\.3' : '5\.0'/,
|
||||
'Only the fixed 4.3/5.0 versions may be selected');
|
||||
assert.match(html, /cjrtnc\.leaningtech\.com/);
|
||||
assert.match(html, /body\.cheerpj-standalone #state/);
|
||||
assert.match(widget, /standalone=workplace&runtime=/);
|
||||
assert.match(widget, /Fensterdiagnose/);
|
||||
assert.match(widget, /windowMode:windowMode\.value/);
|
||||
assert.match(html, /id="window-diagnostics"/);
|
||||
assert.match(widget, /rel="noopener noreferrer"/);
|
||||
assert.match(widget, /CheerpJ Laufzeitversion/);
|
||||
assert.match(widget, /workplace\.value \? '5\.0' : '4\.3'/, 'Do not change the runtime of ordinary widgets');
|
||||
assert.match(widget, /:src="frameSrc"/);
|
||||
assert.match(css, /cheerpj-open-window/);
|
||||
|
||||
async function runStandalone(query) {
|
||||
const local = 'https://mes.internal:8181';
|
||||
const classNames = [];
|
||||
const fetched = [];
|
||||
const status = {textContent:'',className:''};
|
||||
const context = {
|
||||
URL, Error, Promise, setInterval, clearInterval, mockJaasNativeHandlers:{},
|
||||
location:{href:local+'/backend/hmi/cheerpj-runner.html'+query,origin:local},
|
||||
document:{getElementById:id=>status,body:{classList:{add:n=>classNames.push(n)}}},
|
||||
fetch:async url=>{fetched.push(url);return {ok:false,status:503,url}},
|
||||
window:{addEventListener:()=>{}}
|
||||
};
|
||||
context.window.parent = context.window;
|
||||
vm.runInNewContext(js,context);
|
||||
await new Promise(resolve=>setTimeout(resolve,5));
|
||||
return {fetched,classNames,status};
|
||||
}
|
||||
const launched = await runStandalone('?standalone=workplace&runtime=5.0&jnlpUrl=https://evil.example/payload.jnlp');
|
||||
assert.deepEqual(launched.fetched, [
|
||||
'https://mes.internal:8181/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp'
|
||||
]);
|
||||
assert.ok(launched.classNames.includes('cheerpj-standalone'));
|
||||
assert.match(launched.status.textContent,/HTTP 503/);
|
||||
const idle=await runStandalone('?standalone=unknown');
|
||||
assert.deepEqual(idle.fetched,[]);
|
||||
console.log('CheerpJ standalone window, fixed JNLP endpoint, and 4.3/5.0 runtime option tests passed.');
|
||||
20
hmi-frontend/tests/login-contrast.mjs
Normal file
20
hmi-frontend/tests/login-contrast.mjs
Normal file
@@ -0,0 +1,20 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import assert from 'node:assert/strict';
|
||||
const css = readFileSync(new URL('../src/style.css', import.meta.url), 'utf8');
|
||||
const themeCss = readFileSync(new URL('../src/ios-widget.css', import.meta.url), 'utf8');
|
||||
const neonCss = readFileSync(new URL('../src/workbench-neon.css', import.meta.url), 'utf8');
|
||||
const rule = css.match(/\.hmi-diagnostic-notice \.hmi-mes-login input\s*\{([^}]+)\}/)?.[1];
|
||||
assert.ok(rule, 'Scoped IMSAPI input CSS is present');
|
||||
for (const expected of ['background:var(--input)', 'color:var(--text)', 'caret-color:var(--text)', 'border:1px solid var(--line)']) {
|
||||
assert.ok(rule.includes(expected), `Missing contrast rule: ${expected}`);
|
||||
}
|
||||
assert.ok(!rule.includes('color:inherit'), 'Login text must not inherit label color');
|
||||
assert.match(css, /\.hmi-diagnostic-notice \.hmi-mes-login input::placeholder\{color:var\(--muted\)/);
|
||||
assert.match(css, /\.hmi-diagnostic-notice \.hmi-mes-login input:focus-visible/);
|
||||
assert.match(css, /-webkit-text-fill-color:var\(--text\)/);
|
||||
assert.match(css, /-webkit-box-shadow:0 0 0 1000px var\(--input\) inset/);
|
||||
assert.match(css, /\.shell\.ios \.hmi-mes-login input,\.shell\.light \.hmi-mes-login input\{color-scheme:light\}/);
|
||||
assert.match(css, /\.shell\.dark \.hmi-mes-login input,\.shell\.neon \.hmi-mes-login input\{color-scheme:dark\}/);
|
||||
assert.match(themeCss, /\.shell\.ios\s*\{[^}]*--input:#fff/);
|
||||
assert.match(neonCss, /--input:#0e1b25/);
|
||||
console.log('OK: IMSAPI login contrast, focus, placeholder, and autofill styles');
|
||||
141
hmi-frontend/tests/native-loader-smoke.mjs
Normal file
141
hmi-frontend/tests/native-loader-smoke.mjs
Normal file
@@ -0,0 +1,141 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const base = new URL('../public/', import.meta.url);
|
||||
const html = fs.readFileSync(new URL('cheerpj-native-loader-test.html', base), 'utf8');
|
||||
const js = fs.readFileSync(new URL('cheerpj-native-loader-test.js', base), 'utf8');
|
||||
const native = fs.readFileSync(new URL('cheerpj/natives/wwprobe.js', base), 'utf8');
|
||||
const java = fs.readFileSync(new URL('../../hmi-docs/cheerpj/NativeLoaderSmoke.java', base), 'utf8');
|
||||
const jarFile = fileURLToPath(new URL('cheerpj/jaas-native-loader-smoke.jar', base));
|
||||
const bridgeJar = fileURLToPath(new URL('cheerpj/jaas-identity-bridge.jar', base));
|
||||
|
||||
assert.ok(fs.statSync(jarFile).size > 1500);
|
||||
assert.ok(fs.statSync(bridgeJar).size > 1000);
|
||||
assert.match(html, /id="modes"/);
|
||||
assert.match(html, /id="runtime-links"/);
|
||||
assert.match(html, /id="copy-report"/);
|
||||
assert.doesNotMatch(html, /<script src="https:\/\/cjrtnc/); // Only one selected CheerpJ runtime is loaded.
|
||||
assert.match(js, /version:\s*11/);
|
||||
assert.match(js, /java\.library\.path=/);
|
||||
assert.match(js, /cheerpjRunMain/);
|
||||
assert.ok(js.includes("params.get('runtime') === '4.3'"));
|
||||
assert.match(js, /System\.loadLibrary\/UnixSystem ist dadurch NICHT repariert/);
|
||||
assert.match(native, /Java_com_widgetworkbench_cheerpj_NativeLoaderSmoke_ping/);
|
||||
assert.match(java, /System\.loadLibrary\(mode\)/);
|
||||
assert.match(java, /"direct"/);
|
||||
assert.match(java, /"bridge"/);
|
||||
assert.match(java, /"unix"/);
|
||||
assert.match(java, /"environment"/);
|
||||
assert.match(java, /"sysprop"/);
|
||||
assert.match(java, /Unsafe/);
|
||||
assert.doesNotMatch(java, /System\.out\.println\([^\n]*\+\s*user\s*\)/);
|
||||
for(const entry of [
|
||||
{jar:jarFile, clazz:'com.widgetworkbench.cheerpj.NativeLoaderSmoke'},
|
||||
{jar:bridgeJar, clazz:'com.widgetworkbench.cheerpj.JaasIdentityBridge'},
|
||||
]) {
|
||||
const javap = execFileSync('javap', ['-verbose', '-cp', entry.jar, entry.clazz], {encoding:'utf8'});
|
||||
assert.match(javap, /major version: 55/); // Java 11 classfile
|
||||
}
|
||||
|
||||
// Contract tests, not real browser/JVM. Verify the Java-11 runtime settings and
|
||||
// that no direct natives handler is supplied to System.loadLibrary tests.
|
||||
async function launch(mode, { runtime='5.0', path='normal', rangeStatus=206, javaExit=0,
|
||||
moduleMime='text/javascript', dynamicLoader=false, blockedLoader=false }={}) {
|
||||
const output = { textContent: '' };
|
||||
const calls = [];
|
||||
const wwprobeNativeHandlers = { Java_com_widgetworkbench_cheerpj_NativeLoaderSmoke_ping() { return 42; } };
|
||||
const content = js
|
||||
.replace(/import wwprobeNativeHandlers from '\.\/cheerpj\/natives\/wwprobe\.js';/,
|
||||
'const wwprobeNativeHandlers=globalThis.__nativeHandlers;')
|
||||
.replace('run().catch(error => {', 'globalThis.__runPromise=run().catch(error => {');
|
||||
let scriptRequested = null;
|
||||
const context = {
|
||||
__nativeHandlers: wwprobeNativeHandlers,
|
||||
navigator: {clipboard:{writeText:async()=>{}}},
|
||||
document: {
|
||||
getElementById: id => id==='result' ? output : null,
|
||||
createElement: name => {
|
||||
assert.equal(name, 'script');
|
||||
scriptRequested = {src:'',onload:null,onerror:null};
|
||||
return scriptRequested;
|
||||
},
|
||||
head: {appendChild: script=>{
|
||||
calls.push(['script',script.src]);
|
||||
if(blockedLoader) script.onerror();
|
||||
else {
|
||||
context.cheerpjInit = async opts=>{calls.push(['init', opts]);};
|
||||
script.onload();
|
||||
}
|
||||
}},
|
||||
},
|
||||
location: {href: 'https://company.example/backend/hmi/cheerpj-native-loader-test.html?mode=' + mode + '&runtime=' + runtime + '&path=' + path},
|
||||
URL,
|
||||
console: {info() {}, error() {}},
|
||||
fetch: async (url, opts) => {
|
||||
calls.push(['fetch', url, opts]);
|
||||
const isJar = url.endsWith('.jar');
|
||||
const status = isJar ? rangeStatus : 200;
|
||||
return {
|
||||
ok: status >= 200 && status < 300, status,
|
||||
headers: {get: name => {
|
||||
if (name==='content-type') return isJar?'application/java-archive':moduleMime;
|
||||
if (name==='content-range') return isJar && status===206 ? 'bytes 0-0/4821' : null;
|
||||
if (name==='accept-ranges') return isJar ? 'bytes' : null;
|
||||
return null;
|
||||
}},
|
||||
text: async () => 'export default { async Java_com_widgetworkbench_cheerpj_NativeLoaderSmoke_ping(){} }',
|
||||
};
|
||||
},
|
||||
cheerpjRunMain: async (...args) => {calls.push(['main', args]); return javaExit;},
|
||||
};
|
||||
if(!dynamicLoader) context.cheerpjInit = async opts => {calls.push(['init', opts]);};
|
||||
vm.runInNewContext(content, context, {filename:'cheerpj-native-loader-test.js'});
|
||||
await context.__runPromise;
|
||||
return { calls, output:output.textContent, scriptRequested };
|
||||
}
|
||||
|
||||
for (const mode of ['environment','sysprop','direct','wwprobe','jaas','unix','bridge']) {
|
||||
const {calls, output} = await launch(mode);
|
||||
const init = calls.find(c => c[0] === 'init')?.[1];
|
||||
const main = calls.find(c => c[0] === 'main')?.[1];
|
||||
assert.equal(init.version, 11, mode);
|
||||
assert.equal(main[2], mode, mode);
|
||||
assert.equal(main[0], 'com.widgetworkbench.cheerpj.NativeLoaderSmoke');
|
||||
assert.ok(Array.from(init.javaProperties).includes('java.library.path=/app/backend/hmi/cheerpj/natives'));
|
||||
assert.match(output, /TESTERGEBNIS: PASS/);
|
||||
if (mode === 'direct') {
|
||||
assert.equal(typeof init.natives.Java_com_widgetworkbench_cheerpj_NativeLoaderSmoke_ping, 'function');
|
||||
assert.match(output, /Direct JNI funktioniert/);
|
||||
} else {
|
||||
assert.equal(init.natives, undefined, 'Direct registration must only be used in direct mode.');
|
||||
}
|
||||
if (mode === 'bridge') {
|
||||
assert.match(main[1], /jaas-native-loader-smoke\.jar:.*jaas-identity-bridge\.jar/);
|
||||
assert.match(output, /Java-Bridge funktioniert OHNE UnixSystem-Konstruktor/);
|
||||
} else {
|
||||
assert.doesNotMatch(main[1], /jaas-identity-bridge\.jar/);
|
||||
}
|
||||
assert.equal(calls.filter(c=>c[0]==='fetch' && c[1].endsWith('.jar')).length, mode==='bridge'?2:1);
|
||||
}
|
||||
|
||||
// Optional CheerpJ 4.3 comparison is still running Java 11 (not Java 17).
|
||||
const versionCompare = await launch('wwprobe', {runtime:'4.3', dynamicLoader:true});
|
||||
assert.equal(versionCompare.calls.find(c=>c[0]==='script')[1], 'https://cjrtnc.leaningtech.com/4.3/loader.js');
|
||||
assert.equal(versionCompare.calls.find(c=>c[0]==='init')[1].version, 11);
|
||||
const failedExit = await launch('wwprobe', {javaExit:31});
|
||||
assert.match(failedExit.output,/TESTERGEBNIS: FAIL/);
|
||||
const missingRange = await launch('bridge', {rangeStatus:200});
|
||||
assert.match(missingRange.output,/TESTABBRUCH: Java-JAR unterstützt keinen HTTP-Range-Abruf/);
|
||||
assert.ok(!missingRange.calls.some(c=>c[0]==='init'));
|
||||
const invalidMime = await launch('wwprobe', {moduleMime:'text/html'});
|
||||
assert.match(invalidMime.output,/TESTABBRUCH: JS-Native-Modul fehlt/);
|
||||
const missingPath = await launch('wwprobe', {path:'missing'});
|
||||
assert.ok(Array.from(missingPath.calls.find(c=>c[0]==='init')[1].javaProperties)
|
||||
.some(s=>s.endsWith('/absichtlich-nicht-vorhanden')));
|
||||
const blockedCdn = await launch('environment',{dynamicLoader:true,blockedLoader:true});
|
||||
assert.match(blockedCdn.output,/TESTABBRUCH: CheerpJ-Loader nicht erreichbar/);
|
||||
assert.ok(!blockedCdn.calls.some(c=>c[0]==='init'));
|
||||
console.log('CheerpJ V5.10.22 Java11 diagnostics: 7 modes, 4.3 vs 5.0, classfile55, JNI isolation, Range, MIME, and error paths validated.');
|
||||
27
hmi-frontend/tests/workplace-handoff.mjs
Normal file
27
hmi-frontend/tests/workplace-handoff.mjs
Normal file
@@ -0,0 +1,27 @@
|
||||
import assert from 'node:assert/strict';
|
||||
globalThis.window={location:{protocol:'https:',hostname:'mes.example.test'}};
|
||||
const {offerWorkplaceCredentials,takeWorkplaceCredentials,clearWorkplaceCredentials}=await import('../src/workplaceHandoff.ts');
|
||||
clearWorkplaceCredentials();
|
||||
assert.equal(takeWorkplaceCredentials(),null);
|
||||
offerWorkplaceCredentials('tester','secret123','any');
|
||||
assert.deepEqual(takeWorkplaceCredentials(),{username:'tester',password:'secret123',client:'any'});
|
||||
assert.equal(takeWorkplaceCredentials(),null,'must be single use');
|
||||
offerWorkplaceCredentials('tester','secret123','any');
|
||||
clearWorkplaceCredentials();
|
||||
assert.equal(takeWorkplaceCredentials(),null,'logout must discard offer');
|
||||
globalThis.window.location.protocol='http:';
|
||||
offerWorkplaceCredentials('tester','secret123','any');
|
||||
assert.equal(takeWorkplaceCredentials(),null,'no HTTP credential forwarding');
|
||||
globalThis.window.location.protocol='https:';
|
||||
const original=Date.now;
|
||||
try{
|
||||
let now=1_000_000;Date.now=()=>now;
|
||||
offerWorkplaceCredentials('tester','secret123','any');
|
||||
now+=120_001;
|
||||
assert.equal(takeWorkplaceCredentials(),null,'expired secrets must not be offered');
|
||||
}finally{Date.now=original;clearWorkplaceCredentials();}
|
||||
offerWorkplaceCredentials('tester','secret123','any');
|
||||
offerWorkplaceCredentials('second','anotherSecret','special');
|
||||
assert.deepEqual(takeWorkplaceCredentials(),{username:'second',password:'anotherSecret',client:'special'},'new login replaces old login');
|
||||
assert.equal(takeWorkplaceCredentials(),null);
|
||||
console.info('V5.10.23 credential-only-memory handoff: single-use, expiry, logout, HTTP block, replacement validated.');
|
||||
Reference in New Issue
Block a user