Update
This commit is contained in:
@@ -33,20 +33,10 @@ let responseText='';
|
||||
const origin='https://demo.example.org:8181';
|
||||
async function launch(path,version=11,opts={},testOptions={}){
|
||||
const sent=[],called=[];
|
||||
// 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'},
|
||||
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:parentProxy,addEventListener:(type,fn)=>{if(type==='message')context._handler=fn},
|
||||
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},
|
||||
@@ -72,7 +62,14 @@ async function launch(path,version=11,opts={},testOptions={}){
|
||||
deleteIfExists:async path=>{called.push(['tempProbeRemove',path.value]);return true;}
|
||||
}
|
||||
}},lang:{System:{setProperty:async (key,value)=>{called.push(['setProperty',key,value]);return '/files';}}}},
|
||||
com:{sun:{security:{auth:{module:{UnixSystem:class {
|
||||
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
|
||||
@@ -94,9 +91,7 @@ async function launch(path,version=11,opts={},testOptions={}){
|
||||
}
|
||||
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:{
|
||||
}}}}},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');
|
||||
@@ -110,8 +105,13 @@ async function launch(path,version=11,opts={},testOptions={}){
|
||||
}}}}};
|
||||
},
|
||||
},
|
||||
parent:parentProxy,
|
||||
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;
|
||||
@@ -122,10 +122,6 @@ async function launch(path,version=11,opts={},testOptions={}){
|
||||
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;
|
||||
@@ -133,7 +129,7 @@ async function launch(path,version=11,opts={},testOptions={}){
|
||||
}
|
||||
return {ok:true,status:200,url:u,text:async()=>responseText};
|
||||
},
|
||||
setInterval,clearInterval,setTimeout,clearTimeout,Error,Promise,ResizeObserver:class { observe(){} disconnect(){} },
|
||||
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}});
|
||||
@@ -167,6 +163,8 @@ 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');
|
||||
@@ -182,14 +180,22 @@ 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-v4.jar')));
|
||||
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-v4.jar')));
|
||||
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.equal(workplaceCall[2].split(':').length,133);
|
||||
assert.match(workplaceCall[2],/workplace-credential-bridge\.jar/);
|
||||
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'));
|
||||
@@ -198,6 +204,32 @@ assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='jsonpProbe'&&c[2]==='b
|
||||
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));
|
||||
@@ -296,38 +328,7 @@ 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-v4.jar',import.meta.url)).size>1000);
|
||||
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.');
|
||||
|
||||
// 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.');
|
||||
|
||||
Reference in New Issue
Block a user