mirror of
https://github.com/pvrzz/Portage.git
synced 2026-11-29 05:22:26 +00:00
test: harden IndexedDB migration and verify Brave Stable compatibility
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Real Chromium/Brave WebExtensions smoke test, using only temporary browser
|
||||
// profiles and a local HTTP fixture; no personal browser profiles or secrets.
|
||||
'use strict';
|
||||
const CHROMIUM = process.env.PORTAGE_TEST_CHROMIUM || '/usr/bin/google-chrome';
|
||||
const assert = require('node:assert/strict');
|
||||
const http = require('node:http');
|
||||
const os = require('node:os');
|
||||
@@ -27,7 +28,7 @@ async function main() {
|
||||
const extDir = path.resolve('chrome');
|
||||
let browser;
|
||||
try {
|
||||
browser = await puppeteer.launch({executablePath: '/usr/bin/google-chrome',headless:true,userDataDir:dir,timeout:25000,pipe:true,enableExtensions:true,args:['--no-sandbox','--disable-gpu','--no-first-run','--no-default-browser-check']});
|
||||
browser = await puppeteer.launch({executablePath: CHROMIUM,headless:true,userDataDir:dir,timeout:25000,pipe:true,enableExtensions:true,args:['--no-sandbox','--disable-gpu','--no-first-run','--no-default-browser-check']});
|
||||
const id=await browser.installExtension(extDir);
|
||||
console.log('installed id:',id);
|
||||
if (!id) throw new Error('Portage extension failed to load');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Firefox 159 -> AES encrypted Portage file -> offline Chrome 156 import.
|
||||
// Creates only disposable profiles and uses synthetic site values.
|
||||
'use strict';
|
||||
const CHROMIUM = process.env.PORTAGE_TEST_CHROMIUM || '/usr/bin/google-chrome';
|
||||
const fs=require('node:fs'),os=require('node:os'),path=require('node:path'),http=require('node:http');
|
||||
const assert=require('node:assert/strict');
|
||||
const {spawn,spawnSync}=require('node:child_process');
|
||||
@@ -42,13 +43,13 @@ async function main(){
|
||||
// Exercise the actual command-line importer, including encrypted input.
|
||||
const imported=spawnSync(process.execPath,[
|
||||
'tools/chromium_localstorage_import.cjs',
|
||||
'--bundle',file,'--user-data-dir',chrome,'--browser','/usr/bin/google-chrome',
|
||||
'--bundle',file,'--user-data-dir',chrome,'--browser',CHROMIUM,
|
||||
'--passphrase-stdin','--apply'
|
||||
],{input:passphrase+'\n',encoding:'utf8',env:process.env,timeout:30000});
|
||||
assert.equal(imported.status,0,imported.stderr+'\n'+imported.stdout);
|
||||
assert(imported.stdout.includes('Imported 1/1 origins'), imported.stdout);
|
||||
assert.equal(requests,before,'Offline import must not access website');
|
||||
browser=await pp.launch({executablePath:'/usr/bin/google-chrome',headless:true,userDataDir:chrome,args:['--disable-background-networking','--no-first-run']});
|
||||
browser=await pp.launch({executablePath:CHROMIUM,headless:true,userDataDir:chrome,args:['--disable-background-networking','--no-first-run']});
|
||||
const page=await browser.newPage();
|
||||
await page.goto(origin);
|
||||
const v=await page.evaluate(()=>({first:localStorage.getItem('migration_probe'),len:localStorage.getItem('large_probe').length}));
|
||||
|
||||
+16
-4
@@ -1,11 +1,12 @@
|
||||
'use strict';
|
||||
const CHROMIUM = process.env.PORTAGE_TEST_CHROMIUM || '/usr/bin/google-chrome';
|
||||
const assert=require('node:assert/strict');
|
||||
const fs=require('node:fs');
|
||||
const os=require('node:os');
|
||||
const path=require('node:path');
|
||||
const http=require('node:http');
|
||||
const pp=require('../tools/node_modules/puppeteer-core');
|
||||
const {migrate,originsForFirefox,inertPage,navigateOffline}=require('../tools/indexeddb_migrate.cjs');
|
||||
const {migrate,originsForFirefox,inertPage,navigateOffline,restoreOrigin}=require('../tools/indexeddb_migrate.cjs');
|
||||
async function main(){
|
||||
const scratch=fs.mkdtempSync(path.join(os.tmpdir(),'portage-idb-test-'));
|
||||
const fx=path.join(scratch,'firefox'),chrome=path.join(scratch,'chrome');
|
||||
@@ -47,10 +48,10 @@ async function main(){
|
||||
await browser.close();browser=null;
|
||||
assert.deepEqual(originsForFirefox(fx),[...origins].sort());
|
||||
const before=hits.slice();
|
||||
const stats=await migrate({firefoxProfile:fx,chromiumProfile:chrome,firefox:'/usr/local/bin/firefox',chromium:'/usr/bin/google-chrome',apply:true,timeout:20000});
|
||||
const stats=await migrate({firefoxProfile:fx,chromiumProfile:chrome,firefox:'/usr/local/bin/firefox',chromium:CHROMIUM,apply:true,timeout:20000});
|
||||
assert.equal(stats.restored,2,JSON.stringify(stats));
|
||||
assert.deepEqual(hits,before,'IndexedDB migration must not access real origin');
|
||||
browser=await pp.launch({executablePath:'/usr/bin/google-chrome',userDataDir:chrome,headless:true,args:['--disable-background-networking']});
|
||||
browser=await pp.launch({executablePath:CHROMIUM,userDataDir:chrome,headless:true,args:['--disable-background-networking']});
|
||||
const verify=await inertPage(browser,'chromium');
|
||||
for(const [n,origin] of origins.entries()){
|
||||
await navigateOffline(verify,origin,20000);
|
||||
@@ -75,11 +76,22 @@ async function main(){
|
||||
when:'2020-02-03T04:05:06.000Z',bytes:[1,2,3,255],
|
||||
big:'12345678901234567890',blob:'file-contents',map:'猫',set:['a','b'],
|
||||
undefinedValue:true,negativeZero:true,byName:'site-'+n,byTag:'origin-'+n,autoValue:'origin-'+n});
|
||||
// Invalid structured clone payload must not create a partially valid DB.
|
||||
const rejected=await restoreOrigin(verify,{databases:[{
|
||||
name:'portage-unsupported-test',version:1,stores:[{
|
||||
name:'bad',keyPath:null,autoIncrement:false,indexes:[],
|
||||
records:[[{t:'number',v:1},{t:'unsupported-cryptokey'}]]
|
||||
}]
|
||||
}]});
|
||||
assert.equal(rejected.restored,0);
|
||||
assert.equal(rejected.skipped,1);
|
||||
const after=await verify.evaluate(()=>indexedDB.databases());
|
||||
assert(!after.some(x=>x.name==='portage-unsupported-test'), 'Rejected DB should not exist');
|
||||
}
|
||||
await verify.close();await browser.close();browser=null;
|
||||
assert.deepEqual(hits,before,'No real site traffic including verification');
|
||||
// Re-running must never overwrite existing destination IndexedDB databases.
|
||||
const repeated=await migrate({firefoxProfile:fx,chromiumProfile:chrome,firefox:'/usr/local/bin/firefox',chromium:'/usr/bin/google-chrome',apply:true,timeout:20000});
|
||||
const repeated=await migrate({firefoxProfile:fx,chromiumProfile:chrome,firefox:'/usr/local/bin/firefox',chromium:CHROMIUM,apply:true,timeout:20000});
|
||||
assert.equal(repeated.restored,0);assert.equal(repeated.skipped,2);
|
||||
process.exitCode=undefined;
|
||||
console.log('PASS: Firefox 159 -> Chrome 156 indexedDB: 2 origins, schema, indexes, rich values, no target-site traffic');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
const CHROMIUM = process.env.PORTAGE_TEST_CHROMIUM || '/usr/bin/google-chrome';
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
@@ -20,9 +21,9 @@ async function main() {
|
||||
fs.writeFileSync(file,JSON.stringify(bundle),{mode:0o600});
|
||||
try {
|
||||
assert.equal(validateBundle(bundle).totalKeys,2);
|
||||
await run({bundle:file, userDataDir:profile, browser:'/usr/bin/google-chrome', profileDirectory:'Default', timeout:12000, apply:true});
|
||||
await run({bundle:file, userDataDir:profile, browser:CHROMIUM, profileDirectory:'Default', timeout:12000, apply:true});
|
||||
assert.equal(hits,0,'Importer must NOT send a single request to the origin');
|
||||
const browser=await puppeteer.launch({executablePath:'/usr/bin/google-chrome',headless:true,userDataDir:profile,args:['--no-sandbox','--disable-background-networking']});
|
||||
const browser=await puppeteer.launch({executablePath:CHROMIUM,headless:true,userDataDir:profile,args:['--no-sandbox','--disable-background-networking']});
|
||||
try {
|
||||
const page=await browser.newPage();
|
||||
await page.goto(origin);
|
||||
|
||||
@@ -27,5 +27,11 @@ const {encode,decode}=require('../tools/indexeddb_codec.js');
|
||||
const recovered=decode(JSON.parse(JSON.stringify(await encode(special))));
|
||||
assert.equal(Object.getPrototypeOf(recovered),null);
|
||||
assert.deepEqual(recovered['__proto__'].safe,1);
|
||||
const normal={alpha:1};
|
||||
const normalRestored=decode(JSON.parse(JSON.stringify(await encode(normal))));
|
||||
assert.equal(Object.getPrototypeOf(normalRestored),Object.prototype);
|
||||
const arr=[1,,3];arr.label='tag';
|
||||
const arrRestored=decode(JSON.parse(JSON.stringify(await encode(arr))));
|
||||
assert.equal(arrRestored.label,'tag');assert.equal(1 in arrRestored,false);
|
||||
console.log('PASS: IndexedDB codec rich types, -0, invalid dates, cyclic rejection and prototype safety');
|
||||
})().catch(e=>{console.error(e.stack);process.exitCode=1});
|
||||
|
||||
Reference in New Issue
Block a user