mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +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
|
# model related
|
||||||
gem 'pg', '~> 0.18.0'
|
gem 'pg', '~> 0.18.0'
|
||||||
gem 'ransack', '~> 1.5.1' # for searching
|
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
|
# with polymorphic fix
|
||||||
gem 'paper_trail',
|
gem 'paper_trail',
|
||||||
github: 'airblade/paper_trail',
|
github: 'airblade/paper_trail',
|
||||||
|
|
|
@ -521,6 +521,8 @@ GEM
|
||||||
parser (~> 2.2.2)
|
parser (~> 2.2.2)
|
||||||
procto (~> 0.0.2)
|
procto (~> 0.0.2)
|
||||||
uuidtools (2.1.5)
|
uuidtools (2.1.5)
|
||||||
|
validates_email_format_of (1.6.3)
|
||||||
|
i18n
|
||||||
virtus (1.0.5)
|
virtus (1.0.5)
|
||||||
axiom-types (~> 0.1)
|
axiom-types (~> 0.1)
|
||||||
coercible (~> 1.0)
|
coercible (~> 1.0)
|
||||||
|
@ -622,4 +624,5 @@ DEPENDENCIES
|
||||||
uglifier (~> 2.7.1)
|
uglifier (~> 2.7.1)
|
||||||
unicorn
|
unicorn
|
||||||
uuidtools (~> 2.1.4)
|
uuidtools (~> 2.1.4)
|
||||||
|
validates_email_format_of (~> 1.6.3)
|
||||||
whenever (~> 0.9.4)
|
whenever (~> 0.9.4)
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Contact < ActiveRecord::Base
|
||||||
# Phone nr validation is very minimam in order to support legacy requirements
|
# Phone nr validation is very minimam in order to support legacy requirements
|
||||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
||||||
validates :email, format: /@/
|
validates :email, format: /@/
|
||||||
|
validates :email, email_format: { message: :invalid }, if: proc { |c| c.email_changed? }
|
||||||
validates :ident,
|
validates :ident,
|
||||||
format: { with: /\d{4}-\d{2}-\d{2}/, message: :invalid_birthday_format },
|
format: { with: /\d{4}-\d{2}-\d{2}/, message: :invalid_birthday_format },
|
||||||
if: proc { |c| c.ident_type == 'birthday' }
|
if: proc { |c| c.ident_type == 'birthday' }
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Invoice < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
|
|
||||||
attr_accessor :billing_email
|
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,
|
validates :invoice_type, :due_date, :currency, :seller_name,
|
||||||
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
||||||
|
|
|
@ -45,7 +45,9 @@ class Registrar < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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)
|
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)
|
cr_date.text.in_time_zone.utc.should be_within(5).of(Time.zone.now)
|
||||||
end
|
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
|
it 'should add registrar prefix for code when missing' do
|
||||||
response = create_request({ id: { value: 'abc12345' } })
|
response = create_request({ id: { value: 'abc12345' } })
|
||||||
response[:msg].should == 'Command completed successfully'
|
response[:msg].should == 'Command completed successfully'
|
||||||
|
@ -397,6 +404,18 @@ describe 'EPP Contact', epp: true do
|
||||||
response[:results][1][:result_code].should == '2005'
|
response[:results][1][:result_code].should == '2005'
|
||||||
end
|
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
|
it 'should not update code with custom string' do
|
||||||
response = update_request(
|
response = update_request(
|
||||||
{
|
{
|
||||||
|
|
|
@ -109,6 +109,12 @@ describe Contact do
|
||||||
it 'should have no related domain descriptions' do
|
it 'should have no related domain descriptions' do
|
||||||
@contact.related_domain_descriptions.should == {}
|
@contact.related_domain_descriptions.should == {}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'with valid attributes' do
|
context 'with valid attributes' do
|
||||||
|
@ -247,6 +253,14 @@ describe Contact do
|
||||||
contact = @domain.contacts.first
|
contact = @domain.contacts.first
|
||||||
contact.related_domain_descriptions.should == { "#{@domain.name}" => [:admin] }
|
contact.related_domain_descriptions.should == { "#{@domain.name}" => [:admin] }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'as birthday' do
|
context 'as birthday' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue