mirror of
https://github.com/internetee/registry.git
synced 2025-05-30 17:33:57 +02:00
Improve ip whitelist #2713
This commit is contained in:
parent
afb3d7ed1d
commit
a4ccc5749e
6 changed files with 19 additions and 13 deletions
|
@ -47,16 +47,6 @@ class Registrar::SessionsController < Devise::SessionsController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless @api_user.registrar.registrar_ip_white?(request.ip)
|
|
||||||
@depp_user.errors.add(:base, I18n.t(:ip_is_not_whitelisted))
|
|
||||||
end
|
|
||||||
|
|
||||||
if @api_user.can_make_api_calls?
|
|
||||||
unless @api_user.registrar.api_ip_white?(request.ip)
|
|
||||||
@depp_user.errors.add(:base, I18n.t(:ip_is_not_whitelisted))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if @depp_user.errors.none? && @depp_user.valid?
|
if @depp_user.errors.none? && @depp_user.valid?
|
||||||
if @api_user.active?
|
if @api_user.active?
|
||||||
sign_in @api_user
|
sign_in @api_user
|
||||||
|
|
|
@ -9,6 +9,8 @@ class RegistrarController < ApplicationController
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/PerceivedComplexity
|
||||||
|
# rubocop:disable Metrics/CyclomaticComplexity
|
||||||
def check_ip
|
def check_ip
|
||||||
return unless current_user
|
return unless current_user
|
||||||
unless current_user.is_a? ApiUser
|
unless current_user.is_a? ApiUser
|
||||||
|
@ -16,11 +18,20 @@ class RegistrarController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
return if Rails.env.development?
|
return if Rails.env.development?
|
||||||
return if current_user.registrar.registrar_ip_white?(request.ip)
|
riw = current_user.registrar.registrar_ip_white?(request.ip)
|
||||||
|
|
||||||
|
aiw = true
|
||||||
|
if current_user.can_make_api_calls?
|
||||||
|
aiw = current_user.registrar.api_ip_white?(request.ip)
|
||||||
|
end
|
||||||
|
|
||||||
|
return if riw && aiw
|
||||||
flash[:alert] = t('access_denied')
|
flash[:alert] = t('access_denied')
|
||||||
sign_out(current_user)
|
sign_out(current_user)
|
||||||
redirect_to registrar_login_path and return
|
redirect_to registrar_login_path and return
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/PerceivedComplexity
|
||||||
|
# rubocop:enable Metrics/CyclomaticComplexity
|
||||||
|
|
||||||
helper_method :head_title_sufix
|
helper_method :head_title_sufix
|
||||||
def head_title_sufix
|
def head_title_sufix
|
||||||
|
|
|
@ -911,3 +911,5 @@ en:
|
||||||
pending_epp: Pending epp
|
pending_epp: Pending epp
|
||||||
id: ID
|
id: ID
|
||||||
hidden: '[hidden]'
|
hidden: '[hidden]'
|
||||||
|
registrar_ip_is_not_whitelisted: 'Registrar IP is not whitelisted'
|
||||||
|
api_ip_is_not_whitelisted: 'API IP is not whitelisted'
|
||||||
|
|
|
@ -9,7 +9,7 @@ Fabricator(:registrar) do
|
||||||
country_code 'EE'
|
country_code 'EE'
|
||||||
code { sequence(:code) { |i| "REGISTRAR#{i}" } }
|
code { sequence(:code) { |i| "REGISTRAR#{i}" } }
|
||||||
reference_no { sequence(:reference_no) { |i| "RF#{i}" } }
|
reference_no { sequence(:reference_no) { |i| "RF#{i}" } }
|
||||||
white_ips { [Fabricate(:white_ip)] }
|
white_ips { [Fabricate(:white_ip), Fabricate(:white_ip, interface: WhiteIp::REGISTRAR)] }
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:registrar_with_no_account_activities, from: :registrar) do
|
Fabricator(:registrar_with_no_account_activities, from: :registrar) do
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Fabricator(:white_ip) do
|
Fabricator(:white_ip) do
|
||||||
ipv4 '127.0.0.1'
|
ipv4 '127.0.0.1'
|
||||||
interface WhiteIp::GLOBAL
|
interface WhiteIp::API
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:white_ip_registrar, from: :white_ip) do
|
Fabricator(:white_ip_registrar, from: :white_ip) do
|
||||||
|
|
|
@ -3,6 +3,7 @@ require 'rails_helper'
|
||||||
feature 'Sessions', type: :feature do
|
feature 'Sessions', type: :feature do
|
||||||
context 'with invalid ip' do
|
context 'with invalid ip' do
|
||||||
it 'should not see login page' do
|
it 'should not see login page' do
|
||||||
|
Setting.registrar_ip_whitelist_enabled = true
|
||||||
WhiteIp.destroy_all
|
WhiteIp.destroy_all
|
||||||
visit registrar_login_path
|
visit registrar_login_path
|
||||||
page.should have_text('Access denied')
|
page.should have_text('Access denied')
|
||||||
|
@ -36,6 +37,7 @@ feature 'Sessions', type: :feature do
|
||||||
|
|
||||||
it 'should get in with invalid when whitelist disabled' do
|
it 'should get in with invalid when whitelist disabled' do
|
||||||
Setting.registrar_ip_whitelist_enabled = false
|
Setting.registrar_ip_whitelist_enabled = false
|
||||||
|
Setting.api_ip_whitelist_enabled = false
|
||||||
Fabricate(:registrar, white_ips: [Fabricate(:white_ip), Fabricate(:white_ip_registrar)])
|
Fabricate(:registrar, white_ips: [Fabricate(:white_ip), Fabricate(:white_ip_registrar)])
|
||||||
@api_user_invalid_ip = Fabricate(
|
@api_user_invalid_ip = Fabricate(
|
||||||
:api_user, identity_code: '37810013294', registrar: Fabricate(:registrar, white_ips: [])
|
:api_user, identity_code: '37810013294', registrar: Fabricate(:registrar, white_ips: [])
|
||||||
|
@ -46,6 +48,7 @@ feature 'Sessions', type: :feature do
|
||||||
click_button 'Log in'
|
click_button 'Log in'
|
||||||
page.should have_text('Log out')
|
page.should have_text('Log out')
|
||||||
Setting.registrar_ip_whitelist_enabled = true
|
Setting.registrar_ip_whitelist_enabled = true
|
||||||
|
Setting.api_ip_whitelist_enabled = true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not get in with invalid user' do
|
it 'should not get in with invalid user' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue