6d37fe952b
Fix missing access checks on issue lookup using IssuableFinder Split from !2024 to partially solve https://gitlab.com/gitlab-org/gitlab-ce/issues/23867 ⚠️ - Potentially untested 💣 - No test coverage 🚥 - Test coverage of some sort exists (a test failed when error raised) 🚦 - Test coverage of return value (a test failed when nil used) ✅ - Permissions check tested - [x] ✅ app/controllers/projects/branches_controller.rb:39 - `before_action :authorize_push_code!` helpes limit/prevent exploitation. Always checks for reporter access so fine with confidential issues, issues only visible to team, etc. - [x] 🚥 app/models/cycle_analytics/summary.rb:9 [`.count`] - [x] ✅ app/controllers/projects/todos_controller.rb:19 - [x] Potential double render in app/controllers/projects/todos_controller.rb - https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2024/diffs#cedccb227af9bfdf88802767cb58d43c2b977439_24_24 See merge request !2030
133 lines
3.5 KiB
Ruby
133 lines
3.5 KiB
Ruby
require('spec_helper')
|
|
|
|
describe Projects::TodosController do
|
|
include ApiHelpers
|
|
|
|
let(:user) { create(:user) }
|
|
let(:project) { create(:empty_project) }
|
|
let(:issue) { create(:issue, project: project) }
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
context 'Issues' do
|
|
describe 'POST create' do
|
|
def go
|
|
post :create,
|
|
namespace_id: project.namespace.path,
|
|
project_id: project.path,
|
|
issuable_id: issue.id,
|
|
issuable_type: 'issue',
|
|
format: 'html'
|
|
end
|
|
|
|
context 'when authorized' do
|
|
before do
|
|
sign_in(user)
|
|
project.team << [user, :developer]
|
|
end
|
|
|
|
it 'creates todo for issue' do
|
|
expect do
|
|
go
|
|
end.to change { user.todos.count }.by(1)
|
|
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
|
|
it 'returns todo path and pending count' do
|
|
go
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(json_response['count']).to eq 1
|
|
expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/)
|
|
end
|
|
end
|
|
|
|
context 'when not authorized for project' do
|
|
it 'does not create todo for issue that user has no access to' do
|
|
sign_in(user)
|
|
expect do
|
|
go
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
expect(response).to have_http_status(404)
|
|
end
|
|
|
|
it 'does not create todo for issue when user not logged in' do
|
|
expect do
|
|
go
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
expect(response).to have_http_status(302)
|
|
end
|
|
end
|
|
|
|
context 'when not authorized for issue' do
|
|
before do
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
|
|
sign_in(user)
|
|
end
|
|
|
|
it "doesn't create todo" do
|
|
expect{ go }.not_to change { user.todos.count }
|
|
expect(response).to have_http_status(404)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'Merge Requests' do
|
|
describe 'POST create' do
|
|
def go
|
|
post :create,
|
|
namespace_id: project.namespace.path,
|
|
project_id: project.path,
|
|
issuable_id: merge_request.id,
|
|
issuable_type: 'merge_request',
|
|
format: 'html'
|
|
end
|
|
|
|
context 'when authorized' do
|
|
before do
|
|
sign_in(user)
|
|
project.team << [user, :developer]
|
|
end
|
|
|
|
it 'creates todo for merge request' do
|
|
expect do
|
|
go
|
|
end.to change { user.todos.count }.by(1)
|
|
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
|
|
it 'returns todo path and pending count' do
|
|
go
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(json_response['count']).to eq 1
|
|
expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/)
|
|
end
|
|
end
|
|
|
|
context 'when not authorized' do
|
|
it 'does not create todo for merge request user has no access to' do
|
|
sign_in(user)
|
|
expect do
|
|
go
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
expect(response).to have_http_status(404)
|
|
end
|
|
|
|
it 'does not create todo for merge request user has no access to' do
|
|
expect do
|
|
go
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
expect(response).to have_http_status(302)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|