mirror of
https://github.com/immich-app/immich.git
synced 2026-07-14 17:11:15 +00:00
fix: too strict cron expression validation (#29138)
This commit is contained in:
parent
a23a7c69ae
commit
e70a1163f3
3 changed files with 13 additions and 7 deletions
|
|
@ -18490,7 +18490,6 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"cronExpression": {
|
"cronExpression": {
|
||||||
"description": "Cron expression",
|
"description": "Cron expression",
|
||||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"enabled": {
|
"enabled": {
|
||||||
|
|
@ -25677,7 +25676,6 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"cronExpression": {
|
"cronExpression": {
|
||||||
"description": "Cron expression for when the integrity check should run",
|
"description": "Cron expression for when the integrity check should run",
|
||||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"enabled": {
|
"enabled": {
|
||||||
|
|
@ -25710,7 +25708,6 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"cronExpression": {
|
"cronExpression": {
|
||||||
"description": "Cron expression for when the integrity check should run",
|
"description": "Cron expression for when the integrity check should run",
|
||||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"enabled": {
|
"enabled": {
|
||||||
|
|
@ -25810,7 +25807,6 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"cronExpression": {
|
"cronExpression": {
|
||||||
"description": "Cron expression",
|
"description": "Cron expression",
|
||||||
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"enabled": {
|
"enabled": {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { validateCronExpression } from 'cron';
|
||||||
import { createZodDto } from 'nestjs-zod';
|
import { createZodDto } from 'nestjs-zod';
|
||||||
import { SystemConfig } from 'src/config';
|
import { SystemConfig } from 'src/config';
|
||||||
import {
|
import {
|
||||||
|
|
@ -43,7 +44,16 @@ const JobSettingsSchema = z
|
||||||
|
|
||||||
const cronExpressionSchema = z
|
const cronExpressionSchema = z
|
||||||
.string()
|
.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');
|
.describe('Cron expression');
|
||||||
|
|
||||||
const DatabaseBackupSchema = z
|
const DatabaseBackupSchema = z
|
||||||
|
|
|
||||||
|
|
@ -319,14 +319,14 @@ describe(SystemConfigService.name, () => {
|
||||||
it('should accept valid cron expressions', async () => {
|
it('should accept valid cron expressions', async () => {
|
||||||
mocks.config.getEnv.mockReturnValue(mockEnvData({ configFile: 'immich-config.json' }));
|
mocks.config.getEnv.mockReturnValue(mockEnvData({ configFile: 'immich-config.json' }));
|
||||||
mocks.systemMetadata.readFile.mockResolvedValue(
|
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({
|
await expect(sut.getSystemConfig()).resolves.toMatchObject({
|
||||||
library: {
|
library: {
|
||||||
scan: {
|
scan: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
cronExpression: '0 0 * * *',
|
cronExpression: '0 0 */3 * *',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue