Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/asciidoc_spec.rb')
-rw-r--r--spec/lib/gitlab/asciidoc_spec.rb106
1 files changed, 101 insertions, 5 deletions
diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb
index 31e575e0466..a43f08db659 100644
--- a/spec/lib/gitlab/asciidoc_spec.rb
+++ b/spec/lib/gitlab/asciidoc_spec.rb
@@ -20,7 +20,7 @@ module Gitlab
expected_asciidoc_opts = {
safe: :secure,
backend: :gitlab_html5,
- attributes: described_class::DEFAULT_ADOC_ATTRS.merge({ "kroki-server-url" => nil }),
+ attributes: described_class::DEFAULT_ADOC_ATTRS.merge({ "kroki-server-url" => nil, "allow-uri-read" => false }),
extensions: be_a(Proc)
}
@@ -35,7 +35,7 @@ module Gitlab
expected_asciidoc_opts = {
safe: :secure,
backend: :gitlab_html5,
- attributes: described_class::DEFAULT_ADOC_ATTRS.merge({ "kroki-server-url" => nil }),
+ attributes: described_class::DEFAULT_ADOC_ATTRS.merge({ "kroki-server-url" => nil, "allow-uri-read" => false }),
extensions: be_a(Proc)
}
@@ -730,6 +730,19 @@ module Gitlab
include_examples 'invalid include'
end
+ context 'with a URI that returns 404' do
+ let(:include_path) { 'https://example.com/some_file.adoc' }
+
+ before do
+ stub_request(:get, include_path).to_return(status: 404, body: 'not found')
+ allow_any_instance_of(ApplicationSetting).to receive(:wiki_asciidoc_allow_uri_includes).and_return(true)
+ end
+
+ it 'renders Unresolved directive placeholder' do
+ is_expected.to include("<strong>[ERROR: include::#{include_path}[] - unresolved directive]</strong>")
+ end
+ end
+
context 'with path to a textual file' do
let(:include_path) { 'sample.adoc' }
@@ -804,6 +817,59 @@ module Gitlab
end
end
+ describe 'the effect of max-includes' do
+ before do
+ create_file 'doc/preface.adoc', 'source: preface'
+ create_file 'doc/chapter-1.adoc', 'source: chapter-1'
+ create_file 'license.adoc', 'source: license'
+ stub_request(:get, 'https://example.com/some_file.adoc')
+ .to_return(status: 200, body: 'source: interwebs')
+ stub_request(:get, 'https://example.com/other_file.adoc')
+ .to_return(status: 200, body: 'source: intertubes')
+ allow_any_instance_of(ApplicationSetting).to receive(:wiki_asciidoc_allow_uri_includes).and_return(true)
+ end
+
+ let(:input) do
+ <<~ADOC
+ Source: requested file
+
+ include::doc/preface.adoc[]
+ include::https://example.com/some_file.adoc[]
+ include::doc/chapter-1.adoc[]
+ include::https://example.com/other_file.adoc[]
+ include::license.adoc[]
+ ADOC
+ end
+
+ it 'includes the content of all sources' do
+ expect(output.gsub(/<[^>]+>/, '').gsub(/\n\s*/, "\n").strip).to eq <<~ADOC.strip
+ Source: requested file
+ source: preface
+ source: interwebs
+ source: chapter-1
+ source: intertubes
+ source: license
+ ADOC
+ end
+
+ context 'when the document includes more than MAX_INCLUDES' do
+ before do
+ stub_const("#{described_class}::MAX_INCLUDES", 2)
+ end
+
+ it 'includes only the content of the first 2 sources' do
+ expect(output.gsub(/<[^>]+>/, '').gsub(/\n\s*/, "\n").strip).to eq <<~ADOC.strip
+ Source: requested file
+ source: preface
+ source: interwebs
+ doc/chapter-1.adoc
+ https://example.com/other_file.adoc
+ license.adoc
+ ADOC
+ end
+ end
+ end
+
context 'recursive includes with relative paths' do
let(:input) do
<<~ADOC
@@ -811,29 +877,53 @@ module Gitlab
include::doc/README.adoc[]
- include::license.adoc[]
+ include::https://example.com/some_file.adoc[]
+
+ include::license.adoc[lines=1]
ADOC
end
before do
+ stub_request(:get, 'https://example.com/some_file.adoc')
+ .to_return(status: 200, body: <<~ADOC)
+ Source: some file from Example.com
+
+ include::https://example.com/other_file[lines=1..2]
+
+ End some file from Example.com
+ ADOC
+
+ stub_request(:get, 'https://example.com/other_file')
+ .to_return(status: 200, body: <<~ADOC)
+ Source: other file from Example.com
+ Other file line 2
+ Other file line 3
+ ADOC
+
create_file 'doc/README.adoc', <<~ADOC
Source: doc/README.adoc
- include::../license.adoc[]
+ include::../license.adoc[lines=1;3]
include::api/hello.adoc[]
ADOC
create_file 'license.adoc', <<~ADOC
Source: license.adoc
+ License content
+ License end
ADOC
create_file 'doc/api/hello.adoc', <<~ADOC
Source: doc/api/hello.adoc
- include::./common.adoc[]
+ include::./common.adoc[lines=2..3]
ADOC
create_file 'doc/api/common.adoc', <<~ADOC
+ Common start
Source: doc/api/common.adoc
+ Common end
ADOC
+
+ allow_any_instance_of(ApplicationSetting).to receive(:wiki_asciidoc_allow_uri_includes).and_return(true)
end
it 'includes content of the included files recursively' do
@@ -841,8 +931,14 @@ module Gitlab
Source: requested file
Source: doc/README.adoc
Source: license.adoc
+ License end
Source: doc/api/hello.adoc
Source: doc/api/common.adoc
+ Common end
+ Source: some file from Example.com
+ Source: other file from Example.com
+ Other file line 2
+ End some file from Example.com
Source: license.adoc
ADOC
end