Skip to content

Commit f8e0ade

Browse files
committed
fix: update upload size limit checks to enforce a 10 GB cap and adjust related tests
1 parent dc4dbba commit f8e0ade

3 files changed

Lines changed: 24 additions & 23 deletions

File tree

src/utils/upload.utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { BufferStream } from './stream.utils';
55
import { ThumbnailUtils } from './thumbnail.utils';
66
import { CLIUtils } from './cli.utils';
77

8-
const HUNDRED_GIGABYTES = 100 * 1024 * 1024 * 1024;
8+
const TEN_GIGABYTES = 10 * 1024 * 1024 * 1024;
99

1010
export class UploadUtils {
1111
static readonly checkUploadSizeLimits = async (size: number): Promise<void> => {
@@ -16,8 +16,9 @@ export class UploadUtils {
1616
throw new Error(`File is too big (${formattedSize} exceeds account upload limit of ${formattedLimit})`);
1717
}
1818

19-
if (size > HUNDRED_GIGABYTES) {
20-
throw new Error('File is too big (more than 100 GB)');
19+
if (size > TEN_GIGABYTES) {
20+
//Default limit if limits are not set from backend
21+
throw new Error('File is too big (more than 10 GB)');
2122
}
2223
};
2324

test/services/network/network-facade.service.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Network Facade Service', () => {
8787
expect(mockEnvironment.upload).not.toHaveBeenCalled();
8888
});
8989

90-
it('Should throw an error when a file exceeds 100 GB', async () => {
90+
it('Should throw an error when a file exceeds 10 GB', async () => {
9191
const mockEnvironment = {
9292
upload: vi.fn(),
9393
};
@@ -106,16 +106,16 @@ describe('Network Facade Service', () => {
106106
await expect(() =>
107107
sut.uploadFile({
108108
from: readStream,
109-
size: 101 * 1024 * 1024 * 1024,
109+
size: 11 * 1024 * 1024 * 1024,
110110
bucketId: 'bucket-id',
111111
progressCallback: vi.fn(),
112112
}),
113-
).rejects.toThrow('File is too big (more than 100 GB)');
113+
).rejects.toThrow('File is too big (more than 10 GB)');
114114

115115
expect(mockEnvironment.upload).not.toHaveBeenCalled();
116116
});
117117

118-
it('Should enforce API limit over 100 GB hard cap when maxUploadFileSize is smaller', async () => {
118+
it('Should enforce API limit over 10 GB hard cap when maxUploadFileSize is smaller', async () => {
119119
const mockEnvironment = {
120120
upload: vi.fn(),
121121
};

test/utils/upload.utils.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ describe('UploadUtils', () => {
1313
});
1414

1515
describe('checkUploadSizeLimits', () => {
16-
it('should not throw when fetchLimits returns no maxUploadFileSize and size is under 100GB', async () => {
16+
it('should not throw when fetchLimits returns no maxUploadFileSize and size is under 10GB', async () => {
1717
vi.spyOn(UsageService.instance, 'fetchLimits').mockResolvedValue(undefined as never);
1818

19-
await expect(UploadUtils.checkUploadSizeLimits(50 * 1024 * 1024 * 1024)).resolves.toBeUndefined();
19+
await expect(UploadUtils.checkUploadSizeLimits(5 * 1024 * 1024 * 1024)).resolves.toBeUndefined();
2020
});
2121

2222
it('should not throw when fetchLimits returns null', async () => {
2323
vi.spyOn(UsageService.instance, 'fetchLimits').mockResolvedValue(null as never);
2424

25-
await expect(UploadUtils.checkUploadSizeLimits(50 * 1024 * 1024 * 1024)).resolves.toBeUndefined();
25+
await expect(UploadUtils.checkUploadSizeLimits(5 * 1024 * 1024 * 1024)).resolves.toBeUndefined();
2626
});
2727

2828
it('should not throw when size is below the account upload limit', async () => {
2929
vi.spyOn(UsageService.instance, 'fetchLimits').mockResolvedValue({
30-
maxUploadFileSize: 100 * 1024 * 1024 * 1024,
30+
maxUploadFileSize: 8 * 1024 * 1024 * 1024,
3131
versioning: { enabled: false, maxFileSize: 0, retentionDays: 0, maxVersions: 0 },
3232
});
3333

34-
await expect(UploadUtils.checkUploadSizeLimits(50 * 1024 * 1024 * 1024)).resolves.toBeUndefined();
34+
await expect(UploadUtils.checkUploadSizeLimits(5 * 1024 * 1024 * 1024)).resolves.toBeUndefined();
3535
});
3636

3737
it('should throw when size exceeds the account upload limit', async () => {
@@ -58,34 +58,34 @@ describe('UploadUtils', () => {
5858
await expect(UploadUtils.checkUploadSizeLimits(limitBytes)).resolves.toBeUndefined();
5959
});
6060

61-
it('should throw when size exceeds 100GB even if no account limit is set', async () => {
61+
it('should throw when size exceeds 10GB even if no account limit is set', async () => {
6262
vi.spyOn(UsageService.instance, 'fetchLimits').mockResolvedValue(undefined as never);
6363

64-
await expect(UploadUtils.checkUploadSizeLimits(101 * 1024 * 1024 * 1024)).rejects.toThrow(
65-
'File is too big (more than 100 GB)',
64+
await expect(UploadUtils.checkUploadSizeLimits(11 * 1024 * 1024 * 1024)).rejects.toThrow(
65+
'File is too big (more than 10 GB)',
6666
);
6767
});
6868

69-
it('should throw when size > 100GB', async () => {
69+
it('should throw when size > 10GB', async () => {
7070
vi.spyOn(UsageService.instance, 'fetchLimits').mockResolvedValue({
71-
maxUploadFileSize: 200 * 1024 * 1024 * 1024,
71+
maxUploadFileSize: 20 * 1024 * 1024 * 1024,
7272
versioning: { enabled: false, maxFileSize: 0, retentionDays: 0, maxVersions: 0 },
7373
});
7474

75-
await expect(UploadUtils.checkUploadSizeLimits(150 * 1024 * 1024 * 1024)).rejects.toThrow(
76-
'File is too big (more than 100 GB)',
75+
await expect(UploadUtils.checkUploadSizeLimits(15 * 1024 * 1024 * 1024)).rejects.toThrow(
76+
'File is too big (more than 10 GB)',
7777
);
7878
});
7979

80-
it('should use the account limit when it is below 100GB', async () => {
81-
const limitBytes = 50 * 1024 * 1024 * 1024;
80+
it('should use the account limit when it is below the default limit', async () => {
81+
const limitBytes = 8 * 1024 * 1024 * 1024;
8282
vi.spyOn(UsageService.instance, 'fetchLimits').mockResolvedValue({
8383
maxUploadFileSize: limitBytes,
8484
versioning: { enabled: false, maxFileSize: 0, retentionDays: 0, maxVersions: 0 },
8585
});
8686

87-
await expect(UploadUtils.checkUploadSizeLimits(75 * 1024 * 1024 * 1024)).rejects.toThrow(
88-
`File is too big (${FormatUtils.humanFileSize(75 * 1024 * 1024 * 1024)} exceeds account ` +
87+
await expect(UploadUtils.checkUploadSizeLimits(9 * 1024 * 1024 * 1024)).rejects.toThrow(
88+
`File is too big (${FormatUtils.humanFileSize(9 * 1024 * 1024 * 1024)} exceeds account ` +
8989
`upload limit of ${FormatUtils.humanFileSize(limitBytes)})`,
9090
);
9191
});

0 commit comments

Comments
 (0)