mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 04:07:33 +02:00
parent
5d61cbf4a8
commit
daba47790c
9 changed files with 125 additions and 125 deletions
|
@ -30,6 +30,12 @@ module Api
|
|||
raise "Invalid status #{params[:status]}"
|
||||
end
|
||||
|
||||
if auction.payment_not_received? || auction.domain_not_registered?
|
||||
update_whois_from_auction(Auction.pending(auction.domain))
|
||||
else
|
||||
update_whois_from_auction(auction)
|
||||
end
|
||||
|
||||
render json: serializable_hash_for_update_action(auction)
|
||||
end
|
||||
|
||||
|
@ -44,6 +50,11 @@ module Api
|
|||
hash[:registration_code] = auction.registration_code if auction.payment_received?
|
||||
hash
|
||||
end
|
||||
|
||||
def update_whois_from_auction(auction)
|
||||
whois_record = Whois::Record.find_by!(name: auction.domain)
|
||||
whois_record.update_from_auction(auction)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,19 +14,17 @@ class Auction < ActiveRecord::Base
|
|||
statuses[:payment_received]].freeze
|
||||
private_constant :PENDING_STATUSES
|
||||
|
||||
def self.sell(domain_name)
|
||||
create!(domain: domain_name.to_s, status: statuses[:started])
|
||||
end
|
||||
|
||||
def self.pending(domain_name)
|
||||
find_by(domain: domain_name.to_s, status: PENDING_STATUSES)
|
||||
end
|
||||
|
||||
def start
|
||||
self.status = self.class.statuses[:started]
|
||||
save!
|
||||
end
|
||||
|
||||
def mark_as_no_bids
|
||||
transaction do
|
||||
DNS::DomainName.new(domain).update_whois
|
||||
no_bids!
|
||||
end
|
||||
no_bids!
|
||||
end
|
||||
|
||||
def mark_as_payment_received
|
||||
|
@ -57,17 +55,18 @@ class Auction < ActiveRecord::Base
|
|||
payment_received? && registration_code_matches?(registration_code)
|
||||
end
|
||||
|
||||
def restart
|
||||
new_auction = self.class.new(domain: domain)
|
||||
new_auction.start
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_registration_code
|
||||
self.registration_code = SecureRandom.hex
|
||||
end
|
||||
|
||||
def restart
|
||||
self.class.create!(domain: domain, status: self.class.statuses[:started])
|
||||
end
|
||||
|
||||
def registration_code_matches?(code)
|
||||
registration_code == code
|
||||
end
|
||||
end
|
||||
end
|
|
@ -33,8 +33,10 @@ module DNS
|
|||
end
|
||||
|
||||
def sell_at_auction
|
||||
Auction.sell(self)
|
||||
update_whois
|
||||
auction = Auction.new
|
||||
auction.domain = name
|
||||
auction.start
|
||||
update_whois_from_auction(auction)
|
||||
end
|
||||
|
||||
def at_auction?
|
||||
|
@ -49,10 +51,6 @@ module DNS
|
|||
pending_auction&.payment_received?
|
||||
end
|
||||
|
||||
def update_whois
|
||||
Whois::Record.refresh(self)
|
||||
end
|
||||
|
||||
def registered?
|
||||
Domain.find_by_idn(name)
|
||||
end
|
||||
|
@ -92,5 +90,10 @@ module DNS
|
|||
def pending_auction
|
||||
Auction.pending(self)
|
||||
end
|
||||
|
||||
def update_whois_from_auction(auction)
|
||||
whois_record = Whois::Record.find_by!(name: name)
|
||||
whois_record.update_from_auction(auction)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,22 +6,18 @@ module Whois
|
|||
Setting.registry_whois_disclaimer
|
||||
end
|
||||
|
||||
def self.refresh(domain_name)
|
||||
if domain_name.at_auction?
|
||||
# Remove original record since `Domain#update_whois_record` callback is disabled when
|
||||
# domain is at auction
|
||||
find_by(name: domain_name.to_s).try(:destroy!)
|
||||
|
||||
create!(name: domain_name, json: { name: domain_name.to_s,
|
||||
status: ['AtAuction'],
|
||||
disclaimer: disclaimer })
|
||||
elsif domain_name.awaiting_payment? || domain_name.pending_registration?
|
||||
find_by(name: domain_name.to_s).update!(json: { name: domain_name.to_s,
|
||||
status: ['PendingRegistration'],
|
||||
disclaimer: disclaimer })
|
||||
else
|
||||
find_by(name: domain_name.to_s).destroy!
|
||||
def update_from_auction(auction)
|
||||
if auction.started?
|
||||
update!(json: { name: auction.domain,
|
||||
status: ['AtAuction'],
|
||||
disclaimer: self.class.disclaimer })
|
||||
elsif auction.no_bids?
|
||||
destroy!
|
||||
elsif auction.awaiting_payment? || auction.payment_received?
|
||||
update!(json: { name: auction.domain,
|
||||
status: ['PendingRegistration'],
|
||||
disclaimer: self.class.disclaimer })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,6 +5,8 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
|
||||
setup do
|
||||
@auction = auctions(:one)
|
||||
@whois_record = whois_records(:one)
|
||||
@whois_record.update!(name: 'auction.test')
|
||||
|
||||
@original_auction_api_allowed_ips_setting = ENV['auction_api_allowed_ips']
|
||||
ENV['auction_api_allowed_ips'] = '127.0.0.1'
|
||||
|
@ -36,9 +38,6 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_marks_as_no_bids
|
||||
assert_equal 'auction.test', @auction.domain
|
||||
whois_records(:one).update!(name: 'auction.test')
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:no_bids] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
@auction.reload
|
||||
|
@ -59,6 +58,13 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
assert @auction.payment_not_received?
|
||||
end
|
||||
|
||||
def test_marks_as_domain_not_registered
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:domain_not_registered] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
@auction.reload
|
||||
assert @auction.domain_not_registered?
|
||||
end
|
||||
|
||||
def test_reveals_registration_code_when_payment_is_received
|
||||
@auction.update!(registration_code: 'auction-001',
|
||||
status: Auction.statuses[:awaiting_payment])
|
||||
|
@ -80,22 +86,16 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
assert_nil response_json['registration_code']
|
||||
end
|
||||
|
||||
def test_restarts_an_auction_when_the_payment_is_not_received
|
||||
@auction.update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
|
||||
def test_updates_whois
|
||||
travel_to Time.zone.parse('2010-07-05 10:00')
|
||||
assert_equal 'auction.test', @auction.domain
|
||||
@whois_record.update!(updated_at: '2010-07-04')
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_not_received] }
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
@whois_record.reload
|
||||
|
||||
assert DNS::DomainName.new('auction.test').at_auction?
|
||||
end
|
||||
|
||||
def test_restarts_an_auction_when_domain_is_not_registered
|
||||
@auction.update!(domain: 'auction.test', status: Auction.statuses[:payment_received])
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:domain_not_registered] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
|
||||
assert DNS::DomainName.new('auction.test').at_auction?
|
||||
assert_equal Time.zone.parse('2010-07-05 10:00'), @whois_record.updated_at
|
||||
end
|
||||
|
||||
def test_inaccessible_when_ip_address_is_not_allowed
|
||||
|
|
|
@ -19,15 +19,13 @@ class AuctionTest < ActiveSupport::TestCase
|
|||
'domain_not_registered' => 'domain_not_registered' }), Auction.statuses
|
||||
end
|
||||
|
||||
def test_selling_domain_starts_new_auction
|
||||
domain_name = DNS::DomainName.new('shop.test')
|
||||
def test_starts_an_auction
|
||||
assert_not @auction.started?
|
||||
|
||||
assert_difference 'Auction.count' do
|
||||
Auction.sell(domain_name)
|
||||
end
|
||||
auction = Auction.last
|
||||
assert_equal domain_name.to_s, auction.domain
|
||||
assert auction.started?
|
||||
@auction.start
|
||||
@auction.reload
|
||||
|
||||
assert @auction.started?
|
||||
end
|
||||
|
||||
def test_pending
|
||||
|
@ -84,16 +82,12 @@ class AuctionTest < ActiveSupport::TestCase
|
|||
assert_nil @auction.registration_code
|
||||
end
|
||||
|
||||
def test_restarts_an_auction_when_payment_is_not_received
|
||||
@auction.update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
|
||||
def test_marking_as_payment_not_received_restarts_an_auction
|
||||
@auction.update!(status: Auction.statuses[:awaiting_payment])
|
||||
|
||||
assert_difference 'Auction.count' do
|
||||
@auction.mark_as_payment_not_received
|
||||
end
|
||||
|
||||
new_auction = Auction.last
|
||||
assert_equal 'auction.test', new_auction.domain
|
||||
assert new_auction.started?
|
||||
end
|
||||
|
||||
def test_marking_as_domain_not_registered
|
||||
|
@ -105,16 +99,12 @@ class AuctionTest < ActiveSupport::TestCase
|
|||
assert @auction.domain_not_registered?
|
||||
end
|
||||
|
||||
def test_restarts_an_auction_when_domain_is_not_registered
|
||||
@auction.update!(domain: 'auction.test', status: Auction.statuses[:domain_not_registered])
|
||||
def test_marking_as_domain_not_registered_restarts_an_auction
|
||||
@auction.update!(status: Auction.statuses[:payment_received])
|
||||
|
||||
assert_difference 'Auction.count' do
|
||||
@auction.mark_as_domain_not_registered
|
||||
end
|
||||
|
||||
new_auction = Auction.last
|
||||
assert_equal 'auction.test', new_auction.domain
|
||||
assert new_auction.started?
|
||||
end
|
||||
|
||||
def test_domain_registrable
|
||||
|
@ -140,4 +130,16 @@ class AuctionTest < ActiveSupport::TestCase
|
|||
assert_not @auction.domain_registrable?(nil)
|
||||
assert_not @auction.domain_registrable?('')
|
||||
end
|
||||
end
|
||||
|
||||
def test_restarts_an_auction
|
||||
assert_equal 'auction.test', @auction.domain
|
||||
|
||||
assert_difference 'Auction.count' do
|
||||
@auction.restart
|
||||
end
|
||||
|
||||
new_auction = Auction.last
|
||||
assert_equal 'auction.test', new_auction.domain
|
||||
assert new_auction.started?
|
||||
end
|
||||
end
|
|
@ -71,8 +71,8 @@ class DNS::DomainNameTest < ActiveSupport::TestCase
|
|||
assert_equal :awaiting_payment, domain_name.unavailability_reason
|
||||
end
|
||||
|
||||
def test_sell_at_auction
|
||||
domain_name = DNS::DomainName.new('new-auction.test')
|
||||
def test_sells_at_auction
|
||||
domain_name = DNS::DomainName.new('shop.test')
|
||||
assert_not domain_name.at_auction?
|
||||
|
||||
domain_name.sell_at_auction
|
||||
|
@ -81,12 +81,15 @@ class DNS::DomainNameTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_selling_at_auction_updates_whois
|
||||
travel_to Time.zone.parse('2010-07-05 10:00')
|
||||
@whois_record = whois_records(:one)
|
||||
@whois_record.update!(name: 'new-auction.test', updated_at: '2010-07-04')
|
||||
domain_name = DNS::DomainName.new('new-auction.test')
|
||||
assert_not domain_name.at_auction?
|
||||
|
||||
domain_name.sell_at_auction
|
||||
@whois_record.reload
|
||||
|
||||
assert Whois::Record.find_by(name: 'new-auction.test')
|
||||
assert_equal Time.zone.parse('2010-07-05 10:00'), @whois_record.updated_at
|
||||
end
|
||||
|
||||
def test_at_auction
|
||||
|
@ -159,4 +162,4 @@ class DNS::DomainNameTest < ActiveSupport::TestCase
|
|||
assert_equal 'reserved.test', reserved_domains(:one).name
|
||||
assert_not DNS::DomainName.new('reserved.test').auctionable?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -49,16 +49,6 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_updates_whois
|
||||
assert_equal 'shop.test', @domain.name
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
Domain.release_domains
|
||||
|
||||
assert Whois::Record.find_by(name: 'shop.test')
|
||||
end
|
||||
|
||||
def test_ignores_domains_with_delete_at_in_the_future_or_now
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 08:00'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
|
|
@ -4,64 +4,60 @@ class Whois::RecordTest < ActiveSupport::TestCase
|
|||
fixtures 'whois/records'
|
||||
|
||||
setup do
|
||||
@whois_record = whois_records(:one)
|
||||
@auction = auctions(:one)
|
||||
|
||||
@original_disclaimer_setting = Setting.registry_whois_disclaimer
|
||||
Setting.registry_whois_disclaimer = 'disclaimer'
|
||||
end
|
||||
|
||||
teardown do
|
||||
Setting.registry_whois_disclaimer = @original_disclaimer_setting
|
||||
end
|
||||
|
||||
def test_reads_disclaimer_from_settings
|
||||
def test_reads_disclaimer_setting
|
||||
Setting.registry_whois_disclaimer = 'test disclaimer'
|
||||
assert_equal 'test disclaimer', Whois::Record.disclaimer
|
||||
end
|
||||
|
||||
def test_creates_new_whois_record_when_domain_is_at_auction
|
||||
domain_name = DNS::DomainName.new('some.test')
|
||||
Setting.registry_whois_disclaimer = 'disclaimer'
|
||||
def test_updates_whois_record_from_auction_when_started
|
||||
@auction.update!(domain: 'domain.test', status: Auction.statuses[:started])
|
||||
@whois_record.update!(name: 'domain.test')
|
||||
@whois_record.update_from_auction(@auction)
|
||||
@whois_record.reload
|
||||
|
||||
domain_name.stub(:at_auction?, true) do
|
||||
assert_difference 'Whois::Record.count' do
|
||||
Whois::Record.refresh(domain_name)
|
||||
end
|
||||
end
|
||||
|
||||
whois_record = Whois::Record.last
|
||||
assert_equal 'some.test', whois_record.name
|
||||
assert_equal ({ 'name' => 'some.test',
|
||||
assert_equal ({ 'name' => 'domain.test',
|
||||
'status' => ['AtAuction'],
|
||||
'disclaimer' => 'disclaimer' }), whois_record.json
|
||||
'disclaimer' => 'disclaimer' }), @whois_record.json
|
||||
end
|
||||
|
||||
def test_refreshes_whois_record_when_domain_auction_reaches_awaiting_payment_state
|
||||
domain_name = DNS::DomainName.new('some.test')
|
||||
Setting.registry_whois_disclaimer = 'disclaimer'
|
||||
whois_records(:one).update!(name: 'some.test')
|
||||
def test_updates_whois_record_from_auction_when_no_bids
|
||||
@auction.update!(domain: 'domain.test', status: Auction.statuses[:no_bids])
|
||||
@whois_record.update!(name: 'domain.test')
|
||||
@whois_record.update_from_auction(@auction)
|
||||
|
||||
domain_name.stub(:awaiting_payment?, true) do
|
||||
Whois::Record.refresh(domain_name)
|
||||
end
|
||||
assert_not Whois::Record.exists?(name: 'domain.test')
|
||||
end
|
||||
|
||||
whois_record = Whois::Record.find_by(name: 'some.test')
|
||||
assert_equal 'some.test', whois_record.name
|
||||
assert_equal ({ 'name' => 'some.test',
|
||||
def test_updates_whois_record_from_auction_when_awaiting_payment
|
||||
@auction.update!(domain: 'domain.test', status: Auction.statuses[:awaiting_payment])
|
||||
@whois_record.update!(name: 'domain.test')
|
||||
@whois_record.update_from_auction(@auction)
|
||||
@whois_record.reload
|
||||
|
||||
assert_equal ({ 'name' => 'domain.test',
|
||||
'status' => ['PendingRegistration'],
|
||||
'disclaimer' => 'disclaimer' }), whois_record.json
|
||||
'disclaimer' => 'disclaimer' }), @whois_record.json
|
||||
end
|
||||
|
||||
def test_refreshes_whois_record_when_domain_auction_reaches_pending_registration_state
|
||||
domain_name = DNS::DomainName.new('some.test')
|
||||
Setting.registry_whois_disclaimer = 'disclaimer'
|
||||
whois_records(:one).update!(name: 'some.test')
|
||||
def test_updates_whois_record_from_auction_when_payment_received
|
||||
@auction.update!(domain: 'domain.test', status: Auction.statuses[:payment_received])
|
||||
@whois_record.update!(name: 'domain.test')
|
||||
@whois_record.update_from_auction(@auction)
|
||||
@whois_record.reload
|
||||
|
||||
domain_name.stub(:pending_registration?, true) do
|
||||
Whois::Record.refresh(domain_name)
|
||||
end
|
||||
|
||||
whois_record = Whois::Record.find_by(name: 'some.test')
|
||||
assert_equal 'some.test', whois_record.name
|
||||
assert_equal ({ 'name' => 'some.test',
|
||||
assert_equal ({ 'name' => 'domain.test',
|
||||
'status' => ['PendingRegistration'],
|
||||
'disclaimer' => 'disclaimer' }), whois_record.json
|
||||
'disclaimer' => 'disclaimer' }), @whois_record.json
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue