diff --git a/app/models/domain.rb b/app/models/domain.rb index 1a897e150..8335d5f42 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -70,6 +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 :period, numericality: { only_integer: true } validates :registrant, :registrar, presence: true diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 56e66bc7d..8da4b4d6b 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -55,7 +55,8 @@ class Epp::Domain < Domain ] ], '2005' => [ # Parameter value syntax error - [:name_dirty, :invalid, { obj: 'name', val: name_dirty }] + [:name_dirty, :invalid, { obj: 'name', val: name_dirty }], + [:name_puny, :too_long, { obj: 'name', val: name_puny }] ], '2201' => [ # Authorisation error [:auth_info, :wrong_pw] diff --git a/config/locales/en.yml b/config/locales/en.yml index 4e66c4283..954e89eeb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -64,6 +64,8 @@ en: invalid: 'Domain name is invalid' reserved: 'Domain name is reserved or restricted' taken: 'Domain name already exists' + name_puny: + too_long: 'Domain name is too long (maximum is 63 characters)' registrant: blank: 'Registrant is missing' not_found: 'Registrant not found' diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 647f88f1d..73ba344ae 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -189,6 +189,15 @@ describe 'EPP Domain', epp: true do # response[:clTRID].should == 'ABC-12345' # end + it 'does not create domain longer than 63 punicode characters' 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[:result_code].should == '2005' + response[:clTRID].should == 'ABC-12345' + end + it 'does not create reserved domain' do xml = domain_create_xml(name: { value: '1162.ee' }) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 741721f4e..cc6c4e257 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -226,6 +226,86 @@ describe Domain do expect(d.name_dirty).to eq('test.ee') end + it 'should be valid when name length is exatly 63 in characters' do + d = Fabricate(:domain, name: "#{'a' * 63}.ee") + d.valid? + d.errors.full_messages.should == [] + end + + it 'should not be valid when name length is longer than 63 characters' do + d = Fabricate.build(:domain, name: "#{'a' * 64}.ee") + 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)" + ]) + end + + it 'should not be valid when name length is longer than 63 characters' do + d = Fabricate.build(:domain, + name: "xn--4caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ee") + 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)" + ]) + end + + it 'should not be valid when name length is longer than 63 punycode characters' 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)" + ] + end + + it 'should not be valid when name length is longer than 63 punycode characters' do + d = Fabricate.build(:domain, name: "#{'ä' * 64}.ee") + 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)" + ]) + end + + it 'should not be valid when name length is longer than 63 punycode characters' 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)" + ]) + end + + it 'should be valid when punycode name length is not longer than 63' do + d = Fabricate.build(:domain, name: "#{'ä' * 53}.pri.ee") + d.valid? + d.errors.full_messages.should == [] + end + + it 'should be valid when punycode name length is not longer than 63' do + d = Fabricate.build(:domain, name: "#{'ä' * 57}.ee") + d.valid? + d.errors.full_messages.should == [] + end + + it 'should not be valid when name length is one pynicode' do + d = Fabricate.build(:domain, name: "xn--4ca.ee") + d.valid? + d.errors.full_messages.should == ["Domain name Domain name is invalid"] + end + + it 'should be valid when name length is two pynicodes' do + d = Fabricate.build(:domain, name: "xn--4caa.ee") + d.valid? + d.errors.full_messages.should == [] + end + + it 'should be valid when name length is two pynicodes' do + d = Fabricate.build(:domain, name: "xn--4ca0b.ee") + d.valid? + d.errors.full_messages.should == [] + end + it 'normalizes ns attrs' do d = Fabricate(:domain) d.nameservers.build(hostname: 'BLA.EXAMPLE.EE', ipv4: ' 192.168.1.1', ipv6: '1080:0:0:0:8:800:200c:417a')