Welcome to mirror list, hosted at ThFree Co, Russian Federation.

repository_archive_rate_limiter_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 49df70f3cb3fcb7ad9adc996b6060ae258144ccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Gitlab::RepositoryArchiveRateLimiter do
  let(:described_class) do
    Class.new do
      include ::Gitlab::RepositoryArchiveRateLimiter

      def check_rate_limit!(**args)
      end
    end
  end

  describe "#check_archive_rate_limit!" do
    let(:project) { instance_double('Project') }
    let(:current_user) { instance_double('User') }
    let(:check) { subject.check_archive_rate_limit!(current_user, project) }

    context 'when archive_rate_limit feature flag is disabled' do
      before do
        stub_feature_flags(archive_rate_limit: false)
      end

      it 'does not check rate limit' do
        expect(subject).not_to receive(:check_rate_limit!)

        expect(check).to eq nil
      end
    end

    context 'when archive_rate_limit feature flag is enabled' do
      before do
        stub_feature_flags(archive_rate_limit: true)
      end

      context 'when current user exists' do
        it 'checks for project_repositories_archive rate limiting with default threshold' do
          expect(subject).to receive(:check_rate_limit!)
                               .with(:project_repositories_archive, scope: [project, current_user], threshold: nil)
          check
        end
      end

      context 'when current user does not exist' do
        let(:current_user) { nil }

        it 'checks for project_repositories_archive rate limiting with threshold 100' do
          expect(subject).to receive(:check_rate_limit!)
                               .with(:project_repositories_archive, scope: [project, current_user], threshold: 100)
          check
        end
      end
    end
  end
end