mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Generate auth info automatically
This commit is contained in:
parent
aa56fa3160
commit
6352ed340f
4 changed files with 25 additions and 7 deletions
|
@ -99,8 +99,7 @@ module Epp::DomainsHelper
|
|||
period: (@ph[:period].to_i == 0) ? 1 : @ph[:period].to_i,
|
||||
period_unit: Domain.parse_period_unit_from_frame(parsed_frame) || 'y',
|
||||
valid_from: Date.today,
|
||||
valid_to: valid_to,
|
||||
auth_info: @ph[:authInfo][:pw]
|
||||
valid_to: valid_to
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ class Domain < ActiveRecord::Base
|
|||
delegate :code, to: :owner_contact, prefix: true
|
||||
delegate :name, to: :registrar, prefix: true
|
||||
|
||||
before_create :generate_auth_info
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
validates :period, numericality: { only_integer: true }
|
||||
validates :name, :owner_contact, presence: true
|
||||
|
@ -313,6 +315,12 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
## SHARED
|
||||
|
||||
def generate_auth_info
|
||||
begin
|
||||
self.auth_info = SecureRandom.hex
|
||||
end while self.class.exists?(auth_info: auth_info)
|
||||
end
|
||||
|
||||
# For domain transfer
|
||||
def authenticate(pw)
|
||||
errors.add(:auth_info, { msg: errors.generate_message(:auth_info, :wrong_pw) }) if pw != auth_info
|
||||
|
|
|
@ -49,7 +49,9 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
|
||||
it 'transfers a domain' do
|
||||
response = epp_request(domain_transfer_xml, :xml)
|
||||
pw = Domain.first.auth_info
|
||||
xml = domain_transfer_xml(pw: pw)
|
||||
response = epp_request(xml, :xml)
|
||||
|
||||
d = Domain.first
|
||||
dtl = d.domain_transfers.last
|
||||
|
@ -65,7 +67,7 @@ describe 'EPP Domain', epp: true do
|
|||
s = Setting.find_by(code: 'transfer_wait_time')
|
||||
s.update(value: 1)
|
||||
|
||||
response = epp_request(domain_transfer_xml, :xml)
|
||||
response = epp_request(xml, :xml)
|
||||
trn_data = response[:parsed].css('trnData')
|
||||
|
||||
d = Domain.first
|
||||
|
@ -81,7 +83,7 @@ describe 'EPP Domain', epp: true do
|
|||
expect(trn_data.css('exDate').text).to eq(d.valid_to.to_time.utc.to_s)
|
||||
|
||||
# should return same data if pending already
|
||||
response = epp_request(domain_transfer_xml, :xml)
|
||||
response = epp_request(xml, :xml)
|
||||
trn_data = response[:parsed].css('trnData')
|
||||
|
||||
expect(d.domain_transfers.count).to eq(2)
|
||||
|
@ -97,8 +99,11 @@ describe 'EPP Domain', epp: true do
|
|||
s = Setting.find_by(code: 'transfer_wait_time')
|
||||
s.update(value: 1)
|
||||
|
||||
epp_request(domain_transfer_xml, :xml)
|
||||
xml = domain_transfer_xml(op: 'approve')
|
||||
pw = Domain.first.auth_info
|
||||
xml = domain_transfer_xml(pw: pw)
|
||||
|
||||
epp_request(xml, :xml)
|
||||
xml = domain_transfer_xml(op: 'approve', pw: pw)
|
||||
response = epp_request(xml, :xml)
|
||||
trn_data = response[:parsed].css('trnData')
|
||||
d = Domain.first
|
||||
|
@ -147,6 +152,7 @@ describe 'EPP Domain', epp: true do
|
|||
expect(d.admin_contacts.count).to eq 1
|
||||
|
||||
expect(d.nameservers.count).to eq(2)
|
||||
expect(d.auth_info).not_to be_empty
|
||||
end
|
||||
|
||||
it 'does not create duplicate domain' do
|
||||
|
|
|
@ -76,5 +76,10 @@ describe Domain do
|
|||
expect(Fabricate.build(:domain, period: 4).valid?).to be false
|
||||
expect(Fabricate.build(:domain, period: 3).valid?).to be true
|
||||
end
|
||||
|
||||
it 'generates auth info' do
|
||||
d = Fabricate(:domain)
|
||||
expect(d.auth_info).to_not be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue