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-08-19 23:49:26 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-19 23:49:26 +0300
commitc46a626682d64102671f6cc07049fd271e370320 (patch)
tree96983b7d7085ea74626ebcbdbe4671f735d34120 /spec/lib/gitlab
parente78903b70c4fdfbd3bfba189fd90af18d2c861e1 (diff)
Add latest changes from gitlab-org/security/gitlab@15-3-stable-ee
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/cache/import/caching_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/lib/gitlab/cache/import/caching_spec.rb b/spec/lib/gitlab/cache/import/caching_spec.rb
index 946a7c604a1..6f9879da281 100644
--- a/spec/lib/gitlab/cache/import/caching_spec.rb
+++ b/spec/lib/gitlab/cache/import/caching_spec.rb
@@ -3,6 +3,17 @@
require 'spec_helper'
RSpec.describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
+ shared_examples 'validated redis value' do
+ let(:value) { double('value', to_s: Object.new) }
+
+ it 'raise error if value.to_s does not return a String' do
+ value_as_string = value.to_s
+ message = /Value '#{value_as_string}' of type '#{value_as_string.class}' for '#{value.inspect}' is not a String/
+
+ expect { subject }.to raise_error(message)
+ end
+ end
+
describe '.read' do
it 'reads a value from the cache' do
described_class.write('foo', 'bar')
@@ -56,6 +67,16 @@ RSpec.describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
expect(described_class.write('foo', 10)).to eq(10)
expect(described_class.read('foo')).to eq('10')
end
+
+ it_behaves_like 'validated redis value' do
+ subject { described_class.write('foo', value) }
+ end
+ end
+
+ describe '.increment_by' do
+ it_behaves_like 'validated redis value' do
+ subject { described_class.increment_by('foo', value) }
+ end
end
describe '.increment' do
@@ -78,6 +99,10 @@ RSpec.describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
expect(values).to eq(['10'])
end
+
+ it_behaves_like 'validated redis value' do
+ subject { described_class.set_add('foo', value) }
+ end
end
describe '.set_includes?' do
@@ -96,6 +121,10 @@ RSpec.describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
expect(described_class.set_includes?('foo', 10)).to eq(true)
end
+
+ it_behaves_like 'validated redis value' do
+ subject { described_class.set_includes?('foo', value) }
+ end
end
describe '.values_from_set' do
@@ -120,6 +149,10 @@ RSpec.describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
expect(values).to eq({ '1' => '1', '2' => '2' })
end
+
+ it_behaves_like 'validated redis value' do
+ subject { described_class.hash_add('foo', 1, value) }
+ end
end
describe '.values_from_hash' do
@@ -160,6 +193,12 @@ RSpec.describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
expect(found).to eq(value.to_s)
end
end
+
+ it_behaves_like 'validated redis value' do
+ let(:mapping) { { 'foo' => value, 'bar' => value } }
+
+ subject { described_class.write_multiple(mapping) }
+ end
end
describe '.expire' do
@@ -175,4 +214,10 @@ RSpec.describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
expect(found_ttl).to be <= timeout
end
end
+
+ describe '.write_if_greater' do
+ it_behaves_like 'validated redis value' do
+ subject { described_class.write_if_greater('foo', value) }
+ end
+ end
end