workflows: check global timeout is not ouf of reasonable bounds (#88864)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-03-29 13:59:33 +01:00
parent 781e4e4c52
commit 3b4617e887
2 changed files with 8 additions and 2 deletions

View File

@ -2842,10 +2842,14 @@ def test_workflows_global_actions_timeout_triggers(pub):
resp = resp.click(
href='triggers/%s/' % Workflow.get(workflow.id).global_actions[0].triggers[0].id, index=0
)
for invalid_value in ('foobar', '-'):
for invalid_value in ('foobar', '-', '0123'):
resp.form['timeout'] = invalid_value
resp = resp.form.submit('submit')
assert 'wrong format' in resp.text
for invalid_value in ('833333335', '-833333335'):
resp.form['timeout'] = invalid_value
resp = resp.form.submit('submit')
assert 'invalid value, out of bounds' in resp.text
resp.form['timeout'] = ''
resp = resp.form.submit('submit')
assert 'required field' in resp.text

View File

@ -2024,9 +2024,11 @@ class WorkflowGlobalActionTimeoutTrigger(WorkflowGlobalActionTrigger):
def validate_timeout(value):
if Template.is_template_string(value):
return ComputedExpressionWidget.validate_template(value)
match = re.match(r'^-?\d+$', value or '')
match = re.match(r'^-?[1-9]\d*$', value or '')
if not match or not match.group() == value:
raise ValueError(_('wrong format'))
if not (365 * -100 < float(value) < 365 * 100): # ±100 years should be enough
raise ValueError(_('invalid value, out of bounds'))
form.add(
StringWidget,