mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Validate only puny label length #2608
This commit is contained in:
parent
1654f87e04
commit
5c68eb558c
6 changed files with 21 additions and 16 deletions
|
@ -70,7 +70,7 @@ class Domain < ActiveRecord::Base
|
|||
after_save :update_whois_record
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
validates :name_puny, length: { maximum: 66 }
|
||||
validates :puny_label, length: { maximum: 63 }
|
||||
validates :period, numericality: { only_integer: true }
|
||||
validates :registrant, :registrar, presence: true
|
||||
|
||||
|
@ -160,6 +160,10 @@ class Domain < ActiveRecord::Base
|
|||
"EIS-#{id}"
|
||||
end
|
||||
|
||||
def puny_label
|
||||
name_puny.to_s.split('.').first
|
||||
end
|
||||
|
||||
def registrant_typeahead
|
||||
@registrant_typeahead || registrant.try(:name) || nil
|
||||
end
|
||||
|
|
|
@ -56,7 +56,7 @@ class Epp::Domain < Domain
|
|||
],
|
||||
'2005' => [ # Parameter value syntax error
|
||||
[:name_dirty, :invalid, { obj: 'name', val: name_dirty }],
|
||||
[:name_puny, :too_long, { obj: 'name', val: name_puny }]
|
||||
[:puny_label, :too_long, { obj: 'name', val: name_puny }]
|
||||
],
|
||||
'2201' => [ # Authorisation error
|
||||
[:auth_info, :wrong_pw]
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
class DomainNameValidator < ActiveModel::EachValidator
|
||||
# TODO
|
||||
# validates lenght of 2-63
|
||||
# validates/honours Estonian additional letters zäõüö
|
||||
# honours punicode and all interfces honors utf8
|
||||
# validates lower level domains (.pri.ee, edu.ee etc)
|
||||
# lower level domains are fixed for .ee and can add statically into settings
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
if !self.class.validate_format(value)
|
||||
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
|
||||
|
|
|
@ -64,7 +64,7 @@ en:
|
|||
invalid: 'Domain name is invalid'
|
||||
reserved: 'Domain name is reserved or restricted'
|
||||
taken: 'Domain name already exists'
|
||||
name_puny:
|
||||
puny_label:
|
||||
too_long: 'Domain name is too long (maximum is 63 characters)'
|
||||
registrant:
|
||||
blank: 'Registrant is missing'
|
||||
|
|
|
@ -193,7 +193,7 @@ describe 'EPP Domain', epp: true do
|
|||
xml = domain_create_xml(name: { value: "#{'ä' * 63}.ee" })
|
||||
|
||||
response = epp_plain_request(xml)
|
||||
response[:msg].should == 'Domain name is too long (maximum is 63 characters) [name_puny]'
|
||||
response[:msg].should == 'Domain name is too long (maximum is 63 characters) [puny_label]'
|
||||
response[:result_code].should == '2005'
|
||||
response[:clTRID].should == 'ABC-12345'
|
||||
end
|
||||
|
|
|
@ -237,7 +237,7 @@ describe Domain do
|
|||
d.valid?
|
||||
d.errors.full_messages.should match_array([
|
||||
"Domain name Domain name is invalid",
|
||||
"Domain name Domain name is too long (maximum is 63 characters)"
|
||||
"Puny label is too long (maximum is 63 characters)"
|
||||
])
|
||||
end
|
||||
|
||||
|
@ -247,7 +247,15 @@ describe Domain do
|
|||
d.valid?
|
||||
d.errors.full_messages.should match_array([
|
||||
"Domain name Domain name is invalid",
|
||||
"Domain name Domain name is too long (maximum is 63 characters)"
|
||||
"Puny label is too long (maximum is 63 characters)"
|
||||
])
|
||||
end
|
||||
|
||||
it 'should be valid when name length is 63 characters' do
|
||||
d = Fabricate.build(:domain,
|
||||
name: "õäöüšžõäöüšžõäöüšžõäöüšžõäöüšžõäöüšžõäöüšžab123.pri.ee")
|
||||
d.valid?
|
||||
d.errors.full_messages.should match_array([
|
||||
])
|
||||
end
|
||||
|
||||
|
@ -255,7 +263,7 @@ describe Domain do
|
|||
d = Fabricate.build(:domain, name: "#{'ä' * 63}.ee")
|
||||
d.valid?
|
||||
d.errors.full_messages.should == [
|
||||
"Domain name Domain name is too long (maximum is 63 characters)"
|
||||
"Puny label is too long (maximum is 63 characters)"
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -264,7 +272,7 @@ describe Domain do
|
|||
d.valid?
|
||||
d.errors.full_messages.should match_array([
|
||||
"Domain name Domain name is invalid",
|
||||
"Domain name Domain name is too long (maximum is 63 characters)"
|
||||
"Puny label is too long (maximum is 63 characters)"
|
||||
])
|
||||
end
|
||||
|
||||
|
@ -272,7 +280,7 @@ describe Domain do
|
|||
d = Fabricate.build(:domain, name: "#{'ä' * 63}.pri.ee")
|
||||
d.valid?
|
||||
d.errors.full_messages.should match_array([
|
||||
"Domain name Domain name is too long (maximum is 63 characters)"
|
||||
"Puny label is too long (maximum is 63 characters)"
|
||||
])
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue