File: unique_ip_check_shared_context.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (41 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download
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
# frozen_string_literal: true

RSpec.shared_context 'unique ips sign in limit' do
  include StubENV
  let(:request_context) { Gitlab::RequestContext.instance }

  before do
    redis_cache_cleanup!
    redis_queues_cleanup!
    redis_shared_state_cleanup!
  end

  before do
    stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')

    Gitlab::CurrentSettings.update!(
      unique_ips_limit_enabled: true,
      unique_ips_limit_time_window: 10000
    )

    # Make sure we're working with the same reqeust context everywhere
    allow(Gitlab::RequestContext).to receive(:instance).and_return(request_context)
  end

  def change_ip(ip)
    allow(request_context).to receive(:client_ip).and_return(ip)
  end

  def request_from_ip(ip)
    change_ip(ip)
    # Implement this method while including this shared context to simulate a request to GitLab
    # The method name gitlab_request was chosen over request to avoid conflict with rack request
    gitlab_request
    response
  end

  def operation_from_ip(ip)
    change_ip(ip)
    operation
  end
end