diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 09:09:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 09:09:21 +0300 |
commit | c8df22c555ab707a705e57c4257fd3ed1ce7c3b0 (patch) | |
tree | 009fb7c1ff12a6192921212cae404b790fd7d66b /spec/lib/gitlab | |
parent | 9345f69894862e02f3491ea3136c3ed2b23fd5b8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/checks/push_file_count_check_spec.rb | 53 | ||||
-rw-r--r-- | spec/lib/gitlab/checks/snippet_check_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_snippet_spec.rb | 9 |
3 files changed, 64 insertions, 8 deletions
diff --git a/spec/lib/gitlab/checks/push_file_count_check_spec.rb b/spec/lib/gitlab/checks/push_file_count_check_spec.rb new file mode 100644 index 00000000000..58ba7d579a3 --- /dev/null +++ b/spec/lib/gitlab/checks/push_file_count_check_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Checks::PushFileCountCheck do + let(:snippet) { create(:personal_snippet, :repository) } + let(:changes) { { oldrev: oldrev, newrev: newrev, ref: ref } } + let(:timeout) { Gitlab::GitAccess::INTERNAL_TIMEOUT } + let(:logger) { Gitlab::Checks::TimedLogger.new(timeout: timeout) } + + subject { described_class.new(changes, repository: snippet.repository, limit: 1, logger: logger) } + + describe '#validate!' do + using RSpec::Parameterized::TableSyntax + + before do + allow(snippet.repository).to receive(:new_commits).and_return( + snippet.repository.commits_between(oldrev, newrev) + ) + end + + context 'initial creation' do + let(:oldrev) { Gitlab::Git::EMPTY_TREE_ID } + let(:newrev) { TestEnv::BRANCH_SHA["snippet/single-file"] } + let(:ref) { "refs/heads/snippet/single-file" } + + it 'allows creation' do + expect { subject.validate! }.not_to raise_error + end + end + + where(:old, :new, :valid, :message) do + 'single-file' | 'edit-file' | true | nil + 'single-file' | 'multiple-files' | false | 'The repository can contain at most 1 file(s).' + 'single-file' | 'no-files' | false | 'The repository must contain at least 1 file.' + 'edit-file' | 'rename-and-edit-file' | true | nil + end + + with_them do + let(:oldrev) { TestEnv::BRANCH_SHA["snippet/#{old}"] } + let(:newrev) { TestEnv::BRANCH_SHA["snippet/#{new}"] } + let(:ref) { "refs/heads/snippet/#{new}" } + + it "verifies" do + if valid + expect { subject.validate! }.not_to raise_error + else + expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, message) + end + end + end + end +end diff --git a/spec/lib/gitlab/checks/snippet_check_spec.rb b/spec/lib/gitlab/checks/snippet_check_spec.rb index 43c69ab7042..3eee5ccfc0a 100644 --- a/spec/lib/gitlab/checks/snippet_check_spec.rb +++ b/spec/lib/gitlab/checks/snippet_check_spec.rb @@ -10,16 +10,16 @@ describe Gitlab::Checks::SnippetCheck do subject { Gitlab::Checks::SnippetCheck.new(changes, logger: logger) } - describe '#exec' do + describe '#validate!' do it 'does not raise any error' do - expect { subject.exec }.not_to raise_error + expect { subject.validate! }.not_to raise_error end context 'trying to delete the branch' do let(:newrev) { '0000000000000000000000000000000000000000' } it 'raises an error' do - expect { subject.exec }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.') + expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.') end end @@ -28,14 +28,14 @@ describe Gitlab::Checks::SnippetCheck do let(:ref) { 'refs/heads/feature' } it 'raises an error' do - expect { subject.exec }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.') + expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.') end context "when branch is 'master'" do let(:ref) { 'refs/heads/master' } it "allows the operation" do - expect { subject.exec }.not_to raise_error + expect { subject.validate! }.not_to raise_error end end end diff --git a/spec/lib/gitlab/git_access_snippet_spec.rb b/spec/lib/gitlab/git_access_snippet_spec.rb index ba7b7da7e7d..f52fe8ef612 100644 --- a/spec/lib/gitlab/git_access_snippet_spec.rb +++ b/spec/lib/gitlab/git_access_snippet_spec.rb @@ -188,12 +188,15 @@ describe Gitlab::GitAccessSnippet do end context 'when changes are specific' do - let(:changes) { 'oldrev newrev ref' } + let(:changes) { "2d1db523e11e777e49377cfb22d368deec3f0793 ddd0f15ae83993f5cb66a927a28673882e99100b master" } let(:user) { snippet.author } it 'does not raise error if SnippetCheck does not raise error' do expect_next_instance_of(Gitlab::Checks::SnippetCheck) do |check| - expect(check).to receive(:exec).and_call_original + expect(check).to receive(:validate!).and_call_original + end + expect_next_instance_of(Gitlab::Checks::PushFileCountCheck) do |check| + expect(check).to receive(:validate!) end expect { push_access_check }.not_to raise_error @@ -201,7 +204,7 @@ describe Gitlab::GitAccessSnippet do it 'raises error if SnippetCheck raises error' do expect_next_instance_of(Gitlab::Checks::SnippetCheck) do |check| - allow(check).to receive(:exec).and_raise(Gitlab::GitAccess::ForbiddenError, 'foo') + allow(check).to receive(:validate!).and_raise(Gitlab::GitAccess::ForbiddenError, 'foo') end expect { push_access_check }.to raise_forbidden('foo') |