diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 013abf73e..d2c1a1dda 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -59,6 +59,13 @@ class EppController < ApplicationController validation_method = "validate_#{params[:action]}" return unless respond_to?(validation_method, true) send(validation_method) + + # validate legal document's type here because it may be in most of the requests + @prefix = nil + if element_count('extension > extdata > legalDocument') > 0 + requires_attribute('extension > extdata > legalDocument', 'type', values: LegalDocument::TYPES) + end + handle_errors and return if epp_errors.any? end diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 0f690480b..07c27fd2a 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -1,3 +1,5 @@ class LegalDocument < ActiveRecord::Base belongs_to :documentable, polymorphic: true + + TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z) end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 1a0c74cbd..eec1bb810 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1420,6 +1420,35 @@ describe 'EPP Domain', epp: true do end end + it 'validates legal document type' do + xml = epp_xml.domain.info({ + name: { value: domain.name } + }, { + _anonymus: [ + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'jpg' } + } + ] + }) + + response = epp_plain_request(xml, :xml) + response[:msg].should == 'Attribute is invalid: type' + + xml = epp_xml.domain.info({ + name: { value: domain.name } + }, { + _anonymus: [ + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==' + } + ] + }) + + response = epp_plain_request(xml, :xml) + response[:msg].should == 'Attribute is invalid: type' + end + ### DELETE ### it 'deletes domain' do response = epp_plain_request(epp_xml.domain.delete({ @@ -1537,7 +1566,6 @@ describe 'EPP Domain', epp: true do name[:avail].should == '0' reason.text.should == 'invalid format' end - end end