37 lines
2.5 KiB
JavaScript
37 lines
2.5 KiB
JavaScript
|
|
import test from 'node:test';
|
||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import {createRequire} from 'node:module';
|
||
|
|
import {readFileSync} from 'node:fs';
|
||
|
|
const require=createRequire(import.meta.url);
|
||
|
|
const {environment}=require('../config/environment.cjs');
|
||
|
|
const {assertInstallableConfig}=require('../scripts/check-installable-config.cjs');
|
||
|
|
const development=require('../config/development.json');
|
||
|
|
const config=()=>({extra:{environment:'dev'},android:{package:'cn.cmvr.wms.dev'},updates:{enabled:true,
|
||
|
|
url:'http://192.168.28.10/updates/dev',codeSigningCertificate:'./certs/dev.pem',codeSigningMetadata:{keyid:'dev'}}});
|
||
|
|
|
||
|
|
test('development default update service is reachable from phones, independent from the selected API',()=>{
|
||
|
|
const dev=environment({APP_ENV:'dev'});
|
||
|
|
assert.equal(dev.updateOrigin,development.updateOrigin);assert.equal(dev.updatesEnabled,true);
|
||
|
|
assert.equal(dev.apiUrl,development.apiUrl);assert.notEqual(new URL(dev.updateOrigin).hostname,'192.168.28.10');
|
||
|
|
assert.equal(environment({APP_ENV:'dev',APP_API_URL:'http://192.168.28.20:8080'}).updateOrigin,dev.updateOrigin);
|
||
|
|
// Local OTA testing remains available, but installable configuration rejects it.
|
||
|
|
assert.equal(environment({APP_ENV:'dev',APP_UPDATE_ORIGIN:'http://127.0.0.1:8090'}).updateOrigin,'http://127.0.0.1:8090');
|
||
|
|
assert.equal(assertInstallableConfig(config()),'http://192.168.28.10/updates/dev');
|
||
|
|
});
|
||
|
|
test('phone builds reject loopback, unsigned, public and wrong-channel update endpoints',()=>{
|
||
|
|
for(const url of ['http://127.0.0.1:8090/updates/dev','http://localhost:8090/updates/dev','http://8.8.8.8/updates/dev',
|
||
|
|
'http://192.168.28.10/updates/prod','http://192.168.28.10/updates/dev?token=x']){
|
||
|
|
const c=config();c.updates.url=url;assert.throws(()=>assertInstallableConfig(c));
|
||
|
|
}
|
||
|
|
for(const changes of [{enabled:false},{codeSigningCertificate:null},{codeSigningMetadata:{keyid:'prod'}}]){
|
||
|
|
const c=config();Object.assign(c.updates,changes);assert.throws(()=>assertInstallableConfig(c));
|
||
|
|
}
|
||
|
|
const c=config();c.android.package='cn.cmvr.wms';assert.throws(()=>assertInstallableConfig(c));
|
||
|
|
});
|
||
|
|
test('every installable build checks the feed; development updates cannot be routed to the production feed',()=>{
|
||
|
|
const build=readFileSync(new URL('../scripts/Build-Android.ps1',import.meta.url),'utf8');
|
||
|
|
assert.match(build,/check-installable-config\.cjs/);
|
||
|
|
const stage=readFileSync(new URL('../scripts/Stage-DevelopmentUpdate.ps1',import.meta.url),'utf8');
|
||
|
|
assert.match(stage,/taskRuntime -ne \$taskApkRuntime/);assert.match(stage,/APP_ENV = 'dev'/);
|
||
|
|
});
|