Unify legacy overlay signing with the queued iframe consent bridge

This commit is contained in:
archipelago
2026-10-06 11:43:33 -04:00
parent 367c32bb08
commit 08c93f4aad
5 changed files with 183 additions and 203 deletions
+19 -10
View File
@@ -12,15 +12,20 @@ const {chromium,expect}=require(process.env.PLAYWRIGHT_MODULE || '@playwright/te
if(!privateHost || !['http:','https:'].includes(url.protocol) || url.username || url.password)throw new Error('Refusing to send qualification cookies outside a private node');
const cookies=JSON.parse(fs.readFileSync(cookieFile,'utf8'));
const browser=await chromium.connectOverCDP(process.env.BROWSER_CDP || 'http://127.0.0.1:32911');
for(const width of [390,1440]){
for(const mode of ['session','overlay']) for(const width of [390,1440]){
const fixturePort=mode==='overlay'?19999:7778;
const fixtureUrl=new URL(origin); fixtureUrl.port=String(fixturePort); fixtureUrl.pathname='/';
const overlayUrl=fixtureUrl.href;
const context=await browser.newContext({viewport:{width,height:900},serviceWorkers:'block'});
try{
await context.addCookies(Object.entries(cookies).map(([name,value])=>({name,value,url:origin,httpOnly:name!=='csrf_token'})));
await context.addInitScript(()=>{
await context.addInitScript(({overlayUrl})=>{
localStorage.setItem('neode-auth','true');
localStorage.removeItem('archipelago_nostr_consent_v2');
localStorage.setItem('archipelago_app_identity_indeedhub',JSON.stringify({id:'qualification-only',name:'Qualification identity',did:'did:key:qualification-only',pubkey:'a'.repeat(64),nostr_pubkey:'b'.repeat(64)}));
});
const identity={id:'qualification-only',name:'Qualification identity',did:'did:key:qualification-only',pubkey:'a'.repeat(64),nostr_pubkey:'b'.repeat(64)};
localStorage.setItem('archipelago_app_identity_indeedhub',JSON.stringify(identity));
localStorage.setItem('archipelago_app_identity_'+overlayUrl.replace(/[^a-z0-9]/gi,'_'),JSON.stringify(identity));
},{overlayUrl});
let signed=0, frameLoads=0; const signedContents=[];
await context.route('**/rpc/v1',async route=>{
let request;try{request=route.request().postDataJSON()}catch{return route.continue()}
@@ -34,7 +39,7 @@ const {chromium,expect}=require(process.env.PLAYWRIGHT_MODULE || '@playwright/te
}
return route.continue();
});
await context.route('**:7778/**',async route=>{
await context.route('**:'+fixturePort+'/**',async route=>{
if(route.request().resourceType()!=='document')return route.abort();
frameLoads++;
return route.fulfill({contentType:'text/html',body:`<!doctype html><html><body><p id="result">waiting</p><script>
@@ -44,10 +49,14 @@ const {chromium,expect}=require(process.env.PLAYWRIGHT_MODULE || '@playwright/te
</script></body></html>`});
});
const page=await context.newPage();
await page.goto(origin+'/dashboard/app-session/indeedhub',{waitUntil:'domcontentloaded'});
await page.goto(origin+(mode==='overlay'?'/dashboard/apps':'/dashboard/app-session/indeedhub'),{waitUntil:'domcontentloaded'});
if(mode==='overlay'){
await page.waitForFunction(()=>document.querySelector('#app')?.__vue_app__?.config.globalProperties.$pinia?._s.has('appLauncher'));
await page.evaluate(url=>document.querySelector('#app').__vue_app__.config.globalProperties.$pinia._s.get('appLauncher').open({url,title:'Qualification custom app'}),overlayUrl);
}
const approve=page.getByRole('button',{name:'Approve',exact:true});
try { await expect(approve).toBeVisible({timeout:30000}); } catch(error) {
console.log(JSON.stringify({node,width,path:new URL(page.url()).pathname,headings:await page.locator('h1').allTextContents(),frames:await page.locator('iframe').evaluateAll(items=>items.map(item=>{const u=new URL(item.src);return {origin:u.origin,path:u.pathname}}))}));
console.log(JSON.stringify({node,mode,width,path:new URL(page.url()).pathname,headings:await page.locator('h1').allTextContents(),frames:await page.locator('iframe').evaluateAll(items=>items.map(item=>{const u=new URL(item.src);return {origin:u.origin,path:u.pathname}}))}));
throw error;
}
await approve.click();
@@ -55,14 +64,14 @@ const {chromium,expect}=require(process.env.PLAYWRIGHT_MODULE || '@playwright/te
await expect(approve).toBeVisible({timeout:10000});
await approve.click();
await expect.poll(()=>signed,{timeout:10000}).toBe(2);
const frame=page.frameLocator('iframe[src*="7778"]');
const frame=page.frameLocator('iframe[src*="'+fixturePort+'"]');
await expect(frame.locator('#result')).toContainText('"id":"first","ok":true');
try { await expect(frame.locator('#result')).toContainText('"id":"second","ok":true'); } catch(error) { console.log(JSON.stringify({node,width,frameLoads,signedContents})); throw error; }
try { await expect(frame.locator('#result')).toContainText('"id":"second","ok":true'); } catch(error) { console.log(JSON.stringify({node,mode,width,frameLoads,signedContents})); throw error; }
await page.waitForTimeout(800); // allow the required 675ms completion presentation to finish
await expect(approve).toHaveCount(0);
expect(frameLoads).toBe(1);
expect(signedContents).toEqual(['qualification-first','qualification-second']);
console.log(JSON.stringify({node,width,result:'PASS',scope:'served dashboard, concurrent iframe requests and consent responses; signing RPC isolated with fixtures; no real signing/payment'}));
console.log(JSON.stringify({node,mode,width,result:'PASS',scope:'served dashboard, concurrent iframe requests and consent responses; signing RPC isolated with fixtures; no real signing/payment'}));
}finally{await context.close()}
}
process.exit(0);