summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-09-05 09:57:36 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-09-05 09:57:36 +0200
commitafbe5490f0d092382774eef2a9695d0ac655826b (patch)
tree62727b3ebf4eb435dbf7a94928be4f2eca9699cd /spec
parentd2f46c3025cd2735ad020c400725c6ad5e98723c (diff)
downloadgitlab-ce-afbe5490f0d092382774eef2a9695d0ac655826b.tar.gz
Limit extendable CI/CD config entry nesting levels
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/ci/config/extendable/entry_spec.rb34
1 files changed, 29 insertions, 5 deletions
diff --git a/spec/lib/gitlab/ci/config/extendable/entry_spec.rb b/spec/lib/gitlab/ci/config/extendable/entry_spec.rb
index 2726d91f6d6..8afdff99c7f 100644
--- a/spec/lib/gitlab/ci/config/extendable/entry_spec.rb
+++ b/spec/lib/gitlab/ci/config/extendable/entry_spec.rb
@@ -62,12 +62,17 @@ describe Gitlab::Ci::Config::Extendable::Entry do
end
end
- describe '#path' do
- it 'returns inheritance chain path' do
- parent = described_class.new(:test, test: { extends: 'something' })
- child = described_class.new(:job, { job: { script: 'something' } }, parent)
+ describe '#ancestors' do
+ let(:parent) do
+ described_class.new(:test, test: { extends: 'something' })
+ end
+
+ let(:child) do
+ described_class.new(:job, { job: { script: 'something' } }, parent)
+ end
- expect(child.path).to eq [:test, :job]
+ it 'returns ancestors keys' do
+ expect(child.ancestors).to eq [:test]
end
end
@@ -196,5 +201,24 @@ describe Gitlab::Ci::Config::Extendable::Entry do
.to raise_error(StandardError, /Circular dependency detected/)
end
end
+
+ context 'when nesting level is too deep' do
+ before do
+ stub_const("#{described_class}::MAX_NESTING_LEVELS", 0)
+ end
+
+ let(:hash) do
+ {
+ first: { script: 'my value' },
+ second: { extends: 'first' },
+ test: { extends: 'second' }
+ }
+ end
+
+ it 'raises an error' do
+ expect { subject.extend! }
+ .to raise_error(Gitlab::Ci::Config::Extendable::Collection::NestingTooDeepError)
+ end
+ end
end
end