Skip to content

Commit

Permalink
Fix domain update confirm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed Dec 18, 2020
1 parent b44ce9f commit 1fca6d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 68 deletions.
67 changes: 1 addition & 66 deletions app/models/epp/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,75 +129,10 @@ def add_legal_file_to_new frame
self.legal_document_id = doc.id
end

def update(frame, current_user, verify = true)
return super if frame.blank?

if discarded?
add_epp_error('2304', nil, nil, 'Object status prohibits operation')
return
end

at = {}.with_indifferent_access
at.deep_merge!(attrs_from(frame.css('chg'), current_user, 'chg'))
at.deep_merge!(attrs_from(frame.css('rem'), current_user, 'rem'))

if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
self.legal_document_id = doc.id
end

at_add = attrs_from(frame.css('add'), current_user, 'add')
at[:nameservers_attributes] += at_add[:nameservers_attributes]
at[:admin_domain_contacts_attributes] += at_add[:admin_domain_contacts_attributes]
at[:tech_domain_contacts_attributes] += at_add[:tech_domain_contacts_attributes]
at[:dnskeys_attributes] += at_add[:dnskeys_attributes]
at[:statuses] =
statuses - domain_statuses_attrs(frame.css('rem'), 'rem') + domain_statuses_attrs(frame.css('add'), 'add')

if errors.empty? && verify
self.upid = current_user.registrar.id if current_user.registrar
self.up_date = Time.zone.now
end

registrant_verification_needed = false
# registrant block may not be present, so we need this to rule out false positives
if frame.css('registrant').text.present?
registrant_verification_needed = (registrant.code != frame.css('registrant').text)
end

if registrant_verification_needed && disputed?
disputed_pw = frame.css('reserved > pw').text
if disputed_pw.blank?
add_epp_error('2304', nil, nil, 'Required parameter missing; reserved' \
'pw element required for dispute domains')
else
dispute = Dispute.active.find_by(domain_name: name, password: disputed_pw)
if dispute
Dispute.close_by_domain(name)
registrant_verification_needed = false # Prevent asking current registrant confirmation
else
add_epp_error('2202', nil, nil, 'Invalid authorization information; '\
'invalid reserved>pw value')
end
end
end

unverified_registrant_params = frame.css('registrant').present? &&
frame.css('registrant').attr('verified').to_s.downcase != 'yes'

if registrant_verification_needed && errors.empty? && verify &&
Setting.request_confirmation_on_registrant_change_enabled &&
unverified_registrant_params
registrant_verification_asked!(frame.to_s, current_user.id) unless disputed?
end

errors.empty? && super(at)
end

def apply_pending_update!
preclean_pendings
user = ApiUser.find(pending_json['current_user_id'])
frame = pending_json['frame'].with_indifferent_access
frame = pending_json['frame'] ? pending_json['frame'].with_indifferent_access : {}

self.statuses.delete(DomainStatus::PENDING_UPDATE)
self.upid = user.registrar.id if user.registrar
Expand Down
9 changes: 7 additions & 2 deletions test/jobs/domain_update_confirm_job_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "test_helper"
require 'deserializers/xml/domain_update'

class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
def setup
Expand Down Expand Up @@ -40,7 +41,9 @@ def test_changes_domain_registrant_after_approval
" <chg>\n <registrant>#{@new_registrant.code}</registrant>\n </chg>\n </update>\n </update>\n <extension>\n <update/>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n </extdata>\n" \
" </extension>\n <clTRID>20alla-1594199756</clTRID>\n </command>\n</epp>\n"
@domain.pending_json['frame'] = epp_xml
parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call

@domain.pending_json['frame'] = parsed_frame
@domain.update(pending_json: @domain.pending_json)

@domain.reload
Expand All @@ -55,7 +58,9 @@ def test_clears_pending_update_after_denial
" <chg>\n <registrant>#{@new_registrant.code}</registrant>\n </chg>\n </update>\n </update>\n <extension>\n <update/>\n" \
" <extdata>\n <legalDocument type=\"pdf\">#{@legal_doc_path}</legalDocument>\n </extdata>\n" \
" </extension>\n <clTRID>20alla-1594199756</clTRID>\n </command>\n</epp>\n"
@domain.pending_json['frame'] = epp_xml
parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call

@domain.pending_json['frame'] = parsed_frame
@domain.update(pending_json: @domain.pending_json)

DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED)
Expand Down

0 comments on commit 1fca6d9

Please sign in to comment.