summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-02-21 12:50:13 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2018-02-22 17:11:36 +0100
commit08266ba0a14ec296b51cda6b54d1648985a11adf (patch)
treed5e611b7ba5c7fabe77114918e3b74fd1a26d5e9 /spec
parent148816cd67a314f17e79c107270cc708501bdd39 (diff)
downloadgitlab-ce-08266ba0a14ec296b51cda6b54d1648985a11adf.tar.gz
Use `Redactor` to hide cross project informationbvl-external-auth-port
Since the redactor can be run on multiple documents at once and query results are stored in the request store.
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/banzai/filter/cross_project_issuable_information_filter_spec.rb50
-rw-r--r--spec/lib/banzai/filter/redactor_filter_spec.rb2
-rw-r--r--spec/lib/banzai/redactor_spec.rb49
3 files changed, 50 insertions, 51 deletions
diff --git a/spec/lib/banzai/filter/cross_project_issuable_information_filter_spec.rb b/spec/lib/banzai/filter/cross_project_issuable_information_filter_spec.rb
deleted file mode 100644
index 92b8c526e88..00000000000
--- a/spec/lib/banzai/filter/cross_project_issuable_information_filter_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require 'spec_helper'
-
-describe Banzai::Filter::CrossProjectIssuableInformationFilter do
- include ActionView::Helpers::UrlHelper
- include FilterSpecHelper
-
- let(:user) { create(:user) }
- let(:project) { create(:project, :public) }
- let(:context) { { project: project, current_user: user } }
- let(:other_project) { create(:project, :public) }
-
- def create_link(issuable)
- type = issuable.class.name.underscore.downcase
- link_to(issuable.to_reference, '',
- class: 'gfm has-tooltip',
- title: issuable.title,
- data: {
- reference_type: type,
- "#{type}": issuable.id
- })
- end
-
- context 'when the user cannot read cross project' do
- before do
- allow(Ability).to receive(:allowed?) { false }
- end
-
- it 'skips links to issues within the same project' do
- issue = create(:issue, project: project)
- link = create_link(issue)
- doc = filter(link, context)
-
- result = doc.css('a').last
-
- expect(result['class']).to include('has-tooltip')
- expect(result['title']).to eq(issue.title)
- end
-
- it 'removes info from a cross project reference' do
- issue = create(:issue, project: other_project)
- link = create_link(issue)
- doc = filter(link, context)
-
- result = doc.css('a').last
-
- expect(result['class']).not_to include('has-tooltip')
- expect(result['title']).to be_empty
- end
- end
-end
diff --git a/spec/lib/banzai/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb
index 5a7858e77f3..9a2e521fdcf 100644
--- a/spec/lib/banzai/filter/redactor_filter_spec.rb
+++ b/spec/lib/banzai/filter/redactor_filter_spec.rb
@@ -6,7 +6,7 @@ describe Banzai::Filter::RedactorFilter do
it 'ignores non-GFM links' do
html = %(See <a href="https://google.com/">Google</a>)
- doc = filter(html, current_user: double)
+ doc = filter(html, current_user: build(:user))
expect(doc.css('a').length).to eq 1
end
diff --git a/spec/lib/banzai/redactor_spec.rb b/spec/lib/banzai/redactor_spec.rb
index 893a10d1b90..1fa89137972 100644
--- a/spec/lib/banzai/redactor_spec.rb
+++ b/spec/lib/banzai/redactor_spec.rb
@@ -88,6 +88,55 @@ describe Banzai::Redactor do
end
end
+ context 'when the user cannot read cross project' do
+ include ActionView::Helpers::UrlHelper
+ let(:project) { create(:project) }
+ let(:other_project) { create(:project, :public) }
+
+ def create_link(issuable)
+ type = issuable.class.name.underscore.downcase
+ link_to(issuable.to_reference, '',
+ class: 'gfm has-tooltip',
+ title: issuable.title,
+ data: {
+ reference_type: type,
+ "#{type}": issuable.id
+ })
+ end
+
+ before do
+ project.add_developer(user)
+
+ allow(Ability).to receive(:allowed?).and_call_original
+ allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global) { false }
+ allow(Ability).to receive(:allowed?).with(user, :read_cross_project) { false }
+ end
+
+ it 'skips links to issues within the same project' do
+ issue = create(:issue, project: project)
+ link = create_link(issue)
+ doc = Nokogiri::HTML.fragment(link)
+
+ redactor.redact([doc])
+ result = doc.css('a').last
+
+ expect(result['class']).to include('has-tooltip')
+ expect(result['title']).to eq(issue.title)
+ end
+
+ it 'removes info from a cross project reference' do
+ issue = create(:issue, project: other_project)
+ link = create_link(issue)
+ doc = Nokogiri::HTML.fragment(link)
+
+ redactor.redact([doc])
+ result = doc.css('a').last
+
+ expect(result['class']).not_to include('has-tooltip')
+ expect(result['title']).to be_empty
+ end
+ end
+
describe '#redact_nodes' do
it 'redacts an Array of nodes' do
doc = Nokogiri::HTML.fragment('<a href="foo">foo</a>')