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>2020-02-22 15:08:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-22 15:08:58 +0300
commited45528885b7b44c61f18175fe7cdbda12360669 (patch)
tree3d27c00a8a83d569cf238eaa05b7eb24b7a28a8d /spec/lib/gitlab
parentab85af0f318ccbcfdd508e7a2f85788f26831785 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/rate_limit_helpers_spec.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/lib/gitlab/rate_limit_helpers_spec.rb b/spec/lib/gitlab/rate_limit_helpers_spec.rb
new file mode 100644
index 00000000000..7eee30d60ca
--- /dev/null
+++ b/spec/lib/gitlab/rate_limit_helpers_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::RateLimitHelpers, :clean_gitlab_redis_shared_state do
+ let(:limiter_class) do
+ Class.new do
+ include ::Gitlab::RateLimitHelpers
+
+ attr_reader :request
+
+ def initialize(request)
+ @request = request
+ end
+ end
+ end
+
+ let(:request) { instance_double(ActionDispatch::Request, request_method: 'GET', ip: '127.0.0.1', fullpath: '/') }
+ let(:class_instance) { limiter_class.new(request) }
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+
+ describe '#archive_rate_limit_reached?' do
+ context 'with a user' do
+ it 'rate limits the user properly' do
+ 5.times do
+ expect(class_instance.archive_rate_limit_reached?(user, project)).to be_falsey
+ end
+
+ expect(class_instance.archive_rate_limit_reached?(user, project)).to be_truthy
+ end
+ end
+
+ context 'with an anonymous user' do
+ before do
+ stub_const('Gitlab::RateLimitHelpers::ARCHIVE_RATE_ANONYMOUS_THRESHOLD', 2)
+ end
+
+ it 'rate limits with higher limits' do
+ 2.times do
+ expect(class_instance.archive_rate_limit_reached?(nil, project)).to be_falsey
+ end
+
+ expect(class_instance.archive_rate_limit_reached?(nil, project)).to be_truthy
+ end
+ end
+ end
+end