Skip to content
Snippets Groups Projects
Commit 470b5dc3 authored by Francisco Javier López's avatar Francisco Javier López
Browse files

Updated refactor and pushing to see if test fails

parent c491b950
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -72,8 +72,6 @@ module API
end
end
 
private
def raise_unauthorized_error!
raise UnauthorizedError
end
Loading
Loading
Loading
Loading
@@ -19,22 +19,6 @@ module Gitlab
user
end
 
def private_token
request.params[:private_token].presence ||
request.headers['PRIVATE-TOKEN'].presence
end
def find_user_by_authentication_token(token_string)
User.find_by_authentication_token(token_string)
end
def find_user_by_personal_access_token(token_string)
access_token = PersonalAccessToken.find_by_token(token_string)
return unless access_token
find_user_by_access_token(access_token)
end
def find_user_by_rss_token
return unless request.path.ends_with?('atom') || request.format.atom?
 
Loading
Loading
@@ -55,6 +39,24 @@ module Gitlab
find_user_by_access_token(access_token)
end
 
private
def private_token
request.params[:private_token].presence ||
request.headers['PRIVATE-TOKEN'].presence
end
def find_user_by_authentication_token(token_string)
User.find_by_authentication_token(token_string)
end
def find_user_by_personal_access_token(token_string)
access_token = PersonalAccessToken.find_by_token(token_string)
return unless access_token
find_user_by_access_token(access_token)
end
def find_oauth_access_token
return @oauth_access_token if defined?(@oauth_access_token)
 
Loading
Loading
require 'spec_helper'
 
describe 'Rack Attack global throttles' do
# If the tests are being flaky as described below, then this constant
# can be set to greater than 1 to make multiple attempts to get a 429.
#
# In tests exceeding the rate limit within a time period (which we know we
# have accomplished because we've made exactly 1 more request than allowed
# while time is stopped) we expect a 429. But sometimes we get a 200,
# sometimes for more than one request, but eventually we get a 429. This
# constant and its usages should be removed if we figure out why this happens.
# More on this:
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14708#note_45151688
NUM_TRIES_FOR_REJECTION = 1
# Extra time travel past what should be strictly necessary to ensure the
# throttle we are testing is using a cache key where the request count is 0.
#
# Why add this? Sometimes we get a 429 when we expect a 200. This constant and
# its usages should be removed if we figure out why this happens.
# More on this:
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14708#note_45151688
NEXT_TIME_PERIOD_BUFFER = 0.seconds
let(:settings) { Gitlab::CurrentSettings.current_application_settings }
 
# Start with really high limits and override them with low limits to ensure
Loading
Loading
@@ -405,11 +384,7 @@ describe 'Rack Attack global throttles' do
end
 
def expect_rejection(&block)
# NUM_TRIES_FOR_REJECTION.times do |i|
yield
# break if response.status == 429 # success
# Rails.logger.warn "Flaky test expected HTTP status 429 but got #{response.status}. Will attempt again (#{i + 1}/#{NUM_TRIES_FOR_REJECTION})" if i + 1 < NUM_TRIES_FOR_REJECTION
# end
yield
 
expect(response).to have_http_status(429)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment