From e485b3f6ad3c220655e4aa909d93bca7a4ae6afc Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 15 Dec 2016 00:28:55 +0800 Subject: Give forbidden if project for the build was deleted Closes #25309 --- lib/ci/api/helpers.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/ci/api/helpers.rb') diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb index e608f5f6cad..0202b3cf8a3 100644 --- a/lib/ci/api/helpers.rb +++ b/lib/ci/api/helpers.rb @@ -13,8 +13,11 @@ module Ci forbidden! unless current_runner end - def authenticate_build_token!(build) - forbidden! unless build_token_valid?(build) + def authenticate_build!(build, verify_token: true) + not_found! unless build + forbidden! if verify_token && !build_token_valid?(build) + forbidden!('Project has been deleted!') unless build.project + forbidden!('Build has been erased!') if build.erased? end def runner_registration_token_valid? -- cgit v1.2.1 From 64d7772b6f0594896eb1ac67d5d3f4c33c813fe3 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 19 Dec 2016 18:43:06 +0800 Subject: Use a separate method to skip validation Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8091#note_20222666 --- lib/ci/api/helpers.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/ci/api/helpers.rb') diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb index 0202b3cf8a3..51b05aa0cb6 100644 --- a/lib/ci/api/helpers.rb +++ b/lib/ci/api/helpers.rb @@ -13,9 +13,14 @@ module Ci forbidden! unless current_runner end - def authenticate_build!(build, verify_token: true) + def authenticate_build!(build) + not_found! unless build + forbidden! if !build_token_valid?(build) + validate_build!(build) + end + + def validate_build!(build) not_found! unless build - forbidden! if verify_token && !build_token_valid?(build) forbidden!('Project has been deleted!') unless build.project forbidden!('Build has been erased!') if build.erased? end -- cgit v1.2.1 From ec003d9eb338f9172696f5540637e759a93f9fcf Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 19 Dec 2016 19:14:21 +0800 Subject: Prefer unless over if not Feedback: https://gitlab.com/gitlab-org/gitlab-ce/builds/7606797 --- lib/ci/api/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/ci/api/helpers.rb') diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb index 51b05aa0cb6..62c10c3b753 100644 --- a/lib/ci/api/helpers.rb +++ b/lib/ci/api/helpers.rb @@ -15,7 +15,7 @@ module Ci def authenticate_build!(build) not_found! unless build - forbidden! if !build_token_valid?(build) + forbidden! unless build_token_valid?(build) validate_build!(build) end -- cgit v1.2.1 From 18c9fc42249a08ff28cf9d5b9159b7bada168bcf Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 20 Dec 2016 03:24:38 +0800 Subject: Use a block to insert extra check for authenticate_build! Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8091#note_20253762 --- lib/ci/api/helpers.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/ci/api/helpers.rb') diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb index 62c10c3b753..31fbd1da108 100644 --- a/lib/ci/api/helpers.rb +++ b/lib/ci/api/helpers.rb @@ -14,13 +14,16 @@ module Ci end def authenticate_build!(build) - not_found! unless build - forbidden! unless build_token_valid?(build) - validate_build!(build) + validate_build!(build) do + forbidden! unless build_token_valid?(build) + end end def validate_build!(build) not_found! unless build + + yield if block_given? + forbidden!('Project has been deleted!') unless build.project forbidden!('Build has been erased!') if build.erased? end -- cgit v1.2.1 From 359718603eb880bffc5688c16ceed170823b665a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 21 Dec 2016 11:45:28 +0100 Subject: Ensure nil User-Agent doesn't break the CI API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- lib/ci/api/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/ci/api/helpers.rb') diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb index 31fbd1da108..5ff25a3a9b2 100644 --- a/lib/ci/api/helpers.rb +++ b/lib/ci/api/helpers.rb @@ -60,7 +60,7 @@ module Ci end def build_not_found! - if headers['User-Agent'].match(/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /) + if headers['User-Agent'].to_s.match(/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /) no_content! else not_found! -- cgit v1.2.1