Skip to content

Commit

Permalink
Merge pull request #1975 from internetee/domain_update_confirm_fix
Browse files Browse the repository at this point in the history
Fix domain update confirm if pendong_json current_user_id got non-string values
  • Loading branch information
vohmar authored May 10, 2021
2 parents 9b55999 + 9df52af commit a889e99
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ def update_domain
end

def assign_domain_update_meta
user = ApiUser.find_by(id: domain.pending_json['current_user_id'])
user = ApiUser.find_by(id: user_id) if user_id.present? && user_id.is_a?(String)

domain.upid = user.registrar.id if user.present? && user.registrar
domain.up_date = Time.zone.now
end

private

def user_id
@user_id ||= domain.pending_json.dig('current_user_id')
end
end
end
end
23 changes: 23 additions & 0 deletions test/jobs/domain_update_confirm_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ def test_protects_statuses_after_confirm
assert @domain.statuses.include? DomainStatus::DISPUTED
end

def test_works_id_current_user_id_broken
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <update>\n <update>\n <name>#{@domain.name}</name>\n" \
" <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"
parsed_frame = Deserializers::Xml::DomainUpdate.new(Nokogiri::XML(epp_xml), @domain.registrar.id).call

@domain.pending_json['frame'] = parsed_frame
@domain.pending_json['current_user_id'] = { key: 'some_value'}
@domain.update(pending_json: @domain.pending_json)
@domain.update(statuses: [DomainStatus::DELETE_CANDIDATE, DomainStatus::DISPUTED])

assert_nothing_raised do
DomainUpdateConfirmJob.perform_now(@domain.id, RegistrantVerification::CONFIRMED)
end
@domain.reload

assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION
assert_not @domain.statuses.include? DomainStatus::PENDING_DELETE
assert @domain.statuses.include? DomainStatus::DELETE_CANDIDATE
assert @domain.statuses.include? DomainStatus::DISPUTED
end

def test_clears_pending_update_and_inactive_after_denial
epp_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp>\n <command>\n <update>\n <update>\n <name>#{@domain.name}</name>\n" \
" <chg>\n <registrant>#{@new_registrant.code}</registrant>\n </chg>\n </update>\n </update>\n <extension>\n <update/>\n" \
Expand Down

0 comments on commit a889e99

Please sign in to comment.