mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +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?
|
||||
|
||||
before_validation :set_ident_country_code
|
||||
before_create :update_code
|
||||
before_validation :prefix_code
|
||||
before_create :generate_auth_info
|
||||
after_save :manage_statuses
|
||||
def manage_statuses
|
||||
|
@ -126,7 +126,8 @@ class Contact < ActiveRecord::Base
|
|||
self[:code] = code if new_record? # cannot change code later
|
||||
end
|
||||
|
||||
def update_code
|
||||
def prefix_code
|
||||
return nil if registrar.blank?
|
||||
code = self[:code]
|
||||
|
||||
# custom code from client
|
||||
|
@ -135,7 +136,6 @@ class Contact < ActiveRecord::Base
|
|||
code.sub!(/^CID:/, '')
|
||||
prefix, *custom_code = code.split(':')
|
||||
code = custom_code.join(':') if prefix == registrar.code
|
||||
code = nil if code == registrar.code
|
||||
end
|
||||
|
||||
code = SecureRandom.hex(4) if code.blank? || code == registrar.code
|
||||
|
@ -143,7 +143,7 @@ class Contact < ActiveRecord::Base
|
|||
self[:code] = "#{registrar.code}:#{code}".upcase
|
||||
end
|
||||
|
||||
# used only for contact trasfere
|
||||
# used only for contact trasphere
|
||||
def generate_new_code!
|
||||
return nil if registrar.blank?
|
||||
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, :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
|
||||
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'
|
||||
back_to_domains: 'Back to domains'
|
||||
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'
|
||||
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
|
||||
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321')
|
||||
@contact.auth_info.should == 'qwe321'
|
||||
|
@ -258,10 +274,10 @@ describe Contact do
|
|||
@contact.code.should_not == ''
|
||||
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.valid?
|
||||
@contact.errors.full_messages.should == ['Code is invalid']
|
||||
@contact.valid?.should == true
|
||||
@contact.code.should =~ /FIXED:..../
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -120,5 +120,11 @@ describe Registrar do
|
|||
i.sum.should == BigDecimal.new('240.0')
|
||||
i.description.should == 'add some money'
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue