From 7d7b0688b846e346a0799340875d459d26c1718d Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Wed, 21 Mar 2018 17:34:55 +0100 Subject: [PATCH] Add validation for max_timeout in Ci::Runner --- app/models/ci/runner.rb | 4 ++++ spec/models/ci/build_spec.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 62cc636db22..5a4c56ec0dc 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -54,6 +54,10 @@ module Ci chronic_duration_attr :maximum_timeout_human_readable, :maximum_timeout + validates :maximum_timeout, allow_nil: true, + numericality: { greater_than_or_equal_to: 600, + message: 'needs to be at least 10 minutes' } + # Searches for runners matching the given query. # # This method uses ILIKE on PostgreSQL and LIKE on MySQL. diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index b209d53ae08..14dec2d4fc9 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1299,7 +1299,7 @@ describe Ci::Build do end context 'when runner sets timeout to smaller value' do - let(:runner2) { create(:ci_runner, maximum_timeout: 500) } + let(:runner2) { create(:ci_runner, maximum_timeout: 600) } let(:build) { create(:ci_build, :pending, pipeline: pipeline2, runner: runner2) } it 'returns project timeout configuration' do