mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
disallow CID for registrar code and fix double code check
This commit is contained in:
parent
c27de39a15
commit
1f504e08ea
5 changed files with 36 additions and 7 deletions
|
@ -27,7 +27,7 @@ class Contact < ActiveRecord::Base
|
||||||
validate :ident_valid_format?
|
validate :ident_valid_format?
|
||||||
|
|
||||||
before_validation :set_ident_country_code
|
before_validation :set_ident_country_code
|
||||||
before_create :update_code
|
before_validation :prefix_code
|
||||||
before_create :generate_auth_info
|
before_create :generate_auth_info
|
||||||
after_save :manage_statuses
|
after_save :manage_statuses
|
||||||
def manage_statuses
|
def manage_statuses
|
||||||
|
@ -126,7 +126,8 @@ class Contact < ActiveRecord::Base
|
||||||
self[:code] = code if new_record? # cannot change code later
|
self[:code] = code if new_record? # cannot change code later
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_code
|
def prefix_code
|
||||||
|
return nil if registrar.blank?
|
||||||
code = self[:code]
|
code = self[:code]
|
||||||
|
|
||||||
# custom code from client
|
# custom code from client
|
||||||
|
@ -135,7 +136,6 @@ class Contact < ActiveRecord::Base
|
||||||
code.sub!(/^CID:/, '')
|
code.sub!(/^CID:/, '')
|
||||||
prefix, *custom_code = code.split(':')
|
prefix, *custom_code = code.split(':')
|
||||||
code = custom_code.join(':') if prefix == registrar.code
|
code = custom_code.join(':') if prefix == registrar.code
|
||||||
code = nil if code == registrar.code
|
|
||||||
end
|
end
|
||||||
|
|
||||||
code = SecureRandom.hex(4) if code.blank? || code == registrar.code
|
code = SecureRandom.hex(4) if code.blank? || code == registrar.code
|
||||||
|
@ -143,7 +143,7 @@ class Contact < ActiveRecord::Base
|
||||||
self[:code] = "#{registrar.code}:#{code}".upcase
|
self[:code] = "#{registrar.code}:#{code}".upcase
|
||||||
end
|
end
|
||||||
|
|
||||||
# used only for contact trasfere
|
# used only for contact trasphere
|
||||||
def generate_new_code!
|
def generate_new_code!
|
||||||
return nil if registrar.blank?
|
return nil if registrar.blank?
|
||||||
registrar.reload # for contact transfere
|
registrar.reload # for contact transfere
|
||||||
|
|
|
@ -14,6 +14,12 @@ class Registrar < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name, :reg_no, :country_code, :email, :code, presence: true
|
validates :name, :reg_no, :country_code, :email, :code, presence: true
|
||||||
validates :name, :reg_no, :reference_no, :code, uniqueness: true
|
validates :name, :reg_no, :reference_no, :code, uniqueness: true
|
||||||
|
validate :forbidden_codes
|
||||||
|
def forbidden_codes
|
||||||
|
return true unless ['CID'].include? code
|
||||||
|
errors.add(:code, I18n.t(:forbidden_code))
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
before_validation :generate_iso_11649_reference_no
|
before_validation :generate_iso_11649_reference_no
|
||||||
def generate_iso_11649_reference_no
|
def generate_iso_11649_reference_no
|
||||||
|
|
|
@ -756,3 +756,4 @@ en:
|
||||||
hostnames_will_be_replaced_only_if_domain_validates_with_the_new_nameserver: 'Hostnames will be replaced only if domain validates with the new nameserver'
|
hostnames_will_be_replaced_only_if_domain_validates_with_the_new_nameserver: 'Hostnames will be replaced only if domain validates with the new nameserver'
|
||||||
back_to_domains: 'Back to domains'
|
back_to_domains: 'Back to domains'
|
||||||
no_hostnames_replaced: 'No hostnames replaced'
|
no_hostnames_replaced: 'No hostnames replaced'
|
||||||
|
forbidden_code: 'is forbidden to use'
|
||||||
|
|
|
@ -228,6 +228,22 @@ describe Contact do
|
||||||
@contact.code.should == 'FIXED:NEW-CODE'
|
@contact.code.should == 'FIXED:NEW-CODE'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not allaw to use same code' do
|
||||||
|
@contact = Fabricate.build(:contact,
|
||||||
|
code: 'FIXED:new-code',
|
||||||
|
auth_info: 'qwe321')
|
||||||
|
@contact.code.should == 'FIXED:new-code' # still new record
|
||||||
|
@contact.save.should == true
|
||||||
|
@contact.code.should == 'FIXED:NEW-CODE'
|
||||||
|
|
||||||
|
@contact = Fabricate.build(:contact,
|
||||||
|
code: 'FIXED:new-code',
|
||||||
|
auth_info: 'qwe321')
|
||||||
|
@contact.code.should == 'FIXED:new-code' # still new record
|
||||||
|
@contact.valid?
|
||||||
|
@contact.errors.full_messages.should == ["Code Contact id already exists"]
|
||||||
|
end
|
||||||
|
|
||||||
it 'should generate a new password' do
|
it 'should generate a new password' do
|
||||||
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321')
|
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321')
|
||||||
@contact.auth_info.should == 'qwe321'
|
@contact.auth_info.should == 'qwe321'
|
||||||
|
@ -258,10 +274,10 @@ describe Contact do
|
||||||
@contact.code.should_not == ''
|
@contact.code.should_not == ''
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not allow empty spaces as code' do
|
it 'should not ignore empty spaces as code and generate new one' do
|
||||||
@contact = Fabricate.build(:contact, code: ' ')
|
@contact = Fabricate.build(:contact, code: ' ')
|
||||||
@contact.valid?
|
@contact.valid?.should == true
|
||||||
@contact.errors.full_messages.should == ['Code is invalid']
|
@contact.code.should =~ /FIXED:..../
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -120,5 +120,11 @@ describe Registrar do
|
||||||
i.sum.should == BigDecimal.new('240.0')
|
i.sum.should == BigDecimal.new('240.0')
|
||||||
i.description.should == 'add some money'
|
i.description.should == 'add some money'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fit 'should not allaw to use CID as code for leagcy reasons' do
|
||||||
|
registrar = Fabricate.build(:registrar, code: 'CID')
|
||||||
|
registrar.valid?
|
||||||
|
registrar.errors.full_messages.should == ['Code is forbidden to use']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue