forked from GithubBackups/healthchecks
Relax cron expression validation
Accept all expressions that croniter accepts. If cron-descriptor throws an exception, don't show the description to the user.
This commit is contained in:
parent
f06616a934
commit
1e84cac37d
@ -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
|
||||
|
||||
|
@ -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"}
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user