Commit 8dba8760 authored by James Lopez's avatar James Lopez

Merge branch '12425-permissions' into 'master'

Add authorization for Dependencies Controller

See merge request gitlab-org/gitlab-ee!14867
parents d680fd3e 4f7281c3
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
module Projects module Projects
module Security module Security
class DependenciesController < Projects::ApplicationController class DependenciesController < Projects::ApplicationController
before_action :authorize_read_dependency_list!
before_action :ensure_dependency_list_feature_available before_action :ensure_dependency_list_feature_available
def index def index
...@@ -31,6 +32,10 @@ module Projects ...@@ -31,6 +32,10 @@ module Projects
::Gitlab::DependenciesCollection.new(found_dependencies) ::Gitlab::DependenciesCollection.new(found_dependencies)
end end
def authorize_read_dependency_list!
return render_403 unless can?(current_user, :read_project_security_dashboard, project)
end
def ensure_dependency_list_feature_available def ensure_dependency_list_feature_available
render_404 unless project.feature_available?(:dependency_list) render_404 unless project.feature_available?(:dependency_list)
end end
......
---
title: Add authorization to the dependency list
merge_request: 14867
author:
type: added
...@@ -9,17 +9,17 @@ describe Projects::Security::DependenciesController do ...@@ -9,17 +9,17 @@ describe Projects::Security::DependenciesController do
let(:params) { { namespace_id: project.namespace, project_id: project } } let(:params) { { namespace_id: project.namespace, project_id: project } }
before do before do
project.add_developer(user) sign_in(user)
end end
context 'with authorized user' do context 'with authorized user' do
before do before do
sign_in(user) project.add_developer(user)
end end
context 'when feature is available' do context 'when feature is available' do
before do before do
stub_licensed_features(dependency_list: true) stub_licensed_features(dependency_list: true, security_dashboard: true)
end end
it 'counts usage of the feature' do it 'counts usage of the feature' do
...@@ -135,6 +135,8 @@ describe Projects::Security::DependenciesController do ...@@ -135,6 +135,8 @@ describe Projects::Security::DependenciesController do
context 'when feature is not available' do context 'when feature is not available' do
before do before do
stub_licensed_features(security_dashboard: true)
get :index, params: params, format: :json get :index, params: params, format: :json
end end
...@@ -146,11 +148,13 @@ describe Projects::Security::DependenciesController do ...@@ -146,11 +148,13 @@ describe Projects::Security::DependenciesController do
context 'with unauthorized user' do context 'with unauthorized user' do
before do before do
project.add_guest(user)
get :index, params: params, format: :json get :index, params: params, format: :json
end end
it 'returns 404' do it 'returns 403' do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(403)
end end
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