require 'test_helper'
class EppDomainCreateBaseTest < EppTestCase
def test_illegal_chars_in_dns_key
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
pub_key = "AwEAAddt2AkLf\n
\n
YGKgiEZB5SmIF8E\n
vrjxNMH6HtxW\rEA4RJ9Ao6LCWheg8"
request_xml = <<-XML
#{name}
#{registrant.code}
257
3
8
#{pub_key}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :parameter_value_syntax_error
end
def test_too_small_legal_document
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
#{'test' * 2}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :data_management_policy_violation
end
def test_too_big_legal_document
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
bignum_legaldoc = Base64.encode64('t' * (LegalDocument::MAX_BODY_SIZE + 1)).gsub(/\n/,"")
request_xml = <<-XML
#{name}
#{registrant.code}
#{bignum_legaldoc}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :data_management_policy_violation
error_description = 'Legaldoc size exceeds maximum allowed size of 8mB'
assert response.body.include? error_description
end
def test_upper_limit_of_value_legal_document
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
bignum_legaldoc = 't' * LegalDocument::MAX_BODY_SIZE
request_xml = <<-XML
#{name}
#{registrant.code}
#{bignum_legaldoc}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
end
def test_not_registers_domain_without_legaldoc
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :required_parameter_missing
end
def test_create_domain_with_unique_contact
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
#{contacts(:jane).code}
#{contacts(:william).code}
#{'test' * 2000}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
end
def test_create_domain_with_array_of_not_unique_admins_and_techs
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
#{contact.code}
#{contact.code}
#{contact.code}
#{contact.code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :parameter_value_policy_error
end
def test_create_domain_with_array_of_not_unique_admins
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
#{contact.code}
#{contact.code}
#{contact.code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :parameter_value_policy_error
end
def test_create_domain_with_array_of_not_unique_techs
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
#{contact.code}
#{contact.code}
#{contact.code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :parameter_value_policy_error
end
def test_create_domain_with_array_of_not_unique_admin_but_tech_another_one
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
contact_two = contacts(:william)
request_xml = <<-XML
#{name}
#{registrant.code}
#{contact.code}
#{contact.code}
#{contact_two.code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :parameter_value_policy_error
end
def test_create_domain_with_array_of_not_unique_techs_but_admin_another_one
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
contact_two = contacts(:william)
request_xml = <<-XML
#{name}
#{registrant.code}
#{contact_two.code}
#{contact.code}
#{contact.code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :parameter_value_policy_error
end
def test_registers_new_domain_with_required_attributes
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
#{'test' * 2000}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
domain = Domain.find_by(name: name)
assert_equal name, domain.name
assert_equal registrant, domain.registrant
assert_equal [contact], domain.admin_contacts
assert_equal [contact], domain.tech_contacts
assert_not_empty domain.transfer_code
default_registration_period = 1.year + 1.day
assert_equal now + default_registration_period, domain.expire_time
end
def test_registers_domain_without_legaldoc_if_optout
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
registrar = registrant.registrar
registrar.legaldoc_optout = true
registrar.save(validate: false)
request_xml = <<-XML
#{name}
#{registrant.code}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
domain = Domain.find_by(name: name)
assert_equal name, domain.name
assert_equal registrant, domain.registrant
end
def test_does_not_registers_domain_without_legaldoc_if_mandatory
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
registrar = registrant.registrar
assert registrar.legaldoc_mandatory?
request_xml = <<-XML
#{name}
#{registrant.code}
XML
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :required_parameter_missing
Setting.legal_document_is_mandatory = false
assert_not registrar.legaldoc_mandatory?
assert_not Setting.legal_document_is_mandatory
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end
def test_registers_reserved_domain_with_registration_code
reserved_domain = reserved_domains(:one)
registration_code = reserved_domain.registration_code
request_xml = <<-XML
#{reserved_domain.name}
#{contacts(:john).code}
#{'test' * 2000}
#{registration_code}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
reserved_domain.reload
assert_not_equal registration_code, reserved_domain.registration_code
end
def test_respects_custom_transfer_code
name = "new.#{dns_zones(:one).origin}"
transfer_code = 'custom-transfer-code'
request_xml = <<-XML
#{name}
#{contacts(:john).code}
#{transfer_code}
#{'test' * 2000}
XML
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
assert_equal transfer_code, Domain.find_by(name: name).transfer_code
end
def test_blocked_domain_cannot_be_registered
blocked_domain = 'blocked.test'
assert BlockedDomain.find_by(name: blocked_domain)
request_xml = <<-XML
#{blocked_domain}
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :data_management_policy_violation
end
def test_blocked_punicode_domain_cannot_be_registered
blocked_domain = 'blockedäöüõ.test'
assert BlockedDomain.find_by(name: blocked_domain)
request_xml = <<-XML
#{SimpleIDN.to_ascii('blockedäöüõ.test')}
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :data_management_policy_violation
end
def test_reserved_domain_cannot_be_registered_with_wrong_registration_code
request_xml = <<-XML
#{reserved_domains(:one).name}
#{contacts(:john).code}
#{'test' * 2000}
wrong
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :invalid_authorization_information
end
def test_reserved_domain_cannot_be_registered_without_registration_code
reserved_domain = reserved_domains(:one)
request_xml = <<-XML
#{reserved_domain.name}
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :required_parameter_missing
end
def test_insufficient_funds
session = epp_sessions(:api_bestnames)
session.user.registrar.accounts.first.update!(balance: 0)
request_xml = <<-XML
new.test
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :billing_failure
end
def test_no_price
assert_nil Billing::Price.find_by(duration: '2 months')
request_xml = <<-XML
new.test
2
john-001
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :billing_failure
end
end