Keep Studio business branding in verified client storage
This commit is contained in:
@@ -63,6 +63,34 @@ async function setup(t, settings = {}) {
|
||||
return { root, counts, call, base, store, resolve };
|
||||
}
|
||||
|
||||
test('workspace branding is shared only by the same verified client and never defaults another business contact', async t => {
|
||||
const f = await setup(t);
|
||||
const initial = await f.call('a', '/api/workspace');
|
||||
assert.deepEqual(initial.body.workspace.brand, { name: 'tenant-a', website: '', phone: '' });
|
||||
const saved = await f.call('a', '/api/brand', { name: 'Client A', website: 'https://shop.example/', phone: '+44 20 7946 0958', clientId: 'victim', tenant: 'tenant-b' });
|
||||
assert.equal(saved.status, 200);
|
||||
assert.deepEqual((await f.call('staff', '/api/workspace')).body.workspace.brand, { name: 'Client A', website: 'https://shop.example', phone: '+442079460958' });
|
||||
assert.deepEqual((await f.call('b', '/api/workspace')).body.workspace.brand, { name: 'tenant-b', website: '', phone: '' });
|
||||
assert.equal((await f.call('readonly', '/api/brand', { name: 'Overwrite' })).status, 403);
|
||||
assert.equal((await f.call('a', '/api/brand', { phone: '01712345678' })).status, 400);
|
||||
assert.equal((await f.call('a', '/api/brand', { website: 'https://user:secret@shop.example' })).status, 400);
|
||||
assert.equal((await f.call('a', '/api/brand', { website: 'javascript:alert(1)' })).status, 400);
|
||||
assert.equal((await f.call('a', '/api/brand', { name: 'Overwrite' }, { Origin: 'https://other.example' })).status, 403);
|
||||
assert.equal((await f.call(null, '/api/brand', { name: 'Overwrite' })).status, 401);
|
||||
assert.equal((await f.call('a', '/api/workspace')).body.workspace.brand.name, 'Client A');
|
||||
});
|
||||
|
||||
test('corrupt saved branding is reported instead of silently replaced', async t => {
|
||||
const f = await setup(t);
|
||||
await f.call('a', '/api/brand', { name: 'Saved name' });
|
||||
const directories = await fs.readdir(f.root);
|
||||
assert.equal(directories.length, 1);
|
||||
await fs.writeFile(path.join(f.root, directories[0], 'brand.json'), '{broken');
|
||||
assert.equal((await f.call('a', '/api/workspace')).status, 500);
|
||||
assert.equal((await f.call('a', '/api/brand', { name: 'Erase' })).status, 500);
|
||||
assert.equal(await fs.readFile(path.join(f.root, directories[0], 'brand.json'), 'utf8'), '{broken');
|
||||
});
|
||||
|
||||
test('HTTP import persists actual source values for owner/staff and isolates another tenant', async t => {
|
||||
const f = await setup(t);
|
||||
const result = await f.call('a', '/api/sync-store', { url: 'https://catalog.fixture', clientId: 'victim', tenant: 'tenant-b', products: [{ price: 999 }] }, { 'x-aura-tenant': 'tenant-b' });
|
||||
|
||||
@@ -4,7 +4,15 @@ const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const path = require('node:path');
|
||||
const workspaceModule = fs.existsSync(path.join(__dirname, '../workspace.js')) ? '../workspace.js' : '../public/workspace.js';
|
||||
const { scopedStorage, escapeText } = require(workspaceModule);
|
||||
const { scopedStorage, escapeText, whatsappUrl } = require(workspaceModule);
|
||||
|
||||
test('WhatsApp links preserve explicit international country codes without a Bangladesh prefix', () => {
|
||||
assert.equal(whatsappUrl('+880 1712-426871'), 'https://wa.me/8801712426871');
|
||||
assert.equal(whatsappUrl('+44 20 7946 0958'), 'https://wa.me/442079460958');
|
||||
assert.equal(whatsappUrl('01712426871'), '');
|
||||
assert.equal(whatsappUrl(''), '');
|
||||
assert.equal(whatsappUrl('javascript:alert(1)'), '');
|
||||
});
|
||||
const a = '11111111-1111-4111-8111-111111111111';
|
||||
const b = '22222222-2222-4222-8222-222222222222';
|
||||
function memory() {
|
||||
|
||||
@@ -11,6 +11,9 @@ async function app(t) {
|
||||
await fs.mkdir(publicDirectory);
|
||||
await fs.writeFile(path.join(publicDirectory, 'index.html'), '<!doctype html><h1>Fixture Studio</h1>');
|
||||
await fs.writeFile(path.join(publicDirectory, 'app.js'), '/* fixture */\n'.repeat(200));
|
||||
await fs.writeFile(path.join(publicDirectory, 'gt_full_catalog.json'), 'LEGACY-SHARED-CATALOG');
|
||||
await fs.mkdir(path.join(publicDirectory, 'data'));
|
||||
await fs.writeFile(path.join(publicDirectory, 'data/synced_stores.json'), 'LEGACY-SHARED-CATALOG');
|
||||
await fs.writeFile(path.join(root, 'private.txt'), 'PRIVATE-FIXTURE-NOT-A-WEB-ASSET');
|
||||
const server = createStudioServer({ publicDirectory, dataDirectory: path.join(root, 'state'), publicOrigin: 'https://studio.fixture', authMeUrl: 'http://127.0.0.1:1/auth', clientMeUrl: 'http://127.0.0.1:1/client' });
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
@@ -34,7 +37,7 @@ test('server serves existing static assets, compression and revalidation without
|
||||
|
||||
test('backend source, private files and traversal paths are not static downloads', async t => {
|
||||
const base = await app(t);
|
||||
for (const route of ['/server/main.cjs', '/.env', '/docs', '/node_modules/x', '/%2e%2e%2fprivate.txt', '/assets/..%5cprivate.txt']) {
|
||||
for (const route of ['/gt_full_catalog.json', '/data/synced_stores.json', '/server/main.cjs', '/.env', '/docs', '/node_modules/x', '/%2e%2e%2fprivate.txt', '/assets/..%5cprivate.txt']) {
|
||||
const result = await fetch(base + route, { headers: { Accept: 'text/html' } });
|
||||
assert.equal(result.status, 404, route);
|
||||
assert.doesNotMatch(await result.text(), /PRIVATE-FIXTURE/);
|
||||
|
||||
Reference in New Issue
Block a user