2019-10-09 08:06:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RackAttackSpecHelpers
|
|
|
|
def api_get_args_with_token_headers(partial_url, token_headers)
|
|
|
|
["/api/#{API::API.version}#{partial_url}", params: nil, headers: token_headers]
|
|
|
|
end
|
|
|
|
|
|
|
|
def rss_url(user)
|
|
|
|
"/dashboard/projects.atom?feed_token=#{user.feed_token}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def private_token_headers(user)
|
|
|
|
{ 'HTTP_PRIVATE_TOKEN' => user.private_token }
|
|
|
|
end
|
|
|
|
|
|
|
|
def personal_access_token_headers(personal_access_token)
|
|
|
|
{ 'HTTP_PRIVATE_TOKEN' => personal_access_token.token }
|
|
|
|
end
|
|
|
|
|
|
|
|
def oauth_token_headers(oauth_access_token)
|
|
|
|
{ 'AUTHORIZATION' => "Bearer #{oauth_access_token.token}" }
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_rejection(&block)
|
|
|
|
yield
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:too_many_requests)
|
2019-10-09 08:06:13 -04:00
|
|
|
end
|
2020-07-16 20:09:37 -04:00
|
|
|
|
|
|
|
def expect_ok(&block)
|
|
|
|
yield
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
def random_next_ip
|
|
|
|
allow_next_instance_of(Rack::Attack::Request) do |instance|
|
|
|
|
allow(instance).to receive(:ip).and_return(FFaker::Internet.ip_v4_address)
|
|
|
|
end
|
|
|
|
end
|
2019-10-09 08:06:13 -04:00
|
|
|
end
|