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
path: root/spec
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-08-25 04:30:12 +0300
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-11-06 17:33:10 +0300
commita7b7a2253c41267fb67d8f56b4c2f92293601a9d (patch)
tree7fde23c006f1b6e0b8ab9939b8141629ba246a26 /spec
parentca049902dc7dad6e6177b05c8e3dc74c00487d27 (diff)
Prevent git push when LFS objects are missing
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/checks/change_access_spec.rb55
1 files changed, 53 insertions, 2 deletions
diff --git a/spec/lib/gitlab/checks/change_access_spec.rb b/spec/lib/gitlab/checks/change_access_spec.rb
index 6c25b7349e1..3a7d3f2176b 100644
--- a/spec/lib/gitlab/checks/change_access_spec.rb
+++ b/spec/lib/gitlab/checks/change_access_spec.rb
@@ -11,13 +11,19 @@ describe Gitlab::Checks::ChangeAccess do
let(:changes) { { oldrev: oldrev, newrev: newrev, ref: ref } }
let(:protocol) { 'ssh' }
- subject do
+ let(:change_access) do
described_class.new(
changes,
project: project,
user_access: user_access,
protocol: protocol
- ).exec
+ )
+ end
+
+ subject do
+ # TODO: Replace use of `subject` with `subject.exec`
+ # Then rename change_access back to subject
+ change_access.exec
end
before do
@@ -163,5 +169,50 @@ describe Gitlab::Checks::ChangeAccess do
end
end
end
+
+ context 'LFS integrity check' do
+ let(:blob_object) { project.repository.blob_at_branch('lfs', 'files/lfs/lfs_object.iso') }
+
+ before do
+ allow_any_instance_of(Gitlab::Git::RevList).to receive(:new_objects) do |&lazy_block|
+ lazy_block.call([blob_object.id])
+ end
+ end
+
+ context 'with LFS not enabled' do
+ it 'skips integrity check' do
+ expect_any_instance_of(Gitlab::Git::RevList).not_to receive(:new_objects)
+
+ change_access.exec
+ end
+ end
+
+ context 'with LFS enabled' do
+ before do
+ allow(project).to receive(:lfs_enabled?).and_return(true)
+ end
+
+ context 'deletion' do
+ let(:changes) { { oldrev: oldrev, ref: ref } }
+
+ it 'skips integrity check' do
+ expect_any_instance_of(Gitlab::Git::RevList).not_to receive(:new_objects)
+
+ change_access.exec
+ end
+ end
+
+ it 'fails if any LFS blobs are missing' do
+ expect { change_access.exec }.to raise_error(Gitlab::GitAccess::UnauthorizedError, /LFS objects are missing/)
+ end
+
+ it 'succeeds if LFS objects have already been uploaded' do
+ lfs_object = create(:lfs_object, oid: blob_object.lfs_oid)
+ create(:lfs_objects_project, project: project, lfs_object: lfs_object)
+
+ expect { change_access.exec }.not_to raise_error
+ end
+ end
+ end
end
end