Commit 8f78afdd authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'mark-scans-as-ondemand-218685' into 'master'

Indicate pipeline was ondemand and rename build

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