diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index e98e88368..57c4d033a 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -8,6 +8,9 @@ class Epp::Contact < Contact # disable STI, there is type column present self.inheritance_column = :sti_disabled + VALID_BIRTH_DATE_FROM = Time.zone.today - 150.years + VALID_BIRTH_DATE_TO = Time.zone.tomorrow + before_validation :manage_permissions def manage_permissions @@ -21,14 +24,18 @@ class Epp::Contact < Contact def validate_birthday_ident return unless Depp::Contact::SELECTION_TYPES[2].include?(ident_type) - if (Date.parse(ident) rescue ArgumentError) == ArgumentError + if begin + Date.parse(ident) + rescue StandardError + ArgumentError + end == 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) + valid_time_range = VALID_BIRTH_DATE_FROM...VALID_BIRTH_DATE_TO return if valid_time_range.cover?(contact_ident_date) add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_range')) diff --git a/config/locales/epp/contacts.en.yml b/config/locales/epp/contacts.en.yml index 1da66f31d..341630299 100644 --- a/config/locales/epp/contacts.en.yml +++ b/config/locales/epp/contacts.en.yml @@ -13,7 +13,7 @@ en: Date format is invalid valid_ident_date_range: >- Ident update is not allowed. - Age must be over 18 and under 125 + Age must be over 0 and under 150 ident_update: >- Only ident type and country can be updated in case of invalid ident. Please create new contact object to update ident code diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index 956735257..5d965596a 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -87,7 +87,7 @@ class EppContactCreateBaseTest < EppTestCase phone = '+1.2' birthday_wrong_format = '1111-22-33' birthday_above_valid_range = '1800-01-01' - birthday_below_valid_range = '2008-07-09' + birthday_below_valid_range = '2050-07-09' request_xml = <<-XML