summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-10-01 16:44:30 +0000
committerBob Van Landuyt <bob@gitlab.com>2018-10-01 16:44:30 +0000
commitc40400ceaeac1b185431adcf4dabd82ed8c531eb (patch)
treeac71100b91a893564abbec3ad2faac36df908189 /spec/serializers
parentb8cf41bc166e8b625852516bfbf43a03e56cd770 (diff)
downloadgitlab-ce-c40400ceaeac1b185431adcf4dabd82ed8c531eb.tar.gz
[master] Stored XSS in Gitlab Merge Request from imported repository
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/diff_line_entity_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/serializers/diff_line_entity_spec.rb b/spec/serializers/diff_line_entity_spec.rb
new file mode 100644
index 00000000000..2549f64bcd3
--- /dev/null
+++ b/spec/serializers/diff_line_entity_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe DiffLineEntity do
+ include RepoHelpers
+
+ let(:code) { 'hello world' }
+ let(:line) { Gitlab::Diff::Line.new(code, 'new', 1, nil, 1) }
+ let(:entity) { described_class.new(line, request: {}) }
+
+ subject { entity.as_json }
+
+ it 'exposes correct attributes' do
+ expect(subject).to include(
+ :line_code, :type, :old_line, :new_line, :text, :meta_data, :rich_text
+ )
+ end
+
+ describe '#rich_text' do
+ let(:code) { '<h2 onmouseover="alert(2)">Test</h2>' }
+ let(:rich_text_value) { nil }
+
+ before do
+ line.instance_variable_set(:@rich_text, rich_text_value)
+ end
+
+ shared_examples 'escapes html tags' do
+ it do
+ expect(subject[:rich_text]).to eq html_escape(code)
+ expect(subject[:rich_text]).to be_html_safe
+ end
+ end
+
+ context 'when rich_line is present' do
+ let(:rich_text_value) { code }
+
+ it_behaves_like 'escapes html tags'
+ end
+
+ context 'when rich_line is not present' do
+ it_behaves_like 'escapes html tags'
+ end
+ end
+end