workflows: check global timeout is not ouf of reasonable bounds (#88864)
gitea/wcs/pipeline/head This commit looks good
Details
gitea/wcs/pipeline/head This commit looks good
Details
This commit is contained in:
parent
781e4e4c52
commit
3b4617e887
|
@ -2842,10 +2842,14 @@ def test_workflows_global_actions_timeout_triggers(pub):
|
||||||
resp = resp.click(
|
resp = resp.click(
|
||||||
href='triggers/%s/' % Workflow.get(workflow.id).global_actions[0].triggers[0].id, index=0
|
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.form['timeout'] = invalid_value
|
||||||
resp = resp.form.submit('submit')
|
resp = resp.form.submit('submit')
|
||||||
assert 'wrong format' in resp.text
|
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.form['timeout'] = ''
|
||||||
resp = resp.form.submit('submit')
|
resp = resp.form.submit('submit')
|
||||||
assert 'required field' in resp.text
|
assert 'required field' in resp.text
|
||||||
|
|
|
@ -2024,9 +2024,11 @@ class WorkflowGlobalActionTimeoutTrigger(WorkflowGlobalActionTrigger):
|
||||||
def validate_timeout(value):
|
def validate_timeout(value):
|
||||||
if Template.is_template_string(value):
|
if Template.is_template_string(value):
|
||||||
return ComputedExpressionWidget.validate_template(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:
|
if not match or not match.group() == value:
|
||||||
raise ValueError(_('wrong format'))
|
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(
|
form.add(
|
||||||
StringWidget,
|
StringWidget,
|
||||||
|
|
Loading…
Reference in New Issue