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
752d127c
Commit
752d127c
authored
Jun 19, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicated test cases for vulnerability exports API
parent
ecfc5247
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
109 deletions
+42
-109
ee/spec/requests/api/vulnerability_exports_spec.rb
ee/spec/requests/api/vulnerability_exports_spec.rb
+42
-109
No files found.
ee/spec/requests/api/vulnerability_exports_spec.rb
View file @
752d127c
...
...
@@ -12,70 +12,10 @@ RSpec.describe API::VulnerabilityExports do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:with_vulnerability
)
}
describe
'POST /security/projects/:id/vulnerability_exports'
do
let
(
:format
)
{
'csv'
}
let
(
:request_path
)
{
"/security/projects/
#{
project
.
id
}
/vulnerability_exports"
}
subject
(
:create_vulnerability_export
)
{
post
api
(
request_path
,
user
),
params:
{
export_format:
format
}
}
context
'with an authorized user with proper permissions'
do
before
do
project
.
add_developer
(
user
)
end
context
'when format is csv'
do
it
'returns information about new vulnerability export'
do
create_vulnerability_export
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/vulnerability_export'
,
dir:
'ee'
)
end
it
'schedules job for export'
do
expect
(
::
VulnerabilityExports
::
ExportWorker
).
to
receive
(
:perform_async
).
with
(
anything
)
create_vulnerability_export
end
end
context
'when format is invalid'
do
let
(
:format
)
{
'invalid'
}
it
'returns error message'
do
create_vulnerability_export
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
).
to
eq
(
'error'
=>
'export_format does not have a valid value'
)
end
it
'does not schedule a job for export'
do
expect
(
::
VulnerabilityExports
::
ExportWorker
).
not_to
receive
(
:perform_async
)
create_vulnerability_export
end
end
it_behaves_like
'forbids access to vulnerability API endpoint in case of disabled features'
end
describe
'permissions'
do
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:maintainer
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:auditor
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_denied_for
(
:anonymous
)
}
end
end
describe
'POST /security/groups/:id/vulnerability_exports'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
shared_examples
'creating export for exportable'
do
let
(
:format
)
{
'csv'
}
let
(
:request_path
)
{
"/security/groups/
#{
group
.
id
}
/vulnerability_exports"
}
let
(
:deny_setup
)
{}
let
(
:permission_setup
)
{}
subject
(
:create_vulnerability_export
)
{
post
api
(
request_path
,
user
),
params:
{
export_format:
format
}
}
...
...
@@ -92,6 +32,10 @@ RSpec.describe API::VulnerabilityExports do
context
'when the request fulfills the requirements'
do
context
'when the user is not authorized to take the action'
do
before
do
deny_setup
end
it
'responds with 403 forbidden'
do
create_vulnerability_export
...
...
@@ -104,7 +48,7 @@ RSpec.describe API::VulnerabilityExports do
before
do
allow
(
VulnerabilityExports
::
CreateService
).
to
receive
(
:new
).
and_return
(
mock_service_object
)
group
.
add_developer
(
user
)
permission_setup
end
context
'when the export creation succeeds'
do
...
...
@@ -130,60 +74,49 @@ RSpec.describe API::VulnerabilityExports do
end
end
end
end
it_behaves_like
'forbids access to vulnerability API endpoint in case of disabled features'
end
describe
'POST /security/vulnerability_exports'
do
let
(
:format
)
{
'csv'
}
let
(
:request_path
)
{
"/security/vulnerability_exports"
}
subject
(
:create_vulnerability_export
)
{
post
api
(
request_path
,
user
),
params:
{
export_format:
format
}
}
context
'when the request does not fulfill the requirements'
do
let
(
:format
)
{
'exif'
}
it
'responds with bad_request'
do
create_vulnerability_export
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
).
to
eq
(
'error'
=>
'export_format does not have a valid value'
)
it_behaves_like
'forbids access to vulnerability API endpoint in case of disabled features'
do
before
do
permission_setup
end
end
end
end
context
'when the request fulfills the requiremen
ts'
do
let
(
:mock_service_object
)
{
instance_double
(
VulnerabilityExports
::
CreateService
,
execute:
vulnerability_export
)
}
before
do
allow
(
VulnerabilityExports
::
CreateService
).
to
receive
(
:new
).
and_return
(
mock_service_object
)
end
context
'when the export creation succeeds'
do
let
(
:vulnerability_export
)
{
create
(
:vulnerability_expor
t
)
}
it
'returns information about new vulnerability export'
do
create_vulnerability_export
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/vulnerability_export'
,
dir:
'ee'
)
end
describe
'POST /security/projects/:id/vulnerability_expor
ts'
do
it_behaves_like
'creating export for exportable'
do
let
(
:request_path
)
{
"/security/projects/
#{
project
.
id
}
/vulnerability_exports"
}
let
(
:deny_setup
)
{
project
.
add_guest
(
user
)
}
let
(
:permission_setup
)
{
project
.
add_developer
(
user
)
}
describe
'permissions'
do
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:owner
).
of
(
projec
t
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:maintainer
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_allowed_for
(
:auditor
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
create_vulnerability_export
}.
to
be_denied_for
(
:anonymous
)
}
end
end
end
context
'when the export creation fails'
do
let
(
:errors
)
{
instance_double
(
ActiveModel
::
Errors
,
any?:
true
,
messages:
[
'foo'
])
}
let
(
:vulnerability_export
)
{
instance_double
(
Vulnerabilities
::
Export
,
persisted?:
false
,
errors:
errors
)
}
it
'returns the error message'
do
create_vulnerability_export
describe
'POST /security/groups/:id/vulnerability_exports'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
).
to
eq
(
'message'
=>
[
'foo'
])
end
end
it_behaves_like
'creating export for exportable'
do
let
(
:request_path
)
{
"/security/groups/
#{
group
.
id
}
/vulnerability_exports"
}
let
(
:permission_setup
)
{
group
.
add_developer
(
user
)
}
end
end
it_behaves_like
'forbids access to vulnerability API endpoint in case of disabled features'
describe
'POST /security/vulnerability_exports'
do
it_behaves_like
'creating export for exportable'
do
let
(
:request_path
)
{
"/security/vulnerability_exports"
}
let
(
:deny_setup
)
{
allow
(
InstanceSecurityDashboard
).
to
receive
(
:new
).
and_return
(
nil
)
}
end
end
describe
'GET /security/vulnerability_exports/:id'
do
...
...
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