Commit 25278ccd authored by Philip Cunningham's avatar Philip Cunningham

Indicate pipeline was ondemand and rename build

parent 1d375778
...@@ -30,7 +30,8 @@ module Ci ...@@ -30,7 +30,8 @@ module Ci
webide: 9, webide: 9,
merge_request_event: 10, merge_request_event: 10,
external_pull_request_event: 11, external_pull_request_event: 11,
parent_pipeline: 12 parent_pipeline: 12,
ondemand_scan: 13
} }
end end
......
...@@ -43,7 +43,7 @@ module Ci ...@@ -43,7 +43,7 @@ module Ci
project: project, project: project,
ref: branch, ref: branch,
sha: project.repository.commit&.id || DEFAULT_SHA_FOR_PROJECTS_WITHOUT_COMMITS, sha: project.repository.commit&.id || DEFAULT_SHA_FOR_PROJECTS_WITHOUT_COMMITS,
source: :web, source: :ondemand_scan,
user: user user: user
) )
end end
...@@ -62,7 +62,7 @@ module Ci ...@@ -62,7 +62,7 @@ module Ci
def create_build!(pipeline, stage, branch, target_url) def create_build!(pipeline, stage, branch, target_url)
reraise!(with: CreateBuildError.new('Could not create build')) do reraise!(with: CreateBuildError.new('Could not create build')) do
Ci::Build.create!( Ci::Build.create!(
name: 'On demand DAST scan', name: 'DAST Scan',
pipeline: pipeline, pipeline: pipeline,
project: project, project: project,
ref: branch, ref: branch,
......
...@@ -34,6 +34,10 @@ describe Ci::RunDastScanService do ...@@ -34,6 +34,10 @@ describe Ci::RunDastScanService do
expect(subject.ref).to eq(branch) expect(subject.ref).to eq(branch)
end end
it 'sets the source to indicate an ondemand scan' do
expect(subject.source).to eq('ondemand_scan')
end
it 'creates a stage' do it 'creates a stage' do
expect { subject }.to change(Ci::Stage, :count).by(1) expect { subject }.to change(Ci::Stage, :count).by(1)
end end
...@@ -42,19 +46,24 @@ describe Ci::RunDastScanService do ...@@ -42,19 +46,24 @@ describe Ci::RunDastScanService do
expect { subject }.to change(Ci::Build, :count).by(1) expect { subject }.to change(Ci::Build, :count).by(1)
end end
it 'sets the build name to indicate a DAST scan' do
build = subject.builds.first
expect(build.name).to eq('DAST Scan')
end
it 'creates a build with appropriate options' do it 'creates a build with appropriate options' do
build = subject.builds.first build = subject.builds.first
expected_options = { expected_options = {
"image" => { 'image' => {
"name" => "$SECURE_ANALYZERS_PREFIX/dast:$DAST_VERSION" 'name' => '$SECURE_ANALYZERS_PREFIX/dast:$DAST_VERSION'
}, },
"script" => [ 'script' => [
"export DAST_WEBSITE=${DAST_WEBSITE:-$(cat environment_url.txt)}", 'export DAST_WEBSITE=${DAST_WEBSITE:-$(cat environment_url.txt)}',
"/analyze" '/analyze'
], ],
"artifacts" => { 'artifacts' => {
"reports" => { 'reports' => {
"dast" => ["gl-dast-report.json"] 'dast' => ['gl-dast-report.json']
} }
} }
} }
...@@ -65,21 +74,21 @@ describe Ci::RunDastScanService do ...@@ -65,21 +74,21 @@ describe Ci::RunDastScanService do
build = subject.builds.first build = subject.builds.first
expected_variables = [ expected_variables = [
{ {
"key" => "DAST_VERSION", 'key' => 'DAST_VERSION',
"value" => "1", 'value' => '1',
"public" => true 'public' => true
}, { }, {
"key" => "SECURE_ANALYZERS_PREFIX", 'key' => 'SECURE_ANALYZERS_PREFIX',
"value" => "registry.gitlab.com/gitlab-org/security-products/analyzers", 'value' => 'registry.gitlab.com/gitlab-org/security-products/analyzers',
"public" => true 'public' => true
}, { }, {
"key" => "DAST_WEBSITE", 'key' => 'DAST_WEBSITE',
"value" => target_url, 'value' => target_url,
"public" => true 'public' => true
}, { }, {
"key" => "GIT_STRATEGY", 'key' => 'GIT_STRATEGY',
"value" => "none", 'value' => 'none',
"public" => true 'public' => true
} }
] ]
expect(build.yaml_variables).to eq(expected_variables) expect(build.yaml_variables).to eq(expected_variables)
...@@ -92,7 +101,7 @@ describe Ci::RunDastScanService do ...@@ -92,7 +101,7 @@ describe Ci::RunDastScanService do
context 'when the repository has no commits' do context 'when the repository has no commits' do
it 'uses a placeholder' do it 'uses a placeholder' do
expect(subject.sha).to eq("placeholder") expect(subject.sha).to eq('placeholder')
end end
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