test(sync): lock that one account cannot update or delete another account's rows
Account B pushes list, task and tag updates and deletes on account A's rows: each comes back skipped with its error, and A's rows keep their owner, name or title, and a null deleted_at. The owner-deletes test now also checks deleted_at on the deleted subtask and tag. Fixes #160 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
58c350c2c8
commit
87ddf7710b
1 changed files with 42 additions and 0 deletions
|
|
@ -251,6 +251,48 @@ describe('POST /api/sync: owner deletes', () => {
|
|||
['tag', 'delete', B.tag, { id: B.tag }],
|
||||
])).toEqual(['applied', 'applied', 'applied']);
|
||||
expect(await row('select count(*)::int c from sl_task_tags where task_id=$1', [B.task])).toEqual({ c: 0 });
|
||||
expect(await row('select deleted_at is not null d from sl_tasks where id=$1', [B.sub])).toEqual({ d: true });
|
||||
expect(await row('select deleted_at is not null d from sl_tags where id=$1', [B.tag])).toEqual({ d: true });
|
||||
});
|
||||
});
|
||||
|
||||
// Two defences guard each update and delete: the ownership check, then the
|
||||
// userId filter of the .where(). Removing the check alone turns the result
|
||||
// into `applied` (the filter still protects the row); removing both lets the
|
||||
// write through. The filter alone cannot be removed observably while the
|
||||
// check runs first.
|
||||
describe('POST /api/sync: writes on another account\'s rows', () => {
|
||||
const denied = { status: 'skipped', error: 'Entity not found or access denied' };
|
||||
const tagDenied = { status: 'skipped', error: 'Tag not found or access denied' };
|
||||
|
||||
it('refuses to update or delete another account\'s list', async () => {
|
||||
const { A, B } = await seed();
|
||||
expect(await pushResults(B.userId, [
|
||||
['list', 'update', A.list, { name: 'hijacked' }],
|
||||
['list', 'delete', A.list, { id: A.list }],
|
||||
])).toEqual([denied, denied]);
|
||||
expect(await row('select user_id, name, deleted_at from sl_lists where id=$1', [A.list]))
|
||||
.toEqual({ user_id: A.userId, name: 'A list', deleted_at: null });
|
||||
});
|
||||
|
||||
it('refuses to update or delete another account\'s task', async () => {
|
||||
const { A, B } = await seed();
|
||||
expect(await pushResults(B.userId, [
|
||||
['task', 'update', A.task, { title: 'hijacked' }],
|
||||
['task', 'delete', A.task, { id: A.task }],
|
||||
])).toEqual([denied, denied]);
|
||||
expect(await row('select user_id, title, deleted_at from sl_tasks where id=$1', [A.task]))
|
||||
.toEqual({ user_id: A.userId, title: 'A task', deleted_at: null });
|
||||
});
|
||||
|
||||
it('refuses to update or delete another account\'s tag', async () => {
|
||||
const { A, B } = await seed();
|
||||
expect(await pushResults(B.userId, [
|
||||
['tag', 'update', A.tag, { name: 'hijacked' }],
|
||||
['tag', 'delete', A.tag, { id: A.tag }],
|
||||
])).toEqual([tagDenied, tagDenied]);
|
||||
expect(await row('select user_id, name, deleted_at from sl_tags where id=$1', [A.tag]))
|
||||
.toEqual({ user_id: A.userId, name: 'a-tag', deleted_at: null });
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue