mirror of
https://github.com/immich-app/immich.git
synced 2026-07-15 21:32:32 +03:00
fix: too strict cron expression validation (#29138)
This commit is contained in:
@@ -18490,7 +18490,6 @@
|
||||
"properties": {
|
||||
"cronExpression": {
|
||||
"description": "Cron expression",
|
||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
||||
"type": "string"
|
||||
},
|
||||
"enabled": {
|
||||
@@ -25677,7 +25676,6 @@
|
||||
"properties": {
|
||||
"cronExpression": {
|
||||
"description": "Cron expression for when the integrity check should run",
|
||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
||||
"type": "string"
|
||||
},
|
||||
"enabled": {
|
||||
@@ -25710,7 +25708,6 @@
|
||||
"properties": {
|
||||
"cronExpression": {
|
||||
"description": "Cron expression for when the integrity check should run",
|
||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
||||
"type": "string"
|
||||
},
|
||||
"enabled": {
|
||||
@@ -25810,7 +25807,6 @@
|
||||
"properties": {
|
||||
"cronExpression": {
|
||||
"description": "Cron expression",
|
||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
||||
"type": "string"
|
||||
},
|
||||
"enabled": {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { validateCronExpression } from 'cron';
|
||||
import { createZodDto } from 'nestjs-zod';
|
||||
import { SystemConfig } from 'src/config';
|
||||
import {
|
||||
@@ -43,7 +44,16 @@ const JobSettingsSchema = z
|
||||
|
||||
const cronExpressionSchema = z
|
||||
.string()
|
||||
.regex(/(((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7}/, 'Invalid cron expression')
|
||||
.superRefine((value, ctx) => {
|
||||
const validated = validateCronExpression(value);
|
||||
if (!validated.valid) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: `Invalid cron expression. ${validated.error?.message ?? ''}`,
|
||||
input: value,
|
||||
});
|
||||
}
|
||||
})
|
||||
.describe('Cron expression');
|
||||
|
||||
const DatabaseBackupSchema = z
|
||||
|
||||
@@ -319,14 +319,14 @@ describe(SystemConfigService.name, () => {
|
||||
it('should accept valid cron expressions', async () => {
|
||||
mocks.config.getEnv.mockReturnValue(mockEnvData({ configFile: 'immich-config.json' }));
|
||||
mocks.systemMetadata.readFile.mockResolvedValue(
|
||||
JSON.stringify({ library: { scan: { cronExpression: '0 0 * * *' } } }),
|
||||
JSON.stringify({ library: { scan: { cronExpression: '0 0 */3 * *' } } }),
|
||||
);
|
||||
|
||||
await expect(sut.getSystemConfig()).resolves.toMatchObject({
|
||||
library: {
|
||||
scan: {
|
||||
enabled: true,
|
||||
cronExpression: '0 0 * * *',
|
||||
cronExpression: '0 0 */3 * *',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user