2016-12-08 20:56:31 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SearchController do
|
2019-01-16 07:09:29 -05:00
|
|
|
let(:user) { create(:user) }
|
2016-12-08 20:56:31 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds issue comments' do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public)
|
2016-12-08 20:56:31 -05:00
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2016-12-08 20:56:31 -05:00
|
|
|
|
|
|
|
expect(assigns[:search_objects].first).to eq note
|
|
|
|
end
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
context 'when the user cannot read cross project' do
|
|
|
|
before do
|
|
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
|
|
allow(Ability).to receive(:allowed?)
|
|
|
|
.with(user, :read_cross_project, :global) { false }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'still allows accessing the search page' do
|
|
|
|
get :show
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'still blocks searches without a project_id' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { search: 'hello' }
|
2017-12-11 09:21:06 -05:00
|
|
|
|
2018-06-04 11:04:04 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2017-12-11 09:21:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows searches with a project_id' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { search: 'hello', project_id: create(:project, :public).id }
|
2017-12-11 09:21:06 -05:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-08 20:56:31 -05:00
|
|
|
context 'on restricted projects' do
|
|
|
|
context 'when signed out' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
sign_out(user)
|
|
|
|
end
|
2016-12-08 20:56:31 -05:00
|
|
|
|
|
|
|
it "doesn't expose comments on issues" do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public, :issues_private)
|
2016-12-08 20:56:31 -05:00
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2016-12-08 20:56:31 -05:00
|
|
|
|
|
|
|
expect(assigns[:search_objects].count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't expose comments on merge_requests" do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public, :merge_requests_private)
|
2016-12-08 20:56:31 -05:00
|
|
|
note = create(:note_on_merge_request, project: project)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2016-12-08 20:56:31 -05:00
|
|
|
|
|
|
|
expect(assigns[:search_objects].count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't expose comments on snippets" do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public, :snippets_private)
|
2016-12-08 20:56:31 -05:00
|
|
|
note = create(:note_on_project_snippet, project: project)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2016-12-08 20:56:31 -05:00
|
|
|
|
|
|
|
expect(assigns[:search_objects].count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|