Skip to content

Commit

Permalink
Implement status policy
Browse files Browse the repository at this point in the history
  • Loading branch information
mlensment committed Mar 30, 2015
1 parent 09c73d6 commit bb93f8b
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 38 deletions.
31 changes: 21 additions & 10 deletions app/controllers/epp/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create
@contact = Epp::Contact.new(params[:parsed_frame], current_user.registrar)

if @contact.save
render_epp_response '/epp/contacts/create'
render_epp_response '/epp/contacts/create'
else
handle_errors(@contact)
end
Expand Down Expand Up @@ -63,10 +63,10 @@ def find_contact
@contact = Epp::Contact.find_by(code: code)

if @contact.blank?
epp_errors << {
epp_errors << {
code: '2303',
msg: t('errors.messages.epp_obj_does_not_exist'),
value: { obj: 'id', val: code }
value: { obj: 'id', val: code }
}
fail CanCan::AccessDenied
end
Expand Down Expand Up @@ -94,27 +94,29 @@ def validate_create
)
ident = params[:parsed_frame].css('ident')
if ident.present? && ident.text != 'birthday' && ident.attr('cc').blank?
epp_errors << {
code: '2003',
msg: I18n.t('errors.messages.required_attribute_missing', key: 'ident country code missing')
epp_errors << {
code: '2003',
msg: I18n.t('errors.messages.required_attribute_missing', key: 'ident country code missing')
}
end
contact_org_disabled
contact_org_disabled
fax_disabled
status_editing_disabled
@prefix = nil
requires 'extension > extdata > ident'
end

def validate_update
@prefix = 'update > update >'
if element_count('chg') == 0 && element_count('rem') == 0 && element_count('add') == 0
epp_errors << {
code: '2003',
msg: I18n.t('errors.messages.required_parameter_missing', key: 'add, rem or chg')
epp_errors << {
code: '2003',
msg: I18n.t('errors.messages.required_parameter_missing', key: 'add, rem or chg')
}
end
contact_org_disabled
fax_disabled
status_editing_disabled
requires 'id', 'authInfo > pw'
@prefix = nil
end
Expand Down Expand Up @@ -142,4 +144,13 @@ def fax_disabled
msg: "#{I18n.t(:contact_fax_error)}: fax [fax]"
}
end

def status_editing_disabled
return true if Setting.client_status_editing_enabled
return true if params[:parsed_frame].css('status').empty?
epp_errors << {
code: '2306',
msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]"
}
end
end
13 changes: 13 additions & 0 deletions app/controllers/epp/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def validate_create

@prefix = nil
requires 'extension > extdata > legalDocument'

status_editing_disabled
end

def validate_renew
Expand All @@ -130,6 +132,8 @@ def validate_update

@prefix = 'update > update >'
requires 'name'

status_editing_disabled
end

## TRANSFER
Expand Down Expand Up @@ -170,4 +174,13 @@ def find_domain
def find_password
@password = params[:parsed_frame].css('authInfo pw').text
end

def status_editing_disabled
return true if Setting.client_status_editing_enabled
return true if params[:parsed_frame].css('status').empty?
epp_errors << {
code: '2306',
msg: "#{I18n.t(:client_side_status_editing_error)}: status [status]"
}
end
end
2 changes: 2 additions & 0 deletions config/initializers/initial_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
Setting.save_default(:ns_max_count, 11)

Setting.save_default(:transfer_wait_time, 0)

Setting.save_default(:client_side_status_editing_enabled, false)
end

# dev only setting
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,4 @@ en:
sending_error: 'Could not send sms to user'
sim_error: 'SIM application error'
internal_error: 'Internal error'
client_side_status_editing_error: 'Parameter value policy error. Client-side object status management not supported'
77 changes: 49 additions & 28 deletions spec/epp/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@registrar1 = Fabricate(:registrar1)
@registrar2 = Fabricate(:registrar2)
@epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')

Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)

Expand Down Expand Up @@ -50,17 +50,17 @@ def create_request(overwrites = {}, extension = {})

it 'fails if request xml is missing' do
response = epp_plain_request(@epp_xml.create, :xml)
response[:results][0][:msg].should ==
response[:results][0][:msg].should ==
'Required parameter missing: create > create > postalInfo > name [name]'
response[:results][1][:msg].should ==
response[:results][1][:msg].should ==
'Required parameter missing: create > create > postalInfo > addr > city [city]'
response[:results][2][:msg].should ==
response[:results][2][:msg].should ==
'Required parameter missing: create > create > postalInfo > addr > cc [cc]'
response[:results][3][:msg].should ==
response[:results][3][:msg].should ==
'Required parameter missing: create > create > voice [voice]'
response[:results][4][:msg].should ==
response[:results][4][:msg].should ==
'Required parameter missing: create > create > email [email]'
response[:results][5][:msg].should ==
response[:results][5][:msg].should ==
'Required parameter missing: extension > extdata > ident [ident]'

response[:results][0][:result_code].should == '2003'
Expand Down Expand Up @@ -101,9 +101,9 @@ def create_request(overwrites = {}, extension = {})
value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==',
attrs: { type: 'pdf' }
},
ident: {
ident: {
value: '1990-22-12',
attrs: { type: 'birthday', cc: 'US' }
attrs: { type: 'birthday', cc: 'US' }
}
}
response = create_request({}, extension)
Expand Down Expand Up @@ -165,7 +165,7 @@ def create_request(overwrites = {}, extension = {})

it 'should return parameter value policy error for org' do
response = create_request({ postalInfo: { org: { value: 'should not save' } } })
response[:msg].should ==
response[:msg].should ==
'Parameter value policy error. Org should be blank: postalInfo > org [org]'
response[:result_code].should == '2306'

Expand All @@ -174,7 +174,7 @@ def create_request(overwrites = {}, extension = {})

it 'should return parameter value policy error for fax' do
response = create_request({ fax: { value: 'should not save' } })
response[:msg].should ==
response[:msg].should ==
'Parameter value policy error. Fax should be blank: fax [fax]'
response[:result_code].should == '2306'

Expand Down Expand Up @@ -220,13 +220,13 @@ def update_request(overwrites = {}, extension = {})
it 'fails if request is invalid' do
response = epp_plain_request(@epp_xml.update, :xml)

response[:results][0][:msg].should ==
response[:results][0][:msg].should ==
'Required parameter missing: add, rem or chg'
response[:results][0][:result_code].should == '2003'
response[:results][1][:msg].should ==
response[:results][1][:msg].should ==
'Required parameter missing: update > update > id [id]'
response[:results][1][:result_code].should == '2003'
response[:results][2][:msg].should ==
response[:results][2][:msg].should ==
'Required parameter missing: update > update > authInfo > pw [pw]'
response[:results][2][:result_code].should == '2003'
response[:results].count.should == 3
Expand Down Expand Up @@ -291,9 +291,9 @@ def update_request(overwrites = {}, extension = {})
value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==',
attrs: { type: 'pdf' }
},
ident: {
ident: {
value: '1990-22-12',
attrs: { type: 'birthday', cc: 'US' }
attrs: { type: 'birthday', cc: 'US' }
}
}
response = update_request({ id: { value: 'sh8013' } }, extension)
Expand All @@ -304,32 +304,53 @@ def update_request(overwrites = {}, extension = {})
end

it 'should return parameter value policy errror for org update' do
response = update_request({
id: { value: 'sh8013' },
response = update_request({
id: { value: 'sh8013' },
chg: {
postalInfo: { org: { value: 'should not save' } }
postalInfo: { org: { value: 'should not save' } }
}
})
response[:msg].should ==
response[:msg].should ==
'Parameter value policy error. Org should be blank: postalInfo > org [org]'
response[:result_code].should == '2306'

Contact.find_by(code: 'sh8013').org_name.should == nil
end

it 'should return parameter value policy errror for fax update' do
response = update_request({
id: { value: 'sh8013' },
response = update_request({
id: { value: 'sh8013' },
chg: {
fax: { value: 'should not save' }
fax: { value: 'should not save' }
}
})
response[:msg].should ==
response[:msg].should ==
'Parameter value policy error. Fax should be blank: fax [fax]'
response[:result_code].should == '2306'

Contact.find_by(code: 'sh8013').fax.should == nil
end

it 'does not allow to edit statuses if policy forbids it' do
Setting.client_status_editing_enabled = false

xml = @epp_xml.update({
id: { value: 'sh8013' },
add: [{
_anonymus: [
{ status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } },
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
]
}]
})

response = epp_plain_request(xml, :xml)
response[:results][0][:result_code].should == '2306'
response[:results][0][:msg].should == "Parameter value policy error. Client-side object status "\
"management not supported: status [status]"

Setting.client_status_editing_enabled = true
end
end

context 'delete command' do
Expand All @@ -349,10 +370,10 @@ def delete_request(overwrites = {})
it 'fails if request is invalid' do
response = epp_plain_request(@epp_xml.delete, :xml)

response[:results][0][:msg].should ==
response[:results][0][:msg].should ==
'Required parameter missing: delete > delete > id [id]'
response[:results][0][:result_code].should == '2003'
response[:results][1][:msg].should ==
response[:results][1][:msg].should ==
'Required parameter missing: delete > delete > authInfo > pw [pw]'
response[:results][1][:result_code].should == '2003'
response[:results].count.should == 2
Expand All @@ -378,7 +399,7 @@ def delete_request(overwrites = {})
@domain = Fabricate(:domain, registrar: @registrar1, owner_contact: @contact)
@domain.owner_contact.address.present?.should == true

response = delete_request
response = delete_request
response[:msg].should == 'Object association prohibits operation [domains]'
response[:result_code].should == '2305'
response[:results].count.should == 1
Expand Down Expand Up @@ -443,7 +464,7 @@ def info_request(overwrites = {})

it 'fails if request invalid' do
response = epp_plain_request(@epp_xml.info, :xml)
response[:results][0][:msg].should ==
response[:results][0][:msg].should ==
'Required parameter missing: info > info > id [id]'
response[:results][0][:result_code].should == '2003'
response[:results].count.should == 1
Expand Down
21 changes: 21 additions & 0 deletions spec/epp/domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,27 @@
d.domain_statuses.count.should == 2
end

it 'does not allow to edit statuses if policy forbids it' do
Setting.client_status_editing_enabled = false

xml = domain_update_xml({
name: { value: domain.name },
add: [{
_anonymus: [
{ status: { value: 'Payment overdue.', attrs: { s: 'clientHold', lang: 'en' } } },
{ status: { value: '', attrs: { s: 'clientUpdateProhibited' } } }
]
}]
})

response = epp_plain_request(xml, :xml)
response[:results][0][:result_code].should == '2306'
response[:results][0][:msg].should == "Parameter value policy error. Client-side object status "\
"management not supported: status [status]"

Setting.client_status_editing_enabled = true
end

it 'updates a domain and removes objects' do
xml = domain_update_xml({
name: { value: domain.name },
Expand Down
2 changes: 2 additions & 0 deletions spec/support/general.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def create_settings
Setting.admin_contacts_max_count = 10
Setting.tech_contacts_min_count = 0
Setting.tech_contacts_max_count = 10

Setting.client_side_status_editing_enabled = true
end

def create_disclosure_settings
Expand Down

0 comments on commit bb93f8b

Please sign in to comment.