diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-07 00:09:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-07 00:09:33 +0000 |
commit | b56027c9d80ac0e297ba8a43c81e8504172dbf9f (patch) | |
tree | b85f743277145e930ae195664655d696e6e0a7fc /spec/lib | |
parent | 7915c41e4261719719e791602c8235574157164c (diff) | |
download | gitlab-ce-b56027c9d80ac0e297ba8a43c81e8504172dbf9f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/git_access_snippet_spec.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git_access_snippet_spec.rb b/spec/lib/gitlab/git_access_snippet_spec.rb index f52fe8ef612..bbc3808df12 100644 --- a/spec/lib/gitlab/git_access_snippet_spec.rb +++ b/spec/lib/gitlab/git_access_snippet_spec.rb @@ -11,6 +11,7 @@ describe Gitlab::GitAccessSnippet do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public) } let_it_be(:snippet) { create(:project_snippet, :public, :repository, project: project) } + let(:repository) { snippet.repository } let(:actor) { user } let(:protocol) { 'ssh' } @@ -211,6 +212,84 @@ describe Gitlab::GitAccessSnippet do end end + describe 'repository size restrictions' do + let(:snippet) { create(:personal_snippet, :public, :repository) } + let(:actor) { snippet.author } + + let(:oldrev) { TestEnv::BRANCH_SHA["snippet/single-file"] } + let(:newrev) { TestEnv::BRANCH_SHA["snippet/edit-file"] } + let(:ref) { "refs/heads/snippet/edit-file" } + let(:changes) { "#{oldrev} #{newrev} #{ref}" } + + shared_examples_for 'a push to repository already over the limit' do + it 'errs' do + expect(snippet.repository_size_checker).to receive(:above_size_limit?).and_return(true) + + expect do + push_access_check + end.to raise_error(described_class::ForbiddenError, /Your push has been rejected/) + end + end + + shared_examples_for 'a push to repository below the limit' do + it 'does not err' do + expect(snippet.repository_size_checker).to receive(:above_size_limit?).and_return(false) + expect(snippet.repository_size_checker) + .to receive(:changes_will_exceed_size_limit?) + .with(change_size) + .and_return(false) + + expect { push_access_check }.not_to raise_error + end + end + + shared_examples_for 'a push to repository to make it over the limit' do + it 'errs' do + expect(snippet.repository_size_checker).to receive(:above_size_limit?).and_return(false) + expect(snippet.repository_size_checker) + .to receive(:changes_will_exceed_size_limit?) + .with(change_size) + .and_return(true) + + expect do + push_access_check + end.to raise_error(described_class::ForbiddenError, /Your push to this repository would cause it to exceed the size limit/) + end + end + + context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is set' do + let(:change_size) { 100 } + + before do + allow(Gitlab::Git::HookEnv) + .to receive(:all) + .with(repository.gl_repository) + .and_return({ 'GIT_OBJECT_DIRECTORY_RELATIVE' => 'objects' }) + + # Stub the object directory size to "simulate" quarantine size + allow(repository).to receive(:object_directory_size).and_return(change_size) + end + + it_behaves_like 'a push to repository already over the limit' + it_behaves_like 'a push to repository below the limit' + it_behaves_like 'a push to repository to make it over the limit' + end + + context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is not set' do + let(:change_size) { 200 } + + before do + allow(snippet.repository).to receive(:new_blobs).and_return( + [double(:blob, size: change_size)] + ) + end + + it_behaves_like 'a push to repository already over the limit' + it_behaves_like 'a push to repository below the limit' + it_behaves_like 'a push to repository to make it over the limit' + end + end + private def raise_snippet_not_found |