mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
added validation and tests
This commit is contained in:
parent
ded22685c9
commit
77d2e402b4
3 changed files with 87 additions and 0 deletions
|
@ -16,6 +16,26 @@ class Epp::Contact < Contact
|
||||||
throw(:abort)
|
throw(:abort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
validate :validate_birthday_ident
|
||||||
|
|
||||||
|
def validate_birthday_ident
|
||||||
|
return unless Depp::Contact::SELECTION_TYPES[2].include?(ident_type)
|
||||||
|
|
||||||
|
if (Date.parse(ident) rescue ArgumentError) == ArgumentError
|
||||||
|
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_format'))
|
||||||
|
@error = true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
contact_ident_date = Date.parse(ident)
|
||||||
|
valid_time_range = (Date.today - 125.years)...(Date.tomorrow - 18.years)
|
||||||
|
return if valid_time_range.cover?(contact_ident_date)
|
||||||
|
|
||||||
|
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_range'))
|
||||||
|
@error = true
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# support legacy search
|
# support legacy search
|
||||||
def find_by_epp_code(code)
|
def find_by_epp_code(code)
|
||||||
|
|
|
@ -8,6 +8,12 @@ en:
|
||||||
valid_ident: >-
|
valid_ident: >-
|
||||||
Ident update is not allowed.
|
Ident update is not allowed.
|
||||||
Consider creating new contact object
|
Consider creating new contact object
|
||||||
|
valid_ident_date_format: >-
|
||||||
|
Ident update is not allowed.
|
||||||
|
Date format is invalid
|
||||||
|
valid_ident_date_range: >-
|
||||||
|
Ident update is not allowed.
|
||||||
|
Age must be over 18 and under 125
|
||||||
ident_update: >-
|
ident_update: >-
|
||||||
Only ident type and country can be updated in case of invalid ident.
|
Only ident type and country can be updated in case of invalid ident.
|
||||||
Please create new contact object to update ident code
|
Please create new contact object to update ident code
|
||||||
|
|
|
@ -81,6 +81,67 @@ class EppContactCreateBaseTest < EppTestCase
|
||||||
assert_epp_response :parameter_value_syntax_error
|
assert_epp_response :parameter_value_syntax_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_responses_with_error_on_invalid_birthday_date
|
||||||
|
name = 'new'
|
||||||
|
email = 'new@registrar.test'
|
||||||
|
phone = '+1.2'
|
||||||
|
birthday_wrong_format = '1111-22-33'
|
||||||
|
birthday_above_valid_range = '1800-01-01'
|
||||||
|
birthday_below_valid_range = '2008-07-09'
|
||||||
|
|
||||||
|
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>
|
||||||
|
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:postalInfo>
|
||||||
|
<contact:name>#{name}</contact:name>
|
||||||
|
</contact:postalInfo>
|
||||||
|
<contact:voice>#{phone}</contact:voice>
|
||||||
|
<contact:email>#{email}</contact:email>
|
||||||
|
</contact:create>
|
||||||
|
</create>
|
||||||
|
<extension>
|
||||||
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
|
<eis:ident type="birthday" cc="LV">#{birthday_wrong_format}</eis:ident>
|
||||||
|
</eis:extdata>
|
||||||
|
</extension>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
|
||||||
|
assert_no_difference 'Contact.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
|
||||||
|
|
||||||
|
request_xml.sub! ">#{birthday_wrong_format}<", ">#{birthday_above_valid_range}<"
|
||||||
|
assert_no_difference 'Contact.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
|
||||||
|
|
||||||
|
request_xml.sub! ">#{birthday_above_valid_range}<", ">#{birthday_below_valid_range}<"
|
||||||
|
assert_no_difference 'Contact.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_responces_error_with_email_error
|
def test_responces_error_with_email_error
|
||||||
name = 'new'
|
name = 'new'
|
||||||
email = 'new@registrar@test'
|
email = 'new@registrar@test'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue