mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Merge repp, epp in IP whitelist
This commit is contained in:
parent
de60ad8e76
commit
df47e21086
7 changed files with 11 additions and 26 deletions
|
@ -9,7 +9,7 @@ module Repp
|
||||||
|
|
||||||
before do
|
before do
|
||||||
if request.ip != ENV['webclient_ip']
|
if request.ip != ENV['webclient_ip']
|
||||||
error! I18n.t('ip_is_not_whitelisted'), 401 unless @current_user.registrar.repp_ip_white?(request.ip)
|
error! I18n.t('ip_is_not_whitelisted'), 401 unless @current_user.registrar.api_ip_white?(request.ip)
|
||||||
end
|
end
|
||||||
|
|
||||||
next if Rails.env.test? || Rails.env.development?
|
next if Rails.env.test? || Rails.env.development?
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Epp::SessionsController < EppController
|
||||||
def ip_white?
|
def ip_white?
|
||||||
return true if request.ip == ENV['webclient_ip']
|
return true if request.ip == ENV['webclient_ip']
|
||||||
if @api_user
|
if @api_user
|
||||||
unless @api_user.registrar.epp_ip_white?(request.ip)
|
unless @api_user.registrar.api_ip_white?(request.ip)
|
||||||
@msg = t('ip_is_not_whitelisted')
|
@msg = t('ip_is_not_whitelisted')
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
@ -147,12 +147,8 @@ class Registrar < ActiveRecord::Base
|
||||||
self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present?
|
self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def repp_ip_white?(ip)
|
def api_ip_white?(ip)
|
||||||
white_ips.repp.pluck(:ipv4, :ipv6).flatten.include?(ip) || global_ip_white?(ip)
|
white_ips.api.pluck(:ipv4, :ipv6).flatten.include?(ip) || global_ip_white?(ip)
|
||||||
end
|
|
||||||
|
|
||||||
def epp_ip_white?(ip)
|
|
||||||
white_ips.epp.pluck(:ipv4, :ipv6).flatten.include?(ip) || global_ip_white?(ip)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrar_ip_white?(ip)
|
def registrar_ip_white?(ip)
|
||||||
|
|
|
@ -13,15 +13,12 @@ class WhiteIp < ActiveRecord::Base
|
||||||
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
|
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
|
||||||
end
|
end
|
||||||
|
|
||||||
EPP = 'epp'
|
API = 'api'
|
||||||
REPP = 'repp'
|
|
||||||
REGISTRAR = 'registrar'
|
REGISTRAR = 'registrar'
|
||||||
GLOBAL = 'global'
|
GLOBAL = 'global'
|
||||||
|
INTERFACES = [GLOBAL, API, REGISTRAR]
|
||||||
|
|
||||||
INTERFACES = [GLOBAL, EPP, REPP, REGISTRAR]
|
scope :api, -> { where(interface: API) }
|
||||||
|
|
||||||
scope :epp, -> { where(interface: EPP) }
|
|
||||||
scope :repp, -> { where(interface: REPP) }
|
|
||||||
scope :registrar, -> { where(interface: REGISTRAR) }
|
scope :registrar, -> { where(interface: REGISTRAR) }
|
||||||
scope :global, -> { where(interface: GLOBAL) }
|
scope :global, -> { where(interface: GLOBAL) }
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,6 @@ Fabricator(:white_ip) do
|
||||||
interface WhiteIp::GLOBAL
|
interface WhiteIp::GLOBAL
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:white_ip_repp, from: :white_ip) do
|
|
||||||
interface WhiteIp::REPP
|
|
||||||
end
|
|
||||||
|
|
||||||
Fabricator(:white_ip_epp, from: :white_ip) do
|
|
||||||
interface WhiteIp::EPP
|
|
||||||
end
|
|
||||||
|
|
||||||
Fabricator(:white_ip_registrar, from: :white_ip) do
|
Fabricator(:white_ip_registrar, from: :white_ip) do
|
||||||
interface WhiteIp::REGISTRAR
|
interface WhiteIp::REGISTRAR
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ feature 'Api users', type: :feature do
|
||||||
|
|
||||||
fill_in 'IPv4', with: '192.168.1.1'
|
fill_in 'IPv4', with: '192.168.1.1'
|
||||||
fill_in 'IPv6', with: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
|
fill_in 'IPv6', with: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
|
||||||
select 'REPP', from: 'Interface'
|
select 'API', from: 'Interface'
|
||||||
click_button 'Save'
|
click_button 'Save'
|
||||||
|
|
||||||
page.should have_text('Record created')
|
page.should have_text('Record created')
|
||||||
|
@ -34,14 +34,14 @@ feature 'Api users', type: :feature do
|
||||||
page.should have_link(@registrar.to_s)
|
page.should have_link(@registrar.to_s)
|
||||||
page.should have_text('192.168.1.1')
|
page.should have_text('192.168.1.1')
|
||||||
page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')
|
page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')
|
||||||
page.should have_text('REPP')
|
page.should have_text('API')
|
||||||
|
|
||||||
click_link @registrar.to_s
|
click_link @registrar.to_s
|
||||||
|
|
||||||
current_path.should == "/admin/registrars/#{@registrar.id}"
|
current_path.should == "/admin/registrars/#{@registrar.id}"
|
||||||
page.should have_text('192.168.1.1')
|
page.should have_text('192.168.1.1')
|
||||||
page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')
|
page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')
|
||||||
page.should have_text('REPP')
|
page.should have_text('API')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not add invalid ip to registrar' do
|
it 'should not add invalid ip to registrar' do
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'rails_helper'
|
||||||
describe Repp::AccountV1 do
|
describe Repp::AccountV1 do
|
||||||
it 'should fail without whitelisted IP' do
|
it 'should fail without whitelisted IP' do
|
||||||
ENV['webclient_ip'] = '192.188.1.1'
|
ENV['webclient_ip'] = '192.188.1.1'
|
||||||
@registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip_epp), Fabricate(:white_ip_registrar)])
|
@registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip_registrar)])
|
||||||
@api_user = Fabricate(:api_user, registrar: @registrar1)
|
@api_user = Fabricate(:api_user, registrar: @registrar1)
|
||||||
|
|
||||||
get_with_auth '/repp/v1/accounts/balance', {}, @api_user
|
get_with_auth '/repp/v1/accounts/balance', {}, @api_user
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue