Merge pull request #2170 from internetee/2169-disputes-fix-for-password-checking

Disputes: fix for registration of disputed domains
This commit is contained in:
Timo Võhmar 2021-09-28 22:01:46 +03:00 committed by GitHub
commit a4d94bffad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 7 deletions

View file

@ -8,12 +8,12 @@ module Whois
def execute
::PaperTrail.request.whodunnit = "job - #{self.class.name} - #{type}"
klass = determine_class
collection = determine_collection
Array(names).each do |name|
record = find_record(klass, name)
record = find_record(collection, name)
if record
Whois::UpdateRecord.run(record: { klass: klass.to_s, id: record.id, type: type })
Whois::UpdateRecord.run(record: { klass: collection.to_s, id: record.id, type: type })
else
Whois::DeleteRecord.run(name: name, type: type)
end
@ -22,7 +22,7 @@ module Whois
private
def determine_class
def determine_collection
case type
when 'reserved' then ReservedDomain
when 'blocked' then BlockedDomain
@ -32,8 +32,12 @@ module Whois
end
end
def find_record(klass, name)
klass == DNS::Zone ? klass.find_by(origin: name) : klass.find_by(name: name)
def find_record(collection, name)
if collection == Dispute.active
collection.find_by(domain_name: name)
else
collection == DNS::Zone ? collection.find_by(origin: name) : collection.find_by(name: name)
end
end
end
end

View file

@ -21,12 +21,16 @@ module Domain::Disputable
@in_disputed_list ||= Dispute.active.find_by(domain_name: name).present?
end
def in_auction_list?
@in_auction_list ||= Auction.find_by(domain: name, status: Auction.statuses[:started]).present?
end
def disputed?
Dispute.active.where(domain_name: name).any?
end
def validate_disputed
return if persisted? || !in_disputed_list?
return if persisted? || !in_disputed_list? || in_auction_list?
if reserved_pw.blank?
errors.add(:base, :required_parameter_missing_disputed)

View file

@ -814,4 +814,42 @@ class EppDomainCreateBaseTest < EppTestCase
assert_correct_against_schema response_xml
assert_epp_response :billing_failure
end
def test_registers_disputed_domain_with_password
now = Time.zone.parse('2010-07-05')
travel_to now
disputed_domain = disputes(:active)
password = disputed_domain.password
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<create>
<domain:create xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')}">
<domain:name>#{disputed_domain.domain_name}</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis', for_version: '1.0')}">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>#{password}</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :completed_successfully
end
end