Commit 8f84505b authored by Stan Hu's avatar Stan Hu

Merge branch 'vulnerability-api-improvement' into 'master'

Improve vulnerability API

See merge request gitlab-org/gitlab-ee!12760
parents 0a27a536 5b3cdef1
---
title: Improve vulnerability API
merge_request: 12760
author: Robert Schilling
type: other
...@@ -43,12 +43,10 @@ module API ...@@ -43,12 +43,10 @@ module API
end end
get ':id/vulnerabilities' do get ':id/vulnerabilities' do
project = Project.find(params[:id]) authorize! :read_project_security_dashboard, user_project
not_found!('Project') unless project && can?(current_user, :read_project_security_dashboard, project)
vulnerability_occurrences = Kaminari.paginate_array( vulnerability_occurrences = Kaminari.paginate_array(
vulnerability_occurrences_by(declared_params.merge(project: project)) vulnerability_occurrences_by(declared_params.merge(project: user_project))
) )
present paginate(vulnerability_occurrences), present paginate(vulnerability_occurrences),
......
...@@ -114,16 +114,18 @@ describe API::Vulnerabilities do ...@@ -114,16 +114,18 @@ describe API::Vulnerabilities do
stub_licensed_features(security_dashboard: false, sast: true, dependency_scanning: true, container_scanning: true) stub_licensed_features(security_dashboard: false, sast: true, dependency_scanning: true, container_scanning: true)
end end
it 'responds with 404 Not Found' do it 'responds with 403 Forbidden' do
get api("/projects/#{project.id}/vulnerabilities", user) get api("/projects/#{project.id}/vulnerabilities", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(403)
end end
end end
context 'with unauthorized user' do context 'with no project access' do
it 'responds with 404 Not Found' do it 'responds with 404 Not Found' do
get api("/projects/#{project.id}/vulnerabilities", user) private_project = create(:project)
get api("/projects/#{private_project.id}/vulnerabilities", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
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