mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
refactoring
This commit is contained in:
parent
03add1183b
commit
28b7acfc96
3 changed files with 68 additions and 45 deletions
|
@ -7,20 +7,23 @@ class Registrar
|
|||
ipv6 = params[:ipv6].split("\r\n")
|
||||
|
||||
domains = domain_list_from_csv
|
||||
|
||||
|
||||
return csv_list_empty_guard if domains == []
|
||||
|
||||
uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
|
||||
request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
|
||||
request.body = { data: { type: 'nameserver', id: params[:old_hostname],
|
||||
domains: domains || [],
|
||||
attributes: { hostname: params[:new_hostname],
|
||||
ipv4: ipv4,
|
||||
ipv6: ipv6 } } }.to_json
|
||||
request.basic_auth(current_registrar_user.username,
|
||||
current_registrar_user.plain_text_password)
|
||||
# uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
|
||||
# request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
|
||||
# request.body = { data: { type: 'nameserver', id: params[:old_hostname],
|
||||
# domains: domains || [],
|
||||
# attributes: { hostname: params[:new_hostname],
|
||||
# ipv4: ipv4,
|
||||
# ipv6: ipv6 } } }.to_json
|
||||
# request.basic_auth(current_registrar_user.username,
|
||||
# current_registrar_user.plain_text_password)
|
||||
|
||||
response = do_request(request, uri)
|
||||
# response = do_request(request, uri)
|
||||
|
||||
response = Actions::NameserverBulkChange.new(domains, params)
|
||||
response.call
|
||||
|
||||
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
|
@ -51,12 +54,13 @@ class Registrar
|
|||
end
|
||||
|
||||
def domain_list_from_csv
|
||||
return if params[:puny_file].blank?
|
||||
return [] if params[:puny_file].blank?
|
||||
|
||||
domains = []
|
||||
csv = CSV.read(params[:puny_file].path, headers: true)
|
||||
|
||||
return if csv['domain_name'].blank?
|
||||
return [] if csv['domain_name'].blank?
|
||||
|
||||
csv.map { |b| domains << b['domain_name'] }
|
||||
|
||||
domains.compact
|
||||
|
|
24
app/interactions/actions/nameserver_bulk_change.rb
Normal file
24
app/interactions/actions/nameserver_bulk_change.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Actions
|
||||
class NameserverBulkChange
|
||||
def initialize(domains, params, ipv4, ipv6)
|
||||
@domains = domains
|
||||
@params = params
|
||||
@ipv4 = ipv4
|
||||
@ipv6 = ipv6
|
||||
end
|
||||
|
||||
def call
|
||||
uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
|
||||
request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json')
|
||||
request.body = { data: { type: 'nameserver', id: @params[:old_hostname],
|
||||
domains: @domains || [],
|
||||
attributes: { hostname: @params[:new_hostname],
|
||||
ipv4: ipv4,
|
||||
ipv6: ipv6 } } }.to_json
|
||||
request.basic_auth(current_registrar_user.username,
|
||||
current_registrar_user.plain_text_password)
|
||||
|
||||
response = do_request(request, uri)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -98,41 +98,36 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
|
|||
def test_replaces_nameservers_with_invalid_domains_list
|
||||
request_body = { data: { type: 'nameserver',
|
||||
id: 'ns1.bestnames.test',
|
||||
domains: ['shop.test'],
|
||||
attributes: { hostname: 'new-ns.bestnames.test',
|
||||
ipv4: %w[192.0.2.55 192.0.2.56],
|
||||
ipv6: %w[2001:db8::55 2001:db8::56] } } }
|
||||
domains: [],
|
||||
attributes: { hostname: 'new-ns.bestnames.test',
|
||||
ipv4: %w[192.0.2.55 192.0.2.56],
|
||||
ipv6: %w[2001:db8::55 2001:db8::56] } } }
|
||||
request_stub = stub_request(:put, "http://epp:3000/repp/v1/registrar/nameservers").
|
||||
with(
|
||||
body: request_body,
|
||||
headers: {
|
||||
'Accept'=>'*/*',
|
||||
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization'=>'Basic dGVzdF9nb29kbmFtZXM6dGVzdHRlc3Q=',
|
||||
'Content-Type'=>'application/json',
|
||||
'Host'=>'epp:3000',
|
||||
'User-Agent'=>'Ruby'
|
||||
}).
|
||||
to_return(status: 200, body: "", headers: {})
|
||||
|
||||
request_stub = stub_request(:put, /registrar\/nameservers/).
|
||||
with(
|
||||
body: "{\"data\":{\"type\":\"nameserver\",\"id\":\"ns1.bestnames.test\",\"domains\":[],\"attributes\":{\"hostname\":\"new-ns.bestnames.test\",\"ipv4\":[\"192.0.2.55\",\"192.0.2.56\"],\"ipv6\":[\"2001:db8::55\",\"2001:db8::56\"]}}}",
|
||||
headers: {
|
||||
'Accept'=>'*/*',
|
||||
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization'=>'Basic dGVzdF9nb29kbmFtZXM6dGVzdHRlc3Q=',
|
||||
'Content-Type'=>'application/json',
|
||||
'Host'=>'epp:3000',
|
||||
'User-Agent'=>'Ruby'
|
||||
}).
|
||||
to_return(status: 200, body: "", headers: {})
|
||||
visit registrar_domains_url
|
||||
click_link 'Bulk change'
|
||||
click_link 'Nameserver'
|
||||
|
||||
visit registrar_domains_url
|
||||
click_link 'Bulk change'
|
||||
click_link 'Nameserver'
|
||||
fill_in 'Old hostname', with: 'ns1.bestnames.test'
|
||||
fill_in 'New hostname', with: 'new-ns.bestnames.test'
|
||||
fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56"
|
||||
fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56"
|
||||
attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'invalid_domains_for_ns_replacement.csv').to_s
|
||||
|
||||
fill_in 'Old hostname', with: 'ns1.bestnames.test'
|
||||
fill_in 'New hostname', with: 'new-ns.bestnames.test'
|
||||
fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56"
|
||||
fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56"
|
||||
attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'invalid_domains_for_ns_replacement.csv').to_s
|
||||
click_on 'Replace nameserver'
|
||||
|
||||
assert_no_changes -> { Domain.find_by(name: 'shop.test').nameservers } do
|
||||
click_on 'Replace nameserver'
|
||||
end
|
||||
|
||||
assert_requested request_stub
|
||||
|
||||
assert_text 'CSV scoped domain list seems empty. Make sure that domains are added and ' \
|
||||
'"domain_name" header is present.'
|
||||
assert_requested request_stub
|
||||
assert_current_path registrar_domains_path
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue