Commit 544dbea8 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'validate-argument-type-build-retry-service' into 'master'

Ensure the controller passes Ci::Build to RetryBuildService

See merge request gitlab-org/gitlab!70782
parents 936b33a0 f9f76690
...@@ -44,7 +44,7 @@ class Projects::JobsController < Projects::ApplicationController ...@@ -44,7 +44,7 @@ class Projects::JobsController < Projects::ApplicationController
render json: BuildSerializer render json: BuildSerializer
.new(project: @project, current_user: @current_user) .new(project: @project, current_user: @current_user)
.represent(@build, {}, BuildDetailsEntity) .represent(@build.present(current_user: current_user), {}, BuildDetailsEntity)
end end
end end
end end
...@@ -120,7 +120,7 @@ class Projects::JobsController < Projects::ApplicationController ...@@ -120,7 +120,7 @@ class Projects::JobsController < Projects::ApplicationController
def status def status
render json: BuildSerializer render json: BuildSerializer
.new(project: @project, current_user: @current_user) .new(project: @project, current_user: @current_user)
.represent_status(@build) .represent_status(@build.present(current_user: current_user))
end end
def erase def erase
...@@ -225,7 +225,6 @@ class Projects::JobsController < Projects::ApplicationController ...@@ -225,7 +225,6 @@ class Projects::JobsController < Projects::ApplicationController
def find_job_as_build def find_job_as_build
@build = project.builds.find(params[:id]) @build = project.builds.find(params[:id])
.present(current_user: current_user)
end end
def find_job_as_processable def find_job_as_processable
......
...@@ -32,6 +32,11 @@ module Ci ...@@ -32,6 +32,11 @@ module Ci
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def reprocess!(build) def reprocess!(build)
# Cloning a build requires a strict type check to ensure
# the attributes being used for the clone are taken straight
# from the model and not overridden by other abstractions.
raise TypeError unless build.instance_of?(Ci::Build)
check_access!(build) check_access!(build)
new_build = clone_build(build) new_build = clone_build(build)
......
...@@ -283,6 +283,10 @@ RSpec.describe Ci::RetryBuildService do ...@@ -283,6 +283,10 @@ RSpec.describe Ci::RetryBuildService do
end end
end end
it 'raises an error when an unexpected class is passed' do
expect { service.reprocess!(create(:ci_build).present) }.to raise_error(TypeError)
end
context 'when user has ability to execute build' do context 'when user has ability to execute build' do
before do before do
stub_not_protect_default_branch stub_not_protect_default_branch
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment