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' });
|
||||
|
||||
Reference in New Issue
Block a user