diff --git a/CHANGELOG.md b/CHANGELOG.md index a0b9e49c..25712421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ## Bug Fixes - Fix downtime summary to handle months when the check didn't exist yet (#472) +- Relax cron expression validation: accept all expressions that croniter accepts ## v1.19.0 - 2021-02-03 diff --git a/hc/front/tests/test_cron_preview.py b/hc/front/tests/test_cron_preview.py index d8299f1d..60d78583 100644 --- a/hc/front/tests/test_cron_preview.py +++ b/hc/front/tests/test_cron_preview.py @@ -12,8 +12,14 @@ class CronPreviewTestCase(BaseTestCase): self.assertContains(r, "cron-preview-title", status_code=200) self.assertContains(r, "“Every minute”") + def test_it_accepts_sunday_7(self): + payload = {"schedule": "* * * * 7", "tz": "UTC"} + r = self.client.post("/checks/cron_preview/", payload) + self.assertContains(r, "Expected Ping Dates", status_code=200) + self.assertNotContains(r, "Invalid cron expression", status_code=200) + def test_it_rejects_invalid_cron_expression(self): - samples = ["", "*", "100 100 100 100 100", "* * * * * *", "1,2 3,* * * *"] + samples = ["", "*", "100 100 100 100 100", "* * * * * *"] for schedule in samples: payload = {"schedule": schedule, "tz": "UTC"} diff --git a/hc/front/views.py b/hc/front/views.py index 56bbe64e..78cebcee 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -477,12 +477,22 @@ def cron_preview(request): for i in range(0, 6): ctx["dates"].append(it.get_next(datetime)) - ctx["desc"] = str(ExpressionDescriptor(schedule, use_24hour_time_format=True)) + pass except UnknownTimeZoneError: ctx["bad_tz"] = True except: ctx["bad_schedule"] = True + if ctx["dates"]: + try: + descriptor = ExpressionDescriptor(schedule, use_24hour_time_format=True) + ctx["desc"] = descriptor.get_description() + except: + # We assume the schedule is valid if croniter accepts it. + # If cron-descriptor throws an exception, don't show the description + # to the user. + pass + return render(request, "front/cron_preview.html", ctx)