103 lines
5.4 KiB
JavaScript
103 lines
5.4 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { MODEL_ASSET_ROUTE, modelAssetTarget, modelAssetUrl, modelUrlResolver } from '../js/model-assets.js';
|
|
import { meshUrlCandidates } from '../js/urdf-paths.js';
|
|
|
|
const origin = 'https://linkerbot.oss-cn-beijing.aliyuncs.com';
|
|
const directory = '/vibemake_dev/urdf/ppsx17fhhtzq/version';
|
|
const base = `${origin}${directory}`;
|
|
|
|
test('LAN and localhost load URDF, meshes and textures from the same origin', () => {
|
|
for (const host of ['localhost', '127.0.0.1', '[::1]', '10.10.12.144', '192.168.1.6', '172.16.0.3', 'computer.local']) {
|
|
for (const asset of ['robot.urdf', 'meshes/leg.stl', 'meshes/arm.glb', 'textures/body.png', 'meshes/model.bin']) {
|
|
const remote = `${base}/${asset}`;
|
|
const local = modelAssetUrl(remote, host);
|
|
assert.equal(local, `${MODEL_ASSET_ROUTE}${directory}/${asset}`);
|
|
assert.equal(modelAssetTarget(local).href, remote);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('deployed sites and unrelated resources keep their original addresses', () => {
|
|
for (const host of ['vibemake.robotquan.com', 'dev-vibemake.robotquan.com', '172.32.0.1', '10.10.12.144.example.com']) {
|
|
assert.equal(modelAssetUrl(`${base}/robot.urdf`, host), `${base}/robot.urdf`);
|
|
}
|
|
for (const url of ['/robots/local/robot.urdf', '/assets/models/microban-assembly.glb', 'blob:local', 'data:image/png;base64,test', 'https://example.com/robot.urdf']) {
|
|
assert.equal(modelAssetUrl(url, '10.10.12.144'), url);
|
|
}
|
|
});
|
|
|
|
test('file URIs emitted by URDFLoader resolve to the package root before proxying', () => {
|
|
const resolve = modelUrlResolver(base, '10.10.12.144');
|
|
for (const value of ['file:///meshes/leg.stl', `${base}/nested/file:///meshes/leg.stl`]) {
|
|
assert.equal(resolve(value), `${MODEL_ASSET_ROUTE}${directory}/meshes/leg.stl`);
|
|
}
|
|
assert.equal(resolve(`${base}/nested/../meshes/leg.stl`), `${MODEL_ASSET_ROUTE}${directory}/meshes/leg.stl`);
|
|
assert.equal(modelUrlResolver(base, 'vibemake.robotquan.com')('file:///meshes/leg.stl'), `${base}/meshes/leg.stl`);
|
|
});
|
|
|
|
test('mesh fallback candidates retain the LAN proxy after merging URDF path handling', () => {
|
|
const path = `${base}/robots/legacy_description/meshes/arm.stl`;
|
|
const candidates = meshUrlCandidates(base, path);
|
|
assert.equal(candidates[0], `${base}/meshes/arm.stl`);
|
|
for (const host of ['localhost', '192.168.1.6']) {
|
|
const resolve = modelUrlResolver(base, host);
|
|
assert.deepEqual(candidates.map((url) => modelAssetTarget(resolve(url)).href), candidates);
|
|
}
|
|
assert.equal(modelUrlResolver(base, 'dev-vibemake.robotquan.com')(candidates[0]), candidates[0]);
|
|
});
|
|
|
|
test('asset names and signed query strings survive a proxy round trip', () => {
|
|
const remote = `${base}/meshes/${encodeURIComponent('左腿 零件')}.stl?Expires=123&Signature=a%2Bb%3D`;
|
|
assert.equal(modelAssetTarget(modelAssetUrl(remote, 'localhost')).href, remote);
|
|
});
|
|
|
|
test('OSS object names containing + load literally on deployed sites and through the LAN proxy', () => {
|
|
const root = `${origin}/vibemake/project-resources/sesame/model-parts/batch`;
|
|
const remote = `${root}/1+4%20PCB%E7%94%B5%E8%B7%AF%E6%9D%BF.glb?Signature=a+b%2Bc%3D&Expires=123`;
|
|
const encoded = remote.replace('/1+4', '/1%2B4');
|
|
for (const host of ['vibemake.robotquan.com', 'dev-vibemake.robotquan.com']) {
|
|
assert.equal(modelAssetUrl(remote, host), encoded);
|
|
assert.equal(modelAssetUrl(encoded, host), encoded);
|
|
}
|
|
for (const host of ['localhost', '192.168.1.6']) {
|
|
assert.equal(modelAssetTarget(modelAssetUrl(remote, host)).href, encoded);
|
|
}
|
|
// A '+' in an unrelated origin, a query, or an encoded literal '%2B'
|
|
// filename must not be reinterpreted as a different object or signature.
|
|
for (const unchanged of [
|
|
'https://example.com/1+4.glb',
|
|
`${root}/part.glb?Signature=a+b%2Bc%3D`,
|
|
`${root}/1%252B4.glb`,
|
|
]) assert.equal(modelAssetUrl(unchanged, 'vibemake.robotquan.com'), unchanged);
|
|
});
|
|
|
|
test('LAN preview proxies package data but never executable uploads', () => {
|
|
const root = `${origin}/vibemake_dev/experiences/project/version`;
|
|
for (const name of ['manifest.json', 'controller.json', 'models/part.glb', 'robot/model.xml', 'policies/walk.onnx', 'assets/beep.wav']) {
|
|
assert.equal(modelAssetTarget(modelAssetUrl(`${root}/${name}`, '192.168.1.6')).href, `${root}/${name}`);
|
|
}
|
|
for (const name of ['index.html', 'script.js', 'engine.wasm', 'training.py']) {
|
|
assert.equal(modelAssetUrl(`${root}/${name}`, 'localhost'), `${root}/${name}`);
|
|
}
|
|
});
|
|
|
|
test('proxy rejects other origins, credentials, active content and escaping paths', () => {
|
|
for (const url of [
|
|
`http://linkerbot.oss-cn-beijing.aliyuncs.com${directory}/robot.urdf`,
|
|
`https://linkerbot.oss-cn-beijing.aliyuncs.com.example.com${directory}/robot.urdf`,
|
|
`https://user:password@linkerbot.oss-cn-beijing.aliyuncs.com${directory}/robot.urdf`,
|
|
`${origin}/private/robot.urdf`, `${base}/index.html`, `${base}/script.js`,
|
|
]) assert.equal(modelAssetUrl(url, 'localhost'), url);
|
|
for (const path of [
|
|
`${MODEL_ASSET_ROUTE}/../private/robot.urdf`,
|
|
`${MODEL_ASSET_ROUTE}${directory}/%2e%2e%2f%2e%2e%2fsecret.stl`,
|
|
`${MODEL_ASSET_ROUTE}${directory}/%252e%252e/secret.stl`,
|
|
`${MODEL_ASSET_ROUTE}${directory}/bad%00.stl`,
|
|
`${MODEL_ASSET_ROUTE}${directory}/bad%5cfile.stl`,
|
|
`${MODEL_ASSET_ROUTE}//example.com/robot.urdf`,
|
|
`${MODEL_ASSET_ROUTE}/private/robot.urdf`,
|
|
'/api/robot.urdf',
|
|
]) assert.equal(modelAssetTarget(path), null, path);
|
|
});
|