Add new element, error messages, fix tests #2565

This commit is contained in:
Martin Lensment 2015-07-09 17:57:33 +03:00
parent 94adc9496f
commit bfdabaacf3
7 changed files with 77 additions and 25 deletions

View file

@ -96,8 +96,17 @@ class Domain < ActiveRecord::Base
validate :validate_reservation
def validate_reservation
return if persisted?
return if !in_reserved_list? || reserved_pw == auth_info
errors.add(:base, :domain_is_reserved_and_requires_correct_auth_info)
return if !in_reserved_list?
if reserved_pw.blank?
errors.add(:base, :required_parameter_missing_reserved)
return false
end
if ReservedDomain.pw_for(name) != reserved_pw
errors.add(:base, :invalid_auth_information_reserved)
return false
end
end
validates :nameservers, object_count: {
@ -149,7 +158,7 @@ class Domain < ActiveRecord::Base
end
attr_accessor :registrant_typeahead, :update_me, :deliver_emails,
:epp_pending_update, :epp_pending_delete
:epp_pending_update, :epp_pending_delete, :reserved_pw
def subordinate_nameservers
nameservers.select { |x| x.hostname.end_with?(name) }
@ -263,11 +272,7 @@ class Domain < ActiveRecord::Base
end
def in_reserved_list?
reserved_pw.present?
end
def reserved_pw
ReservedDomain.pw_for(name)
ReservedDomain.pw_for(name).present?
end
def pending_transfer

View file

@ -25,7 +25,8 @@ class Epp::Domain < Domain
],
'2003' => [ # Required parameter missing
[:registrant, :blank],
[:registrar, :blank]
[:registrar, :blank],
[:base, :required_parameter_missing_reserved]
],
'2004' => [ # Parameter value range error
[:nameservers, :out_of_range,
@ -60,14 +61,16 @@ class Epp::Domain < Domain
'2201' => [ # Authorisation error
[:auth_info, :wrong_pw]
],
'2202' => [
[:base, :invalid_auth_information_reserved]
],
'2302' => [ # Object exists
[:name_dirty, :taken, { value: { obj: 'name', val: name_dirty } }],
[:name_dirty, :reserved, { value: { obj: 'name', val: name_dirty } }],
[:name_dirty, :blocked, { value: { obj: 'name', val: name_dirty } }]
],
'2304' => [ # Object status prohibits operation
[:base, :domain_status_prohibits_operation],
[:base, :domain_is_reserved_and_requires_correct_auth_info]
[:base, :domain_status_prohibits_operation]
],
'2306' => [ # Parameter policy error
[:period, :out_of_range, { value: { obj: 'period', val: period } }],
@ -113,7 +116,7 @@ class Epp::Domain < Domain
at[:period_unit] = Epp::Domain.parse_period_unit_from_frame(frame) || 'y'
at[:auth_info] = frame.css('pw').text if new_record?
at[:reserved_pw] = frame.css('reserved > pw').text
# at[:statuses] = domain_statuses_attrs(frame, action)
# binding.pry

View file

@ -60,7 +60,8 @@ en:
ds_data_not_allowed: 'dsData object is not allowed'
ds_data_with_key_not_allowed: 'dsData object with key data is not allowed'
key_data_not_allowed: 'keyData object is not allowed'
domain_is_reserved_and_requires_correct_auth_info: 'Domain is reserved and requires correct auth info'
required_parameter_missing_reserved: 'Required parameter missing; reserved>pw element required for reserved domains'
invalid_auth_information_reserved: 'Invalid authorization information; invalid reserved>pw value'
name_dirty:
invalid: 'Domain name is invalid'
reserved: 'Domain name is reserved'

View file

@ -24,13 +24,31 @@
<sequence>
<element name="ident" type="eis:identType" minOccurs="0" maxOccurs="1"/>
<element name="legalDocument" type="eis:legalDocType" minOccurs="0" maxOccurs="1"/>
<element name="reserved" type="eis:reservedType" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>
<!--
Child elements of extdata
Child elements of extdata
-->
<!--
Reserved for providing passwords for reserved domains
-->
<complexType name="reservedType">
<sequence>
<element name="pw" type="eis:pwType" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
<simpleType name="pwType">
<restriction base="normalizedString">
<minLength value="1"/>
<maxLength value="255"/>
</restriction>
</simpleType>
<!--
Legal document, encoded in base64
-->

View file

@ -225,18 +225,39 @@ describe 'EPP Domain', epp: true do
xml = domain_create_xml(name: { value: '1162.ee' })
response = epp_plain_request(xml)
response[:result_code].should == '2304'
response[:msg].should == 'Domain is reserved and requires correct auth info'
response[:msg].should == 'Required parameter missing; reserved>pw element required for reserved domains'
response[:result_code].should == '2003'
response[:clTRID].should == 'ABC-12345'
xml = domain_create_xml(name: { value: '1162.ee' }, authInfo: { pw: { value: 'wrong_pw' } })
xml = domain_create_xml({name: { value: '1162.ee' }}, {}, {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
},
reserved: {
pw: { value: 'wrong_pw' }
}
]
})
response = epp_plain_request(xml)
response[:result_code].should == '2304'
response[:msg].should == 'Domain is reserved and requires correct auth info'
response[:msg].should == 'Invalid authorization information; invalid reserved>pw value'
response[:result_code].should == '2202'
end
it 'creates a reserved domain with correct auth info' do
xml = domain_create_xml(name: { value: '1162.ee' }, authInfo: { pw: { value: 'abc' } })
xml = domain_create_xml({name: { value: '1162.ee' }}, {}, {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
attrs: { type: 'pdf' }
},
reserved: {
pw: { value: 'abc' }
}
]
})
response = epp_plain_request(xml)
response[:msg].should == 'Command completed successfully'

View file

@ -24,12 +24,14 @@ feature 'ReservedDomain', type: :feature do
page.should have_content('110.ee: testpw')
d.valid?.should == false
d.errors.full_messages.should match_array(["Domain is reserved and requires correct auth info"])
d.errors.full_messages.should match_array(
["Required parameter missing; reserved>pw element required for reserved domains"]
)
d.auth_info = 'wrongpw'
d.reserved_pw = 'wrongpw'
d.valid?.should == false
d.auth_info = 'testpw'
d.reserved_pw = 'testpw'
d.valid?.should == true
d.errors.full_messages.should match_array([])
end

View file

@ -144,7 +144,7 @@ module Epp
end
# rubocop: disable Metrics/MethodLength
def domain_create_xml(xml_params = {}, dnssec_params = {})
def domain_create_xml(xml_params = {}, dnssec_params = {}, custom_params = {})
defaults = {
name: { value: next_domain_name },
period: { value: '1', attrs: { unit: 'y' } },
@ -185,7 +185,7 @@ module Epp
dnssec_params = dnssec_defaults.deep_merge(dnssec_params) if dnssec_params != false
custom_params = {
custom_defaults = {
_anonymus: [
legalDocument: {
value: 'dGVzdCBmYWlsCg==',
@ -194,6 +194,8 @@ module Epp
]
}
custom_params = custom_defaults.deep_merge(custom_params) if custom_params != false
epp_xml = EppXml::Domain.new(cl_trid: 'ABC-12345')
epp_xml.create(xml_params, dnssec_params, custom_params)
end