Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/core/src/binary-data/__tests__/binary-data.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,42 @@ describe('BinaryDataConfig', () => {
expect.stringContaining('Invalid value for N8N_DEFAULT_BINARY_DATA_MODE'),
);
});

describe('dbMaxFileSize', () => {
it('should coerce string env variable to number', () => {
process.env.N8N_BINARY_DATA_DATABASE_MAX_FILE_SIZE = '1024';

const config = Container.get(BinaryDataConfig);

expect(config.dbMaxFileSize).toBe(1024);
});

it('should use default value when env variable is not set', () => {
const config = Container.get(BinaryDataConfig);

expect(config.dbMaxFileSize).toBe(512);
});

it('should fallback to default for invalid value', () => {
process.env.N8N_BINARY_DATA_DATABASE_MAX_FILE_SIZE = 'not-a-number';

const config = Container.get(BinaryDataConfig);

expect(config.dbMaxFileSize).toBe(512);
expect(console.warn).toHaveBeenCalledWith(
expect.stringContaining('Invalid value for N8N_BINARY_DATA_DATABASE_MAX_FILE_SIZE'),
);
});

it('should fallback to default when value exceeds maximum', () => {
process.env.N8N_BINARY_DATA_DATABASE_MAX_FILE_SIZE = '2048';

const config = Container.get(BinaryDataConfig);

expect(config.dbMaxFileSize).toBe(512);
expect(console.warn).toHaveBeenCalledWith(
expect.stringContaining('Invalid value for N8N_BINARY_DATA_DATABASE_MAX_FILE_SIZE'),
);
});
});
});
2 changes: 1 addition & 1 deletion packages/core/src/binary-data/binary-data.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const availableModesSchema = z
.transform((value) => value.split(','))
.pipe(binaryDataModesSchema.array());

const dbMaxFileSizeSchema = z
const dbMaxFileSizeSchema = z.coerce
.number()
.max(1024, 'Binary data max file size in `database` mode cannot exceed 1024 MiB'); // because of Postgres BYTEA hard limit

Expand Down