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