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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-29 11:23:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-29 11:23:24 +0300
commit2234b4382091add4dfe8d44f4e0764bf64ff8c5e (patch)
tree2e16ea43616574e4612223b7cdb70322ce914648 /spec/models/packages/package_file_spec.rb
parent6c85cb2ff17cf4ea34372e84ef579734fd607cec (diff)
Add latest changes from gitlab-org/security/gitlab@14-10-stable-ee
Diffstat (limited to 'spec/models/packages/package_file_spec.rb')
-rw-r--r--spec/models/packages/package_file_spec.rb43
1 files changed, 36 insertions, 7 deletions
diff --git a/spec/models/packages/package_file_spec.rb b/spec/models/packages/package_file_spec.rb
index f6af8f6a951..82f5b44f38f 100644
--- a/spec/models/packages/package_file_spec.rb
+++ b/spec/models/packages/package_file_spec.rb
@@ -29,19 +29,48 @@ RSpec.describe Packages::PackageFile, type: :model do
let(:package_file) { package.package_files.first }
let(:status) { :default }
+ let(:file_name) { 'foo' }
let(:file) { fixture_file_upload('spec/fixtures/dk.png') }
+ let(:params) { { file: file, file_name: file_name, status: status } }
- subject { package.package_files.create!(file: file, file_name: package_file.file_name, status: status) }
+ subject { package.package_files.create!(params) }
- it 'can not save a duplicated file' do
- expect { subject }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: File name has already been taken")
+ context 'file_name' do
+ let(:file_name) { package_file.file_name }
+
+ it 'can not save a duplicated file' do
+ expect { subject }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: File name has already been taken")
+ end
+
+ context 'with a pending destruction package duplicated file' do
+ let(:status) { :pending_destruction }
+
+ it 'can save it' do
+ expect { subject }.to change { package.package_files.count }.from(1).to(2)
+ end
+ end
end
- context 'with a pending destruction package duplicated file' do
- let(:status) { :pending_destruction }
+ context 'file_sha256' do
+ where(:sha256_value, :expected_success) do
+ 'a' * 64 | true
+ nil | true
+ 'a' * 63 | false
+ 'a' * 65 | false
+ 'a' * 63 + '%' | false
+ '' | false
+ end
+
+ with_them do
+ let(:params) { super().merge({ file_sha256: sha256_value }) }
- it 'can save it' do
- expect { subject }.to change { package.package_files.count }.from(1).to(2)
+ it 'does not allow invalid sha256 characters' do
+ if expected_success
+ expect { subject }.not_to raise_error
+ else
+ expect { subject }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: File sha256 is invalid")
+ end
+ end
end
end
end