Skip to content

Commit

Permalink
fix(core): Prevent object deletion request on no prefix match (#7366)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Oct 6, 2023
1 parent 7b773cc commit 63e11e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/ObjectStore/ObjectStore.service.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export class ObjectStoreService {
async deleteMany(prefix: string) {
const objects = await this.list(prefix);

if (objects.length === 0) return;

const innerXml = objects.map(({ key }) => `<Object><Key>${key}</Key></Object>`).join('\n');

const body = ['<Delete>', innerXml, '</Delete>'].join('\n');
Expand Down
8 changes: 8 additions & 0 deletions packages/core/test/ObjectStore.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ describe('deleteMany()', () => {
);
});

it('should not send a deletion request if no prefix match', async () => {
objectStoreService.list = jest.fn().mockResolvedValue([]);

const result = await objectStoreService.deleteMany('non-matching-prefix');

expect(result).toBeUndefined();
});

it('should throw an error on request failure', async () => {
mockAxios.request.mockRejectedValue(mockError);

Expand Down

0 comments on commit 63e11e4

Please sign in to comment.