Commit 40fd6577 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add head+base report for sast container and dast

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent de645911
......@@ -16,11 +16,15 @@ module EE
delegate :performance_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :sast_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
delegate :sast_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :sast_container_artifact, to: :head_pipeline, allow_nil: true
delegate :dast_artifact, to: :head_pipeline, allow_nil: true
delegate :sast_container_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
delegate :sast_container_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :dast_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
delegate :dast_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :sha, to: :head_pipeline, prefix: :head_pipeline, allow_nil: true
delegate :sha, to: :base_pipeline, prefix: :base_pipeline, allow_nil: true
delegate :has_sast_data?, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :has_sast_container_data?, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :has_dast_data?, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :expose_sast_data?, to: :head_pipeline, allow_nil: true
delegate :expose_sast_container_data?, to: :head_pipeline, allow_nil: true
delegate :expose_dast_data?, to: :head_pipeline, allow_nil: true
......
......@@ -41,33 +41,28 @@ module EE
end
end
expose :sast, if: -> (mr, _) { mr.expose_sast_data? } do
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_sast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_sast_artifact,
path: Ci::Build::SAST_FILE)
end
expose_artifact(:sast, Ci::Build::SAST_FILE)
expose_artifact(:sast_container, Ci::Build::SAST_CONTAINER_FILE)
expose_artifact(:dast, Ci::Build::DAST_FILE)
end
expose :base_path, if: -> (mr, _) { mr.base_has_sast_data? && can?(current_user, :read_build, mr.base_sast_artifact)} do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project,
merge_request.base_sast_artifact,
path: Ci::Build::SAST_FILE)
end
end
class_methods do
def expose_artifact(name, file)
expose name, if: -> (mr, _) { mr.send(:"expose_#{name}_data?") } do
base_artifact_method = :"base_#{name}_artifact"
head_artifact_method = :"head_#{name}_artifact"
expose :sast_container, if: -> (mr, _) { mr.expose_sast_container_data? } do
expose :path, if: -> (mr, _) { can?(current_user, :read_build, mr.sast_container_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.sast_container_artifact,
path: Ci::Build::SAST_CONTAINER_FILE)
end
end
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.send(head_artifact_method)) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.send(head_artifact_method),
path: file)
end
expose :dast, if: -> (mr, _) { mr.expose_dast_data? } do
expose :path, if: -> (mr, _) { can?(current_user, :read_build, mr.dast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.dast_artifact,
path: Ci::Build::DAST_FILE)
expose :base_path, if: -> (mr, _) { mr.send(:"base_has_#{name}_data?") && can?(current_user, :read_build, mr.send(base_artifact_method)) } do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project,
merge_request.send(base_artifact_method),
path: file)
end
end
end
end
......
......@@ -51,8 +51,25 @@ describe MergeRequestWidgetEntity do
build = create(:ci_build, name: 'sast:image', pipeline: pipeline)
allow(merge_request).to receive(:expose_sast_container_data?).and_return(true)
allow(merge_request).to receive(:sast_container_artifact).and_return(build)
allow(merge_request).to receive(:base_has_sast_container_data?).and_return(true)
allow(merge_request).to receive(:base_sast_container_artifact).and_return(build)
allow(merge_request).to receive(:head_sast_container_artifact).and_return(build)
expect(subject.as_json).to include(:sast_container)
expect(subject.as_json[:sast_container]).to include(:head_path)
expect(subject.as_json[:sast_container]).to include(:base_path)
end
it 'has dast data' do
build = create(:ci_build, name: 'dast', pipeline: pipeline)
allow(merge_request).to receive(:expose_dast_data?).and_return(true)
allow(merge_request).to receive(:base_has_dast_data?).and_return(true)
allow(merge_request).to receive(:base_dast_artifact).and_return(build)
allow(merge_request).to receive(:head_dast_artifact).and_return(build)
expect(subject.as_json).to include(:dast)
expect(subject.as_json[:dast]).to include(:head_path)
expect(subject.as_json[:dast]).to include(:base_path)
end
end
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