mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +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
|
||||
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
|
||||
|
||||
next if Rails.env.test? || Rails.env.development?
|
||||
|
|
|
@ -37,7 +37,7 @@ class Epp::SessionsController < EppController
|
|||
def ip_white?
|
||||
return true if request.ip == ENV['webclient_ip']
|
||||
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')
|
||||
return false
|
||||
end
|
||||
|
|
|
@ -147,12 +147,8 @@ class Registrar < ActiveRecord::Base
|
|||
self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present?
|
||||
end
|
||||
|
||||
def repp_ip_white?(ip)
|
||||
white_ips.repp.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)
|
||||
def api_ip_white?(ip)
|
||||
white_ips.api.pluck(:ipv4, :ipv6).flatten.include?(ip) || global_ip_white?(ip)
|
||||
end
|
||||
|
||||
def registrar_ip_white?(ip)
|
||||
|
|
|
@ -13,15 +13,12 @@ class WhiteIp < ActiveRecord::Base
|
|||
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
|
||||
end
|
||||
|
||||
EPP = 'epp'
|
||||
REPP = 'repp'
|
||||
API = 'api'
|
||||
REGISTRAR = 'registrar'
|
||||
GLOBAL = 'global'
|
||||
INTERFACES = [GLOBAL, API, REGISTRAR]
|
||||
|
||||
INTERFACES = [GLOBAL, EPP, REPP, REGISTRAR]
|
||||
|
||||
scope :epp, -> { where(interface: EPP) }
|
||||
scope :repp, -> { where(interface: REPP) }
|
||||
scope :api, -> { where(interface: API) }
|
||||
scope :registrar, -> { where(interface: REGISTRAR) }
|
||||
scope :global, -> { where(interface: GLOBAL) }
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@ Fabricator(:white_ip) do
|
|||
interface WhiteIp::GLOBAL
|
||||
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
|
||||
interface WhiteIp::REGISTRAR
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ feature 'Api users', type: :feature do
|
|||
|
||||
fill_in 'IPv4', with: '192.168.1.1'
|
||||
fill_in 'IPv6', with: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
|
||||
select 'REPP', from: 'Interface'
|
||||
select 'API', from: 'Interface'
|
||||
click_button 'Save'
|
||||
|
||||
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_text('192.168.1.1')
|
||||
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
|
||||
|
||||
current_path.should == "/admin/registrars/#{@registrar.id}"
|
||||
page.should have_text('192.168.1.1')
|
||||
page.should have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329')
|
||||
page.should have_text('REPP')
|
||||
page.should have_text('API')
|
||||
end
|
||||
|
||||
it 'should not add invalid ip to registrar' do
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'rails_helper'
|
|||
describe Repp::AccountV1 do
|
||||
it 'should fail without whitelisted IP' do
|
||||
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)
|
||||
|
||||
get_with_auth '/repp/v1/accounts/balance', {}, @api_user
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue