diff options
-rw-r--r-- | changelogs/unreleased/api-project-issues-404.yml | 4 | ||||
-rw-r--r-- | lib/api/issues.rb | 2 | ||||
-rw-r--r-- | lib/api/v3/issues.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/issues_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/v3/issues_spec.rb | 6 |
5 files changed, 18 insertions, 2 deletions
diff --git a/changelogs/unreleased/api-project-issues-404.yml b/changelogs/unreleased/api-project-issues-404.yml new file mode 100644 index 00000000000..ce40395c99e --- /dev/null +++ b/changelogs/unreleased/api-project-issues-404.yml @@ -0,0 +1,4 @@ +--- +title: Return 404 in project issues API endpoint when project cannot be found +merge_request: 10093 +author: diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 4a9f2b26fb2..e2f24a9cfeb 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -91,7 +91,7 @@ module API use :issues_params end get ":id/issues" do - project = find_project(params[:id]) + project = find_project!(params[:id]) issues = find_issues(project_id: project.id) diff --git a/lib/api/v3/issues.rb b/lib/api/v3/issues.rb index 5d7dfabfcd6..c7c90093ef5 100644 --- a/lib/api/v3/issues.rb +++ b/lib/api/v3/issues.rb @@ -103,7 +103,7 @@ module API use :issues_params end get ":id/issues" do - project = find_project(params[:id]) + project = find_project!(params[:id]) issues = find_issues(project_id: project.id) diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index ea62186434d..dd17ab58928 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -534,6 +534,12 @@ describe API::Issues, api: true do describe "GET /projects/:id/issues" do let(:base_url) { "/projects/#{project.id}" } + it 'returns 404 when project does not exist' do + get api('/projects/1000/issues', non_member) + + expect(response).to have_http_status(404) + end + it "returns 404 on private projects for other users" do private_project = create(:empty_project, :private) create(:issue, project: private_project) diff --git a/spec/requests/api/v3/issues_spec.rb b/spec/requests/api/v3/issues_spec.rb index 1941ca0d7d8..51021eec63c 100644 --- a/spec/requests/api/v3/issues_spec.rb +++ b/spec/requests/api/v3/issues_spec.rb @@ -439,6 +439,12 @@ describe API::V3::Issues, api: true do describe "GET /projects/:id/issues" do let(:base_url) { "/projects/#{project.id}" } + it 'returns 404 when project does not exist' do + get v3_api('/projects/1000/issues', non_member) + + expect(response).to have_http_status(404) + end + it "returns 404 on private projects for other users" do private_project = create(:empty_project, :private) create(:issue, project: private_project) |