Merge branch 'master' into registry-623

# Conflicts:
#	db/structure.sql
This commit is contained in:
Artur Beljajev 2018-03-08 13:04:11 +02:00
commit ffc32b66de
72 changed files with 1004 additions and 932 deletions

View file

@ -9,16 +9,24 @@ john:
code: john-001
auth_info: cacb5b
william:
william: &william
name: William
email: william@inbox.test
phone: '+555.555'
fax: +555.555
ident: 1234
ident_type: priv
ident_country_code: US
registrar: bestnames
code: william-001
auth_info: 6573d0
street: Main Street
zip: 12345
city: New York
state: New York
country_code: US
statuses:
- ok
jane:
name: Jane
@ -42,6 +50,30 @@ acme_ltd:
code: acme-ltd-001
auth_info: 720b3c
jack:
name: Jack
email: jack@inbox.test
phone: '+555.555'
ident: 1234
ident_type: org
registrar: goodnames
ident_country_code: US
code: jack-001
auth_info: e2c440
identical_to_william:
<<: *william
registrar: goodnames
code: william-002
auth_info: 5ab865
not_in_use:
name: Useless
email: useless@inbox.test
registrar: bestnames
code: useless-001
auth_info: e75a2a
invalid:
name: any
code: any

View file

@ -28,6 +28,16 @@ library:
period: 1
period_unit: m
metro:
name: metro.test
name_dirty: metro.test
registrar: goodnames
registrant: jack
transfer_code: 1071ad
valid_to: 2010-07-05
period: 1
period_unit: m
invalid:
name: invalid.test
transfer_code: any

23
test/fixtures/nameservers.yml vendored Normal file
View file

@ -0,0 +1,23 @@
shop_ns1:
hostname: ns1.bestnames.test
ipv4:
- 192.0.2.1
ipv6:
- 2001:db8::1
domain: shop
shop_ns2:
hostname: ns2.bestnames.test
ipv4:
- 192.0.2.2
ipv6:
- 2001:db8::2
domain: shop
airport_ns1:
hostname: ns1.bestnames.test
domain: airport
metro_ns1:
hostname: ns1.bestnames.test
domain: metro

View file

@ -3,6 +3,7 @@ require 'test_helper'
class APIDomainTransfersTest < ActionDispatch::IntegrationTest
def setup
@domain = domains(:shop)
@new_registrar = registrars(:goodnames)
Setting.transfer_wait_time = 0 # Auto-approval
end
@ -10,7 +11,10 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200
assert_equal ({ data: [{
type: 'domain_transfer'
type: 'domain_transfer',
attributes: {
domain_name: 'shop.test'
},
}] }),
JSON.parse(response.body, symbolize_names: true)
end
@ -26,10 +30,10 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest
assert @domain.transfers.last.approved?
end
def test_changes_registrar
def test_assigns_new_registrar
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
@domain.reload
assert_equal registrars(:goodnames), @domain.registrar
assert_equal @new_registrar, @domain.registrar
end
def test_regenerates_transfer_code
@ -49,11 +53,16 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest
end
def test_duplicates_registrant_admin_and_tech_contacts
assert_difference 'Contact.count', 3 do
assert_difference -> { @new_registrar.contacts.size }, 2 do
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
end
end
def test_reuses_identical_contact
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_equal 1, @new_registrar.contacts.where(name: 'William').size
end
def test_fails_if_domain_does_not_exist
request_params = { format: :json,
data: { domainTransfers: [{ domainName: 'non-existent.test', transferCode: 'any' }] } }
@ -68,7 +77,7 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest
data: { domainTransfers: [{ domainName: 'shop.test', transferCode: 'wrong' }] } }
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
refute_equal registrars(:goodnames), @domain.registrar
refute_equal @new_registrar, @domain.registrar
assert_equal ({ errors: [{ title: 'shop.test transfer code is wrong' }] }),
JSON.parse(response.body, symbolize_names: true)
end

View file

@ -0,0 +1,97 @@
require 'test_helper'
class APINameserversPutTest < ActionDispatch::IntegrationTest
def test_replaces_registrar_nameservers
old_nameserver_ids = [nameservers(:shop_ns1).id,
nameservers(:airport_ns1).id,
nameservers(:metro_ns1).id]
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test' } } }
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_empty (old_nameserver_ids & registrars(:bestnames).nameservers(true).ids)
end
def test_saves_all_attributes
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test',
ipv4: ['192.0.2.55'],
ipv6: ['2001:db8::55'] } } }
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
new_nameserver = domains(:shop).nameservers.find_by(hostname: 'ns55.bestnames.test')
assert_equal ['192.0.2.55'], new_nameserver.ipv4
assert_equal ['2001:DB8::55'], new_nameserver.ipv6
end
def test_keeps_other_nameserver_intact
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test' } } }
other_nameserver_hash = nameservers(:shop_ns2).attributes
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_equal other_nameserver_hash, nameservers(:shop_ns2).reload.attributes
end
def test_keeps_other_registrar_nameservers_intact
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test' } } }
nameserver_hash = nameservers(:metro_ns1).attributes
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_equal nameserver_hash, nameservers(:metro_ns1).reload.attributes
end
def test_returns_new_nameserver_record
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test',
ipv4: ['192.0.2.55'],
ipv6: ['2001:db8::55'] } } }
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200
assert_equal ({ data: { type: 'nameserver',
id: 'ns55.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test',
ipv4: ['192.0.2.55'],
ipv6: ['2001:db8::55'] } } }),
JSON.parse(response.body, symbolize_names: true)
end
def test_optional_params
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test' } } }
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200
end
def test_non_existent_nameserver_hostname
request_params = { format: :json, data: { type: 'nameserver', id: 'non-existent.test',
attributes: { hostname: 'any.bestnames.test' } } }
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 404
assert_equal ({ errors: [{ title: 'Hostname non-existent.test does not exist' }] }),
JSON.parse(response.body, symbolize_names: true)
end
def test_invalid_request_params
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: '' } } }
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
assert_equal ({ errors: [{ title: 'Hostname is missing' }] }),
JSON.parse(response.body, symbolize_names: true)
end
def test_unauthenticated
put '/repp/v1/registrar/nameservers'
assert_response 401
end
private
def http_auth_key
ActionController::HttpAuthentication::Basic.encode_credentials('test_bestnames', 'testtest')
end
end

View file

@ -0,0 +1,35 @@
require 'test_helper'
class EppDomainCreateNameserversTest < ActionDispatch::IntegrationTest
# Glue record requirement
def test_nameserver_ip_address_is_required_if_hostname_is_under_the_same_domain
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>new.test</domain:name>
<domain:ns>
<domain:hostAttr>
<domain:hostName>ns1.new.test</domain:hostName>
</domain:hostAttr>
</domain:ns>
<domain:registrant>john-001</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">test</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_equal '2003', Nokogiri::XML(response.body).at_css('result')[:code]
end
end

View file

@ -3,6 +3,7 @@ require 'test_helper'
class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest
def setup
@domain = domains(:shop)
@new_registrar = registrars(:goodnames)
Setting.transfer_wait_time = 0
end
@ -24,10 +25,10 @@ class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest
'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end
def test_changes_registrar
def test_assigns_new_registrar
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
@domain.reload
assert_equal registrars(:goodnames), @domain.registrar
assert_equal @new_registrar, @domain.registrar
end
def test_regenerates_transfer_code
@ -48,11 +49,16 @@ class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest
end
def test_duplicates_registrant_admin_and_tech_contacts
assert_difference 'Contact.count', 3 do
assert_difference -> { @new_registrar.contacts.size }, 2 do
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
end
end
def test_reuses_identical_contact
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
assert_equal 1, @new_registrar.contacts.where(name: 'William').size
end
def test_saves_legal_document
assert_difference -> { @domain.legal_documents(true).size } do
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
@ -106,7 +112,7 @@ class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' }
@domain.reload
refute_equal registrars(:goodnames), @domain.registrar
refute_equal @new_registrar, @domain.registrar
assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code]
end

View file

@ -7,12 +7,14 @@ class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest
end
def test_batch_transfer_succeeds
body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
request_body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
headers = { 'Content-type' => 'application/json' }
request_stub = stub_request(:post, /domain_transfers/).with(body: body,
request_stub = stub_request(:post, /domain_transfers/).with(body: request_body,
headers: headers,
basic_auth: ['test_goodnames', 'testtest'])
.to_return(status: 204)
.to_return(body: { data: [{
type: 'domain_transfer'
}] }.to_json, status: 200)
visit registrar_domains_url
click_link 'Transfer'
@ -23,7 +25,7 @@ class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Domains have been successfully transferred'
assert_text '1 domains have been successfully transferred'
end
def test_batch_transfer_fails_gracefully

View file

@ -0,0 +1,57 @@
require 'test_helper'
class RegistrarNameserverReplacementTest < ActionDispatch::IntegrationTest
def setup
WebMock.reset!
login_as users(:api_goodnames)
end
def test_replaces_current_registrar_nameservers
request_body = { data: { type: 'nameserver',
id: 'ns1.bestnames.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] } } }
request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body,
headers: { 'Content-type' => 'application/json' },
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
type: 'nameserver',
id: 'new-ns.bestnames.test'
}] }.to_json, status: 200)
visit registrar_domains_url
click_link 'Replace 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"
click_on 'Replace nameserver'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Nameserver have been successfully replaced'
end
def test_fails_gracefully
stub_request(:put, /registrar\/nameservers/).to_return(status: 400,
body: { errors: [{ title: 'epic fail' }] }.to_json,
headers: { 'Content-type' => 'application/json' })
visit registrar_domains_url
click_link 'Replace nameserver'
fill_in 'Old hostname', with: 'old hostname'
fill_in 'New hostname', with: 'new hostname'
fill_in 'ipv4', with: 'ipv4'
fill_in 'ipv6', with: 'ipv6'
click_on 'Replace nameserver'
assert_text 'epic fail'
assert_field 'Old hostname', with: 'old hostname'
assert_field 'New hostname', with: 'new hostname'
assert_field 'ipv4', with: 'ipv4'
assert_field 'ipv6', with: 'ipv6'
end
end

View file

@ -12,4 +12,18 @@ class ContactTest < ActiveSupport::TestCase
def test_invalid_fixture_is_invalid
assert contacts(:invalid).invalid?
end
def test_in_use_if_acts_as_a_registrant
DomainContact.delete_all
assert @contact.in_use?
end
def test_in_use_if_acts_as_a_domain_contact
Domain.update_all(registrant_id: contacts(:william))
assert @contact.in_use?
end
def test_not_in_use_if_acts_as_neither_registrant_nor_domain_contact
refute contacts(:not_in_use).in_use?
end
end

View file

@ -0,0 +1,63 @@
require 'test_helper'
class ContactIdenticalTest < ActiveSupport::TestCase
REGULAR_FILTER_ATTRIBUTES = %i[
name
email
phone
fax
ident
ident_type
ident_country_code
org_name
]
def setup
@contact = contacts(:william)
@identical = contacts(:identical_to_william)
end
def test_returns_identical
assert_equal @identical, @contact.identical(@identical.registrar)
end
def test_does_not_return_non_identical
REGULAR_FILTER_ATTRIBUTES.each do |attribute|
previous_value = @identical.public_send(attribute)
@identical.update_attribute(attribute, 'other')
assert_nil @contact.identical(@identical.registrar)
@identical.update_attribute(attribute, previous_value)
end
@identical.update!({ statuses: %w[ok linked] })
assert_nil @contact.identical(@identical.registrar)
end
def test_takes_address_into_account_when_processing_enabled
Contact.address_attribute_names.each do |attribute|
previous_value = @identical.public_send(attribute)
@identical.update_attribute(attribute, 'other')
Contact.stub :address_processing?, true do
assert_nil @contact.identical(@identical.registrar)
end
@identical.update_attribute(attribute, previous_value)
end
end
def test_ignores_address_when_processing_disabled
Setting.address_processing = false
Contact.address_attribute_names.each do |attribute|
previous_value = @identical.public_send(attribute)
@identical.update_attribute(attribute, 'other')
Contact.stub :address_processing?, false do
assert_equal @identical, @contact.identical(@identical.registrar)
end
@identical.update_attribute(attribute, previous_value)
end
end
end

View file

@ -0,0 +1,19 @@
require 'test_helper'
class ContactPostalAddressTest < ActiveSupport::TestCase
def setup
@contact = contacts(:john)
end
def test_invalid_if_country_code_is_invalid_and_address_processing_is_on
Setting.address_processing = true
@contact.country_code = 'invalid'
assert @contact.invalid?
end
def test_valid_if_country_code_is_invalid_and_address_processing_is_off
Setting.address_processing = false
@contact.country_code = 'invalid'
assert @contact.valid?
end
end

View file

@ -8,7 +8,6 @@ class ContactTransferTest < ActiveSupport::TestCase
def test_invalid_without_auth_info
@contact.auth_info = nil
@contact.validate
assert @contact.invalid?
end
@ -36,18 +35,23 @@ class ContactTransferTest < ActiveSupport::TestCase
end
def test_keeps_original_contact_untouched
original_hash = @contact.to_json
original_hash = @contact.attributes
@contact.transfer(@new_registrar)
@contact.reload
assert_equal original_hash, @contact.to_json
assert_equal original_hash, @contact.attributes
end
def test_creates_new_contact
assert_difference 'Contact.count' do
assert_difference -> { @new_registrar.contacts.count } do
@contact.transfer(@new_registrar)
end
end
def test_reuses_identical_contact
identical = contacts(:identical_to_william)
assert_equal identical, contacts(:william).transfer(@new_registrar)
end
def test_bypasses_validation
@contact = contacts(:invalid)
@ -56,12 +60,12 @@ class ContactTransferTest < ActiveSupport::TestCase
end
end
def test_changes_registrar
def test_assigns_new_registrar
new_contact = @contact.transfer(@new_registrar)
assert_equal @new_registrar, new_contact.registrar
end
def test_links_to_original
def test_links_to_original_contact
new_contact = @contact.transfer(@new_registrar)
assert_equal @contact, new_contact.original
end

View file

@ -8,7 +8,6 @@ class DomainTransferableTest < ActiveSupport::TestCase
def test_invalid_without_transfer_code
@domain.transfer_code = nil
@domain.validate
assert @domain.invalid?
end
@ -35,7 +34,7 @@ class DomainTransferableTest < ActiveSupport::TestCase
assert_equal '1bad4f', domain.transfer_code
end
def test_changes_registrar
def test_assigns_new_registrar
@domain.transfer(@new_registrar)
assert_equal @new_registrar, @domain.registrar
end

View file

@ -0,0 +1,27 @@
require 'test_helper'
class NameserverGlueRecordTest < ActiveSupport::TestCase
def setup
@nameserver = nameservers(:shop_ns1)
end
def test_invalid_without_ip_if_glue_record_is_required
@nameserver.hostname = 'ns1.shop.test'
@nameserver.ipv4 = @nameserver.ipv6 = ''
assert @nameserver.invalid?
assert_includes @nameserver.errors.full_messages, 'Either IPv4 or IPv6 is required' \
' for glue record generation'
end
def test_valid_with_ip_if_glue_record_is_required
@nameserver.hostname = 'ns1.shop.test'
@nameserver.ipv4 = ['192.0.2.1']
@nameserver.ipv6 = ''
assert @nameserver.valid?
end
def test_valid_without_ip_if_glue_record_is_not_required
@nameserver.ipv4 = @nameserver.ipv6 = ''
assert @nameserver.valid?
end
end

View file

@ -0,0 +1,81 @@
require 'test_helper'
class NameserverTest < ActiveSupport::TestCase
def setup
@nameserver = nameservers(:shop_ns1)
end
def test_valid
assert @nameserver.valid?
end
def test_invalid_without_domain
@nameserver.domain = nil
assert @nameserver.invalid?
end
def test_invalid_without_hostname
@nameserver.hostname = ''
assert @nameserver.invalid?
end
def test_hostname_format_validation
@nameserver.hostname = 'foo.bar'
assert @nameserver.valid?
@nameserver.hostname = 'äöüõšž.ÄÖÜÕŠŽ.umlauts'
assert @nameserver.valid?
@nameserver.hostname = 'foo_bar'
assert @nameserver.invalid?
end
def test_ipv4_format_validation
@nameserver.ipv4 = ['192.0.2.1']
assert @nameserver.valid?
@nameserver.ipv4 = ['0.0.0.256']
assert @nameserver.invalid?
@nameserver.ipv4 = ['192.168.0.0/24']
assert @nameserver.invalid?
end
def test_ipv6_format_validation
@nameserver.ipv6 = ['2001:db8::1']
assert @nameserver.valid?
@nameserver.ipv6 = ['3ffe:0b00:0000:0001:0000:0000:000a']
assert @nameserver.invalid?
end
def test_hostnames
assert_equal %w[ns1.bestnames.test
ns2.bestnames.test
ns1.bestnames.test
ns1.bestnames.test], Nameserver.hostnames
end
def test_normalizes_hostname
@nameserver.hostname = ' ns1.bestnameS.test.'
@nameserver.validate
assert_equal 'ns1.bestnames.test', @nameserver.hostname
end
def test_normalizes_ipv4
@nameserver.ipv4 = [' 192.0.2.1']
@nameserver.validate
assert_equal ['192.0.2.1'], @nameserver.ipv4
end
def test_normalizes_ipv6
@nameserver.ipv6 = [' 2001:db8::1']
@nameserver.validate
assert_equal ['2001:DB8::1'], @nameserver.ipv6
end
def test_encodes_hostname_to_punycode
@nameserver.hostname = 'ns1.münchen.de'
assert_equal 'ns1.xn--mnchen-3ya.de', @nameserver.hostname_puny
end
end