1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Server: Fixes #10118: Missing record validation before trying to add item to user (#10471)

This commit is contained in:
pedr 2024-06-04 05:55:57 -03:00 committed by GitHub
parent ac7165461a
commit 19f0b667b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

@ -114,6 +114,9 @@ export default class UserItemModel extends BaseModel<UserItem> {
public async add(userId: Uuid, itemId: Uuid, options: SaveOptions = {}): Promise<void> {
const item = await this.models().item().load(itemId, { fields: ['id', 'name'] });
if (!item) {
throw new ErrorNotFound(`No such item: ${itemId}`);
}
await this.addMulti(userId, [item], options);
}

View File

@ -0,0 +1,23 @@
import { beforeAllDb, afterAllTests, beforeEachDb, models } from '../utils/testing/testUtils';
describe('UserItemModel', () => {
beforeAll(async () => {
await beforeAllDb('UserItemModel');
});
afterAll(async () => {
await afterAllTests();
});
beforeEach(async () => {
await beforeEachDb();
});
test('should throw error if item does not exist', async () => {
const mockUserId = 'not-a-real-user-id';
const mockId = 'not-a-real-item-id';
expect(async () => models().userItem().add(mockUserId, mockId)).rejects.toThrow('No such item: not-a-real-item-id');
});
});