Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
23299096
Commit
23299096
authored
Dec 04, 2020
by
Craig Smith
Committed by
Stan Hu
Dec 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show error when the DAST feature not available
parent
1ba0026a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
8 deletions
+106
-8
changelogs/unreleased/error_when_not_licensed_273719.yml
changelogs/unreleased/error_when_not_licensed_273719.yml
+5
-0
ee/spec/lib/gitlab/ci/templates/Jobs/dast_default_branch_gitlab_ci_yaml_spec.rb
...templates/Jobs/dast_default_branch_gitlab_ci_yaml_spec.rb
+2
-2
ee/spec/lib/gitlab/ci/templates/dast_gitlab_ci_yaml_spec.rb
ee/spec/lib/gitlab/ci/templates/dast_gitlab_ci_yaml_spec.rb
+70
-6
lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml
lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml
+29
-0
No files found.
changelogs/unreleased/error_when_not_licensed_273719.yml
0 → 100644
View file @
23299096
---
title
:
Add a job to the DAST template that shows an error in the console if the user is not licensed to use DAST.
merge_request
:
47484
author
:
type
:
changed
ee/spec/lib/gitlab/ci/templates/Jobs/dast_default_branch_gitlab_ci_yaml_spec.rb
View file @
23299096
...
...
@@ -47,8 +47,8 @@ RSpec.describe 'Jobs/DAST-Default-Branch-Deploy.gitlab-ci.yml' do
end
context
'when project has no license'
do
it
'includes
no DAST jobs
'
do
expect
(
build_names
).
to
eq
%w(placeholder)
it
'includes
dast_unlicensed job
'
do
expect
(
build_names
).
to
eq
%w(placeholder
dast_unlicensed
)
end
end
...
...
ee/spec/lib/gitlab/ci/templates/dast_gitlab_ci_yaml_spec.rb
View file @
23299096
...
...
@@ -21,11 +21,75 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
end
context
'when project has no license'
do
it
'includes no jobs'
do
let
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
,
projects:
[
project
])
}
context
'when k8 is active'
do
before
do
allow
(
cluster
).
to
receive
(
:active?
).
and_return
(
true
)
end
it
'includes dast_unlicensed job'
do
expect
(
build_names
).
to
match_array
(
%w[dast_unlicensed]
)
end
end
context
'when DAST_WEBSITE is active'
do
before
do
create
(
:ci_variable
,
project:
project
,
key:
'DAST_WEBSITE'
,
value:
'http://example.com'
)
end
it
'includes dast_unlicensed job'
do
expect
(
build_names
).
to
match_array
(
%w[dast_unlicensed]
)
end
end
context
'when DAST_API_SPECIFICATION is set'
do
before
do
create
(
:ci_variable
,
project:
project
,
key:
'DAST_API_SPECIFICATION'
,
value:
'http://example/open-api-v2.json'
)
end
it
'includes dast_unlicensed job'
do
expect
(
build_names
).
to
match_array
(
%w[dast_unlicensed]
)
end
end
context
'when DAST_DISABLED'
do
before
do
create
(
:ci_variable
,
project:
project
,
key:
'DAST_DISABLED'
,
value:
'1'
)
end
it
'includes no job'
do
expect
{
pipeline
}.
to
raise_error
(
Ci
::
CreatePipelineService
::
CreateError
)
end
end
context
'when DAST_DISABLED_FOR_DEFAULT_BRANCH and CI_DEFAULT_BRANCH equals CI_COMMIT_REF_NAME'
do
before
do
create
(
:ci_variable
,
project:
project
,
key:
'DAST_DISABLED_FOR_DEFAULT_BRANCH'
,
value:
'1'
)
create
(
:ci_variable
,
project:
project
,
key:
'CI_DEFAULT_BRANCH'
,
value:
'test_branch'
)
create
(
:ci_variable
,
project:
project
,
key:
'CI_COMMIT_REF_NAME'
,
value:
'test_branch'
)
end
it
'includes no job'
do
expect
{
pipeline
}.
to
raise_error
(
Ci
::
CreatePipelineService
::
CreateError
)
end
end
context
'when not on default branch and review disabled and both DAST_WEBSITE and DAST_API_SPECIFICATION are not set'
do
before
do
create
(
:ci_variable
,
project:
project
,
key:
'CI_DEFAULT_BRANCH'
,
value:
'main'
)
create
(
:ci_variable
,
project:
project
,
key:
'CI_COMMIT_REF_NAME'
,
value:
'test_branch'
)
create
(
:ci_variable
,
project:
project
,
key:
'REVIEW_DISABLED'
,
value:
'1'
)
create
(
:ci_variable
,
project:
project
,
key:
'DAST_WEBSITE'
,
value:
nil
)
create
(
:ci_variable
,
project:
project
,
key:
'DAST_API_SPECIFICATION'
,
value:
nil
)
end
it
'includes no job'
do
expect
{
pipeline
}.
to
raise_error
(
Ci
::
CreatePipelineService
::
CreateError
)
end
end
end
context
'when project has Ultimate license'
do
let
(
:license
)
{
create
(
:license
,
plan:
License
::
ULTIMATE_PLAN
)
}
let
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
,
projects:
[
project
])
}
...
...
@@ -56,7 +120,7 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
create
(
:ci_variable
,
project:
project
,
key:
'DAST_WEBSITE'
,
value:
'http://example.com'
)
end
it
'includes job'
do
it
'includes
dast
job'
do
expect
(
build_names
).
to
match_array
(
%w[dast]
)
end
end
...
...
@@ -66,7 +130,7 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
create
(
:ci_variable
,
project:
project
,
key:
'DAST_API_SPECIFICATION'
,
value:
'http://my.api/api-specification.yml'
)
end
it
'includes job'
do
it
'includes
dast
job'
do
expect
(
build_names
).
to
match_array
(
%w[dast]
)
end
end
...
...
@@ -104,7 +168,7 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
project
.
repository
.
create_branch
(
pipeline_branch
)
end
it
'includes job'
do
it
'includes
dast
job'
do
expect
(
build_names
).
to
match_array
(
%w[dast]
)
end
end
...
...
@@ -118,7 +182,7 @@ RSpec.describe 'DAST.gitlab-ci.yml' do
end
context
'when on default branch'
do
it
'includes job'
do
it
'includes
dast
job'
do
expect
(
build_names
).
to
match_array
(
%w[dast]
)
end
end
...
...
lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml
View file @
23299096
...
...
@@ -49,3 +49,32 @@ dast:
-
if
:
$CI_COMMIT_BRANCH &&
$GITLAB_FEATURES =~ /\bdast\b/ &&
$DAST_API_SPECIFICATION
dast_unlicensed
:
stage
:
dast
allow_failure
:
true
variables
:
GIT_STRATEGY
:
none
rules
:
-
if
:
$DAST_DISABLED
when
:
never
-
if
:
$DAST_DISABLED_FOR_DEFAULT_BRANCH &&
$CI_DEFAULT_BRANCH == $CI_COMMIT_REF_NAME
when
:
never
-
if
:
$CI_DEFAULT_BRANCH != $CI_COMMIT_REF_NAME &&
$REVIEW_DISABLED && $DAST_WEBSITE ==
null
&&
$DAST_API_SPECIFICATION ==
null
when
:
never
-
if
:
$CI_COMMIT_BRANCH &&
$CI_KUBERNETES_ACTIVE &&
$GITLAB_FEATURES !~ /\bdast\b/
-
if
:
$CI_COMMIT_BRANCH &&
$GITLAB_FEATURES !~ /\bdast\b/ &&
$DAST_WEBSITE
-
if
:
$CI_COMMIT_BRANCH &&
$GITLAB_FEATURES !~ /\bdast\b/ &&
$DAST_API_SPECIFICATION
script
:
-
|
echo "Error: Your GitLab project is not licensed for DAST."
-
exit
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment