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
b35bb456
Commit
b35bb456
authored
Oct 03, 2019
by
Tetiana Chupryna
Committed by
James Lopez
Oct 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Licenses list controller
Add route and additional service for fetching
parent
c1d17c55
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
174 additions
and
7 deletions
+174
-7
ee/app/controllers/projects/security/dependencies_controller.rb
.../controllers/projects/security/dependencies_controller.rb
+1
-1
ee/app/controllers/projects/security/licenses_controller.rb
ee/app/controllers/projects/security/licenses_controller.rb
+38
-0
ee/app/services/security/licenses_list_service.rb
ee/app/services/security/licenses_list_service.rb
+18
-0
ee/config/routes/project.rb
ee/config/routes/project.rb
+1
-0
ee/lib/gitlab/items_collection.rb
ee/lib/gitlab/items_collection.rb
+3
-3
ee/spec/controllers/projects/security/licenses_controller_spec.rb
...controllers/projects/security/licenses_controller_spec.rb
+91
-0
ee/spec/lib/gitlab/items_collection_spec.rb
ee/spec/lib/gitlab/items_collection_spec.rb
+3
-3
ee/spec/services/security/licenses_list_service_spec.rb
ee/spec/services/security/licenses_list_service_spec.rb
+19
-0
No files found.
ee/app/controllers/projects/security/dependencies_controller.rb
View file @
b35bb456
...
...
@@ -19,7 +19,7 @@ module Projects
def
collect_dependencies
found_dependencies
=
report_service
.
able_to_fetch?
?
service
.
execute
:
[]
::
Gitlab
::
Dependencie
sCollection
.
new
(
found_dependencies
)
::
Gitlab
::
Item
sCollection
.
new
(
found_dependencies
)
end
def
authorize_read_dependency_list!
...
...
ee/app/controllers/projects/security/licenses_controller.rb
0 → 100644
View file @
b35bb456
# frozen_string_literal: true
module
Projects
module
Security
class
LicensesController
<
Projects
::
ApplicationController
before_action
:authorize_read_licenses_list!
def
index
respond_to
do
|
format
|
format
.
json
do
render
json:
serializer
.
represent
(
licenses
,
build:
report_service
.
build
)
end
end
end
private
def
licenses
found_licenses
=
report_service
.
able_to_fetch?
?
service
.
execute
:
[]
::
Gitlab
::
ItemsCollection
.
new
(
found_licenses
)
end
def
report_service
@report_service
||=
::
Security
::
ReportFetchService
.
new
(
project
,
::
Ci
::
JobArtifact
.
license_management_reports
)
end
def
serializer
::
LicensesListSerializer
.
new
(
project:
project
,
user:
current_user
)
.
with_pagination
(
request
,
response
)
end
def
service
::
Security
::
LicensesListService
.
new
(
pipeline:
report_service
.
pipeline
)
end
end
end
end
ee/app/services/security/licenses_list_service.rb
0 → 100644
View file @
b35bb456
# frozen_string_literal: true
module
Security
class
LicensesListService
# @param pipeline [Ci::Pipeline]
def
initialize
(
pipeline
:)
@pipeline
=
pipeline
end
def
execute
pipeline
.
license_management_report
.
licenses
end
private
attr_reader
:pipeline
end
end
ee/config/routes/project.rb
View file @
b35bb456
...
...
@@ -87,6 +87,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
namespace
:security
do
resources
:dependencies
,
only:
[
:index
]
resources
:licenses
,
only:
[
:index
]
resources
:vulnerabilities
,
only:
[
:index
]
do
collection
do
get
:summary
...
...
ee/lib/gitlab/
dependencie
s_collection.rb
→
ee/lib/gitlab/
item
s_collection.rb
View file @
b35bb456
# frozen_string_literal: true
module
Gitlab
class
Dependencie
sCollection
class
Item
sCollection
include
Enumerable
def
initialize
(
dependencie
s
)
@collection
=
dependencie
s
def
initialize
(
item
s
)
@collection
=
item
s
end
def
each
...
...
ee/spec/controllers/projects/security/licenses_controller_spec.rb
0 → 100644
View file @
b35bb456
# frozen_string_literal: true
require
'spec_helper'
describe
Projects
::
Security
::
LicensesController
do
describe
"GET index.json"
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
{
namespace_id:
project
.
namespace
,
project_id:
project
}
}
let
(
:get_licenses
)
{
get
:index
,
params:
params
,
format: :json
}
before
do
sign_in
(
user
)
end
context
'with authorized user'
do
before
do
project
.
add_guest
(
user
)
end
context
'when feature is available'
do
before
do
stub_licensed_features
(
licenses_list:
true
,
license_management:
true
)
end
context
'with existing report'
do
let!
(
:pipeline
)
{
create
(
:ee_ci_pipeline
,
:with_license_management_report
,
project:
project
)
}
before
do
get_licenses
end
it
'returns success code'
do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'returns a hash with licenses'
do
expect
(
json_response
).
to
be_a
(
Hash
)
expect
(
json_response
[
'licenses'
].
length
).
to
eq
(
4
)
end
it
'returns status ok'
do
expect
(
json_response
[
'report'
][
'status'
]).
to
eq
(
'ok'
)
end
context
'with pagination params'
do
let
(
:params
)
{
{
namespace_id:
project
.
namespace
,
project_id:
project
,
per_page:
3
,
page:
2
}
}
it
'return only 1 license'
do
expect
(
json_response
[
'licenses'
].
length
).
to
eq
(
1
)
end
end
end
context
'without existing report'
do
let!
(
:pipeline
)
{
create
(
:ee_ci_pipeline
,
:with_dependency_list_report
,
project:
project
)
}
before
do
get_licenses
end
it
'returns status job_not_set_up'
do
expect
(
json_response
[
'report'
][
'status'
]).
to
eq
(
'job_not_set_up'
)
end
end
end
context
'when feature is not available'
do
before
do
get_licenses
end
it
'returns 404'
do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
context
'with unauthorized user'
do
before
do
stub_licensed_features
(
licenses_list:
true
,
license_management:
true
)
get_licenses
end
it
'returns 404'
do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
end
ee/spec/lib/gitlab/
dependencie
s_collection_spec.rb
→
ee/spec/lib/gitlab/
item
s_collection_spec.rb
View file @
b35bb456
...
...
@@ -2,9 +2,9 @@
require
'spec_helper'
describe
Gitlab
::
Dependencie
sCollection
do
let
(
:collection
)
{
described_class
.
new
(
fake_dependencie
s
)
}
let
(
:
fake_dependencie
s
)
{
Array
.
new
(
42
,
:dependency
)
}
describe
Gitlab
::
Item
sCollection
do
let
(
:collection
)
{
described_class
.
new
(
item
s
)
}
let
(
:
item
s
)
{
Array
.
new
(
42
,
:dependency
)
}
it
'responds to each'
do
expect
(
collection
).
to
respond_to
(
:each
)
...
...
ee/spec/services/security/licenses_list_service_spec.rb
0 → 100644
View file @
b35bb456
# frozen_string_literal: true
require
'spec_helper'
describe
Security
::
LicensesListService
do
describe
'#execute'
do
let!
(
:pipeline
)
{
create
(
:ee_ci_pipeline
,
:with_license_management_report
)
}
subject
{
described_class
.
new
(
pipeline:
pipeline
).
execute
}
before
do
stub_licensed_features
(
license_management:
true
)
end
it
'returns array of Licenses'
do
is_expected
.
to
be_an
(
Array
)
end
end
end
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