summaryrefslogtreecommitdiff
path: root/spec/support/helpers/rack_attack_spec_helpers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/rack_attack_spec_helpers.rb')
-rw-r--r--spec/support/helpers/rack_attack_spec_helpers.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/support/helpers/rack_attack_spec_helpers.rb b/spec/support/helpers/rack_attack_spec_helpers.rb
index a8ae69885d8..d50a6382a40 100644
--- a/spec/support/helpers/rack_attack_spec_helpers.rb
+++ b/spec/support/helpers/rack_attack_spec_helpers.rb
@@ -21,10 +21,31 @@ module RackAttackSpecHelpers
{ 'AUTHORIZATION' => "Bearer #{oauth_access_token.token}" }
end
+ def basic_auth_headers(user, personal_access_token)
+ encoded_login = ["#{user.username}:#{personal_access_token.token}"].pack('m0')
+ { 'AUTHORIZATION' => "Basic #{encoded_login}" }
+ end
+
def expect_rejection(&block)
yield
expect(response).to have_gitlab_http_status(:too_many_requests)
+
+ expect(response.headers.to_h).to include(
+ 'RateLimit-Limit' => a_string_matching(/^\d+$/),
+ 'RateLimit-Name' => a_string_matching(/^throttle_.*$/),
+ 'RateLimit-Observed' => a_string_matching(/^\d+$/),
+ 'RateLimit-Remaining' => a_string_matching(/^\d+$/),
+ 'Retry-After' => a_string_matching(/^\d+$/)
+ )
+ expect(response).to have_header('RateLimit-Reset')
+ expect do
+ DateTime.strptime(response.headers['RateLimit-Reset'], '%s')
+ end.not_to raise_error
+ expect(response).to have_header('RateLimit-ResetTime')
+ expect do
+ Time.httpdate(response.headers['RateLimit-ResetTime'])
+ end.not_to raise_error
end
def expect_ok(&block)