mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Validate contact and invoice emails when they change #2745
This commit is contained in:
parent
c482a3e46d
commit
6ca53f946a
7 changed files with 43 additions and 2 deletions
2
Gemfile
2
Gemfile
|
@ -18,6 +18,8 @@ gem 'figaro', '~> 1.1.1'
|
|||
# model related
|
||||
gem 'pg', '~> 0.18.0'
|
||||
gem 'ransack', '~> 1.5.1' # for searching
|
||||
gem 'validates_email_format_of', '~> 1.6.3' # validates email against RFC 2822 and RFC 3696
|
||||
|
||||
# with polymorphic fix
|
||||
gem 'paper_trail',
|
||||
github: 'airblade/paper_trail',
|
||||
|
|
|
@ -521,6 +521,8 @@ GEM
|
|||
parser (~> 2.2.2)
|
||||
procto (~> 0.0.2)
|
||||
uuidtools (2.1.5)
|
||||
validates_email_format_of (1.6.3)
|
||||
i18n
|
||||
virtus (1.0.5)
|
||||
axiom-types (~> 0.1)
|
||||
coercible (~> 1.0)
|
||||
|
@ -622,4 +624,5 @@ DEPENDENCIES
|
|||
uglifier (~> 2.7.1)
|
||||
unicorn
|
||||
uuidtools (~> 2.1.4)
|
||||
validates_email_format_of (~> 1.6.3)
|
||||
whenever (~> 0.9.4)
|
||||
|
|
|
@ -19,6 +19,7 @@ class Contact < ActiveRecord::Base
|
|||
# Phone nr validation is very minimam in order to support legacy requirements
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
||||
validates :email, format: /@/
|
||||
validates :email, email_format: { message: :invalid }, if: proc { |c| c.email_changed? }
|
||||
validates :ident,
|
||||
format: { with: /\d{4}-\d{2}-\d{2}/, message: :invalid_birthday_format },
|
||||
if: proc { |c| c.ident_type == 'birthday' }
|
||||
|
|
|
@ -12,7 +12,7 @@ class Invoice < ActiveRecord::Base
|
|||
}
|
||||
|
||||
attr_accessor :billing_email
|
||||
validates :billing_email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, allow_blank: true
|
||||
validates :billing_email, email_format: { message: :invalid }, allow_blank: true
|
||||
|
||||
validates :invoice_type, :due_date, :currency, :seller_name,
|
||||
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
||||
|
|
|
@ -45,7 +45,9 @@ class Registrar < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
validates :email, :billing_email, format: /@/, allow_blank: true
|
||||
validates :email, :billing_email,
|
||||
email_format: { message: :invalid },
|
||||
allow_blank: true, if: proc { |c| c.email_changed? }
|
||||
|
||||
WHOIS_TRIGGERS = %w(name email phone street city state zip)
|
||||
|
||||
|
|
|
@ -133,6 +133,13 @@ describe 'EPP Contact', epp: true do
|
|||
cr_date.text.in_time_zone.utc.should be_within(5).of(Time.zone.now)
|
||||
end
|
||||
|
||||
it 'should return email issue' do
|
||||
response = create_request(email: { value: 'not@valid' })
|
||||
|
||||
response[:msg].should == 'Email is invalid [email]'
|
||||
response[:result_code].should == '2005'
|
||||
end
|
||||
|
||||
it 'should add registrar prefix for code when missing' do
|
||||
response = create_request({ id: { value: 'abc12345' } })
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
|
@ -397,6 +404,18 @@ describe 'EPP Contact', epp: true do
|
|||
response[:results][1][:result_code].should == '2005'
|
||||
end
|
||||
|
||||
it 'should return email issue' do
|
||||
response = update_request({
|
||||
id: { value: 'FIRST0:SH8013' },
|
||||
chg: {
|
||||
email: { value: 'legacy@wrong' }
|
||||
}
|
||||
})
|
||||
|
||||
response[:msg].should == 'Email is invalid [email]'
|
||||
response[:result_code].should == '2005'
|
||||
end
|
||||
|
||||
it 'should not update code with custom string' do
|
||||
response = update_request(
|
||||
{
|
||||
|
|
|
@ -109,6 +109,12 @@ describe Contact do
|
|||
it 'should have no related domain descriptions' do
|
||||
@contact.related_domain_descriptions.should == {}
|
||||
end
|
||||
|
||||
it 'should fully validate email syntax for new records' do
|
||||
@contact.email = 'not@correct'
|
||||
@contact.valid?
|
||||
@contact.errors[:email].should == ['Email is invalid']
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid attributes' do
|
||||
|
@ -247,6 +253,14 @@ describe Contact do
|
|||
contact = @domain.contacts.first
|
||||
contact.related_domain_descriptions.should == { "#{@domain.name}" => [:admin] }
|
||||
end
|
||||
|
||||
it 'should fully validate email syntax for old records' do
|
||||
old = @contact.email
|
||||
@contact.email = 'legacy@support-not-correct'
|
||||
@contact.valid?
|
||||
@contact.errors[:email].should == ['Email is invalid']
|
||||
@contact.email = old
|
||||
end
|
||||
end
|
||||
|
||||
context 'as birthday' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue