diff options
author | Stan Hu <stanhu@gmail.com> | 2016-01-11 06:42:00 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-01-11 20:15:42 +0300 |
commit | 78d9c904380f2a8b0eb2c8a3a1d340d1aff417df (patch) | |
tree | 271bad3c5c1105c1f58a814d26b4964592c9d495 /app | |
parent | a18ebb3c9e5c50a7c33537c1c3f31e3c75d46bf4 (diff) |
Merge branch 'check-for-present-runner-token' into 'master'
Fix Error 500 when visiting build page of project with nil runners_token
Properly ensure that the token exists and add defensively check for a
non-nil value.
Closes #4294
See merge request !2294
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index e9c8d0ea4e7..0cf04cc3a94 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -196,7 +196,7 @@ module Ci def trace trace = raw_trace - if project && trace.present? + if project && trace.present? && project.runners_token.present? trace.gsub(project.runners_token, 'xxxxxx') else trace diff --git a/app/models/project.rb b/app/models/project.rb index a8f69fd1eec..a660a5116b2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -43,6 +43,7 @@ class Project < ActiveRecord::Base include Sortable include AfterCommitQueue include CaseSensitivity + include TokenAuthenticatable extend Gitlab::ConfigHelper @@ -169,10 +170,8 @@ class Project < ActiveRecord::Base if: ->(project) { project.avatar.present? && project.avatar_changed? } validates :avatar, file_size: { maximum: 200.kilobytes.to_i } - before_validation :set_runners_token_token - def set_runners_token_token - self.runners_token = SecureRandom.hex(15) if self.runners_token.blank? - end + add_authentication_token_field :runners_token + before_save :ensure_runners_token mount_uploader :avatar, AvatarUploader @@ -864,4 +863,8 @@ class Project < ActiveRecord::Base def open_issues_count issues.opened.count end + + def runners_token + ensure_runners_token! + end end |