mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 21:46:24 +02:00
Updated base_test
This commit is contained in:
parent
52405e1796
commit
fe6015491c
7 changed files with 59 additions and 15 deletions
|
@ -51,13 +51,39 @@ class ReppV1BaseTest < ActionDispatch::IntegrationTest
|
|||
whiteip.update(ipv4: '1.1.1.1')
|
||||
|
||||
get repp_v1_contacts_path, headers: @auth_headers
|
||||
|
||||
assert_unauthorized_ip
|
||||
|
||||
Setting.api_ip_whitelist_enabled = false
|
||||
Setting.registrar_ip_whitelist_enabled = false
|
||||
end
|
||||
|
||||
def test_takes_ip_whitelist_into_account_if_webclient_request
|
||||
Setting.api_ip_whitelist_enabled = true
|
||||
Setting.registrar_ip_whitelist_enabled = true
|
||||
|
||||
whiteip = white_ips(:one)
|
||||
whiteip.update(interfaces: ['api'])
|
||||
|
||||
Repp::V1::BaseController.stub_any_instance(:webclient_request?, true) do
|
||||
Repp::V1::BaseController.stub_any_instance(:validate_webclient_ca, true) do
|
||||
get repp_v1_contacts_path, headers: @auth_headers.merge!({ 'X-Client-IP' => whiteip.ipv4 })
|
||||
end
|
||||
end
|
||||
|
||||
assert_unauthorized_ip
|
||||
|
||||
Setting.api_ip_whitelist_enabled = false
|
||||
Setting.registrar_ip_whitelist_enabled = false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_unauthorized_ip
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :unauthorized
|
||||
assert_equal 2202, response_json[:code]
|
||||
assert response_json[:message].include? 'Access denied from IP'
|
||||
|
||||
Setting.api_ip_whitelist_enabled = false
|
||||
Setting.registrar_ip_whitelist_enabled = false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class ReppV1RegistrarAuthCheckInfoTest < ActionDispatch::IntegrationTest
|
|||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
|
||||
adapter = ENV["shunter_default_adapter"].constantize.new
|
||||
adapter = ENV['shunter_default_adapter'].constantize.new
|
||||
adapter&.clear!
|
||||
end
|
||||
|
||||
|
@ -40,8 +40,8 @@ class ReppV1RegistrarAuthCheckInfoTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_returns_error_response_if_throttled
|
||||
ENV["shunter_default_threshold"] = '1'
|
||||
ENV["shunter_enabled"] = 'true'
|
||||
ENV['shunter_default_threshold'] = '1'
|
||||
ENV['shunter_enabled'] = 'true'
|
||||
|
||||
get '/repp/v1/registrar/auth', headers: @auth_headers
|
||||
get '/repp/v1/registrar/auth', headers: @auth_headers
|
||||
|
@ -50,7 +50,7 @@ class ReppV1RegistrarAuthCheckInfoTest < ActionDispatch::IntegrationTest
|
|||
assert_response :bad_request
|
||||
assert_equal json[:code], 2502
|
||||
assert response.body.include?(Shunter.default_error_message)
|
||||
ENV["shunter_default_threshold"] = '10000'
|
||||
ENV["shunter_enabled"] = 'false'
|
||||
ENV['shunter_default_threshold'] = '10000'
|
||||
ENV['shunter_enabled'] = 'false'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue