summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-29 19:31:31 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-29 19:31:31 +0000
commite810b8327513c3b07cb779dbce6c75dbcb49ca84 (patch)
tree65b220240faa9e191388c6ab233fed03da2b8713 /spec/services
parent11e9b7b58837da351f08c18e6f0f4faba4d7d301 (diff)
downloadgitlab-ce-e810b8327513c3b07cb779dbce6c75dbcb49ca84.tar.gz
Add latest changes from gitlab-org/security/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/snippets/repository_validation_service_spec.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/services/snippets/repository_validation_service_spec.rb b/spec/services/snippets/repository_validation_service_spec.rb
new file mode 100644
index 00000000000..1c139d8c223
--- /dev/null
+++ b/spec/services/snippets/repository_validation_service_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Snippets::RepositoryValidationService do
+ describe '#execute' do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:snippet) { create(:personal_snippet, :empty_repo, author: user) }
+
+ let(:repository) { snippet.repository }
+ let(:service) { described_class.new(user, snippet) }
+
+ subject { service.execute }
+
+ before do
+ allow(repository).to receive(:branch_count).and_return(1)
+ allow(repository).to receive(:ls_files).and_return(['foo'])
+ allow(repository).to receive(:branch_names).and_return(['master'])
+ end
+
+ it 'returns error when the repository has more than one branch' do
+ allow(repository).to receive(:branch_count).and_return(2)
+
+ expect(subject).to be_error
+ expect(subject.message).to match /Repository has more than one branch/
+ end
+
+ it 'returns error when existing branch name is not the default one' do
+ allow(repository).to receive(:branch_names).and_return(['foo'])
+
+ expect(subject).to be_error
+ expect(subject.message).to match /Repository has an invalid default branch name/
+ end
+
+ it 'returns error when the repository has tags' do
+ allow(repository).to receive(:tag_count).and_return(1)
+
+ expect(subject).to be_error
+ expect(subject.message).to match /Repository has tags/
+ end
+
+ it 'returns error when the repository has more file than the limit' do
+ limit = Snippet.max_file_limit(user) + 1
+ files = Array.new(limit) { FFaker::Filesystem.file_name }
+ allow(repository).to receive(:ls_files).and_return(files)
+
+ expect(subject).to be_error
+ expect(subject.message).to match /Repository files count over the limit/
+ end
+
+ it 'returns error when the repository has no files' do
+ allow(repository).to receive(:ls_files).and_return([])
+
+ expect(subject).to be_error
+ expect(subject.message).to match /Repository must contain at least 1 file/
+ end
+
+ it 'returns error when the repository size is over the limit' do
+ expect_any_instance_of(Gitlab::RepositorySizeChecker).to receive(:above_size_limit?).and_return(true)
+
+ expect(subject).to be_error
+ expect(subject.message).to match /Repository size is above the limit/
+ end
+
+ it 'returns success when no validation errors are raised' do
+ expect(subject).to be_success
+ end
+ end
+end