2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SearchController do
|
2019-07-07 11:18:12 +05:30
|
|
|
include ExternalAuthorizationServiceHelpers
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
context 'uses the right partials depending on scope' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
render_views
|
|
|
|
|
|
|
|
set(:project) { create(:project, :public, :repository, :wiki_repo) }
|
|
|
|
|
|
|
|
subject { get(:show, params: { project_id: project.id, scope: scope, search: 'merge' }) }
|
|
|
|
|
|
|
|
where(:partial, :scope) do
|
|
|
|
'_blob' | :blobs
|
|
|
|
'_wiki_blob' | :wiki_blobs
|
|
|
|
'_commit' | :commits
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it do
|
|
|
|
project_wiki = create(:project_wiki, project: project, user: user)
|
|
|
|
create(:wiki_page, wiki: project_wiki, attrs: { title: 'merge', content: 'merge' })
|
|
|
|
|
|
|
|
expect(subject).to render_template("search/results/#{partial}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
it 'finds issue comments' do
|
2017-09-10 17:25:29 +05:30
|
|
|
project = create(:project, :public)
|
2017-01-15 13:20:01 +05:30
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
expect(assigns[:search_objects].first).to eq note
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
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
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { search: 'hello' }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows searches with a project_id' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { search: 'hello', project_id: create(:project, :public).id }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
context 'on restricted projects' do
|
|
|
|
context 'when signed out' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
sign_out(user)
|
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
it "doesn't expose comments on issues" do
|
2017-09-10 17:25:29 +05:30
|
|
|
project = create(:project, :public, :issues_private)
|
2017-01-15 13:20:01 +05:30
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
expect(assigns[:search_objects].count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't expose comments on merge_requests" do
|
2017-09-10 17:25:29 +05:30
|
|
|
project = create(:project, :public, :merge_requests_private)
|
2017-01-15 13:20:01 +05:30
|
|
|
note = create(:note_on_merge_request, project: project)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
expect(assigns[:search_objects].count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't expose comments on snippets" do
|
2017-09-10 17:25:29 +05:30
|
|
|
project = create(:project, :public, :snippets_private)
|
2017-01-15 13:20:01 +05:30
|
|
|
note = create(:note_on_project_snippet, project: project)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
expect(assigns[:search_objects].count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
context 'with external authorization service enabled' do
|
|
|
|
let(:project) { create(:project, namespace: user.namespace) }
|
|
|
|
let(:note) { create(:note_on_issue, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
enable_external_authorization_service_check
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
it 'renders a 403 when no project is given' do
|
|
|
|
get :show, params: { scope: 'notes', search: note.note }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(403)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders a 200 when a project was set' do
|
|
|
|
get :show, params: { project_id: project.id, scope: 'notes', search: note.note }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #autocomplete' do
|
|
|
|
it 'renders a 403 when no project is given' do
|
|
|
|
get :autocomplete, params: { term: 'hello' }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(403)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders a 200 when a project was set' do
|
|
|
|
get :autocomplete, params: { project_id: project.id, term: 'hello' }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
end
|