Skip to content

Commit

Permalink
Merge branch 'master' into 2210-replace-banklinks-to-linkpay
Browse files Browse the repository at this point in the history
  • Loading branch information
DinSmol authored Dec 30, 2021
2 parents b6f6eaa + 779aedc commit 03c8737
Show file tree
Hide file tree
Showing 28 changed files with 511 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-18.04]
ruby: [ 2.7, 3.0 ]
ruby: [ '2.7', '3.0.3' ]
runs-on: ${{ matrix.os }}
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
steps:
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ 2.7, 3.0 ]
ruby: [ '2.7', '3.0.3' ]
runs-on: ubuntu-18.04

env:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.3
3.1.0
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
29.12.2021
* User test env is renamed to demo to remove naming conflict with autotest env [#2238](https://github.com/internetee/registry/pull/2238)
* imporved mx level email validation for contact create and update [#2246](https://github.com/internetee/registry/issues/2246)
* improved tests for account_activities [#2255](https://github.com/internetee/registry/pull/2255)

27.12.2021
* Improved mx level checks for email validation [#2244](https://github.com/internetee/registry/issues/2244)
* fixed support for idn domains in email validation [#2250](https://github.com/internetee/registry/issues/2250)

20.12.2021
* delete prohibited can be set to domains in force delete [#2218](https://github.com/internetee/registry/issues/2218)

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gem 'figaro', '~> 1.2'
gem 'paper_trail', '~> 12.1'
gem 'pg', '1.2.3'
# 1.8 is for Rails < 5.0
gem 'ransack', '~> 2.4.2'
gem 'ransack', '~> 2.5.0'
gem 'truemail', '~> 2.4' # validates email by regexp, mail server existence and address existence
gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696

Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ GEM
httpi (2.4.5)
rack
socksify
i18n (1.8.10)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
i18n_data (0.13.0)
isikukood (0.1.2)
Expand Down Expand Up @@ -305,7 +305,7 @@ GEM
rake
mini_mime (1.1.1)
mini_portile2 (2.6.1)
minitest (5.14.4)
minitest (5.15.0)
monetize (1.9.4)
money (~> 6.12)
money (6.13.8)
Expand Down Expand Up @@ -407,7 +407,7 @@ GEM
rake (>= 0.13)
thor (~> 1.0)
rake (13.0.6)
ransack (2.4.2)
ransack (2.5.0)
activerecord (>= 5.2.4)
activesupport (>= 5.2.4)
i18n
Expand Down Expand Up @@ -529,7 +529,7 @@ GEM
wkhtmltopdf-binary (0.12.5.4)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.4.2)
zeitwerk (2.5.2)

PLATFORMS
ruby
Expand Down Expand Up @@ -587,7 +587,7 @@ DEPENDENCIES
que
que-web
rails (~> 6.1.4)
ransack (~> 2.4.2)
ransack (~> 2.5.0)
rest-client
rexml
rqrcode (~> 2.0)
Expand Down
34 changes: 34 additions & 0 deletions app/interactions/actions/a_and_aaaa_email_validation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Actions
module AAndAaaaEmailValidation
extend self

def call(email:, value:)
check_for_records_value(email: email, value: value)
end

private

def check_for_records_value(email:, value:)
email_domain = Mail::Address.new(email).domain
dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip)

resolve_a_and_aaaa_records(dns_servers: dns_servers, email_domain: email_domain, value: value)
end

def resolve_a_and_aaaa_records(dns_servers:, email_domain:, value:)
Resolv::DNS.open({ nameserver: dns_servers }) do |dns|
dns.timeouts = ENV['a_and_aaaa_validation_timeout'].to_i || 1
ress = nil

case value
when 'A'
ress = dns.getresources email_domain, Resolv::DNS::Resource::IN::A
when 'AAAA'
ress = dns.getresources email_domain, Resolv::DNS::Resource::IN::AAAA
end

ress.map(&:address)
end
end
end
end
12 changes: 6 additions & 6 deletions app/interactions/actions/contact_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def maybe_change_email
return if Rails.env.test?

[:regex, :mx].each do |m|
r = Actions::SimpleMailValidator.run(email: contact.email, level: m)
result = Actions::SimpleMailValidator.run(email: contact.email, level: m)

unless r.success
contact.add_epp_error('2005', nil, r.errors, I18n.t(:parameter_value_syntax_error))
@error = true
return
end
next if result

contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error))
@error = true
return
end

true
Expand Down
11 changes: 5 additions & 6 deletions app/interactions/actions/contact_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ def maybe_change_email
return if Rails.env.test?

[:regex, :mx].each do |m|
r = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m)
result = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m)
next if result

unless r.success
contact.add_epp_error('2005', nil, r.errors, I18n.t(:parameter_value_syntax_error))
@error = true
return
end
contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error))
@error = true
return
end

true
Expand Down
44 changes: 43 additions & 1 deletion app/interactions/actions/email_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,54 @@ def filtering_old_failed_records(result)
end

def save_result(result)
validation_eventable.validation_events.create(validation_event_attrs(result))
if !result.success && @check_level == "mx"
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'A')
output_a_and_aaaa_validation_results(email: @email,
result: result_validation,
type: 'A')

result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'AAAA') if result_validation.empty?
output_a_and_aaaa_validation_results(email: @email,
result: result_validation,
type: 'AAAA')

result_validation.present? ? result.success = true : result.success = false
validation_eventable.validation_events.create(validation_event_attrs(result))
else
validation_eventable.validation_events.create(validation_event_attrs(result))
end
rescue ActiveRecord::RecordNotSaved
logger.info "Cannot save validation result for #{log_object_id}"
true
end

def output_a_and_aaaa_validation_results(email:, result:, type:)
return if Rails.env.test?

logger.info "Validated #{type} record for #{email}. Validation result - #{result}"
end

def check_for_records_value(domain:, value:)
result = nil
dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip)

Resolv::DNS.open({ nameserver: dns_servers }) do |dns|
dns.timeouts = ENV['a_and_aaaa_validation_timeout'].to_i || 1
ress = nil

case value
when 'A'
ress = dns.getresources domain, Resolv::DNS::Resource::IN::A
when 'AAAA'
ress = dns.getresources domain, Resolv::DNS::Resource::IN::AAAA
end

result = ress.map { |r| r.address }
end

result
end

def validation_event_attrs(result)
{
event_data: event_data(result),
Expand Down
32 changes: 31 additions & 1 deletion app/interactions/actions/simple_mail_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,37 @@ module SimpleMailValidator
extend self

def run(email:, level:)
Truemail.validate(email, with: level).result
result = truemail_validate(email: email, level: level)
result = validate_for_a_and_aaaa_records(email) if !result && level == :mx
result
end

def truemail_validate(email:, level:)
Truemail.validate(email, with: level).result.success
end

def validate_for_a_and_aaaa_records(email)
result_validation = Actions::AAndAaaaEmailValidation.call(email: email, value: 'A')
output_a_and_aaaa_validation_results(email: email,
result: result_validation,
type: 'A')

result_validation = Actions::AAndAaaaEmailValidation.call(email: email, value: 'AAAA') if result_validation.empty?
output_a_and_aaaa_validation_results(email: email,
result: result_validation,
type: 'AAAA')

result_validation.present? ? true : false
end

def output_a_and_aaaa_validation_results(email:, result:, type:)
return if Rails.env.test?

logger.info "Validated #{type} record for #{email}. Validation result - #{result}"
end

def logger
@logger ||= Rails.logger
end
end
end
2 changes: 2 additions & 0 deletions app/interactions/domains/force_delete_email/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def execute
Domain.where(registrant_id: registrant_ids)

domains.each do |domain|
next if domain.expired?

before_execute_force_delete(domain)
end
end
Expand Down
10 changes: 10 additions & 0 deletions config/application.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,13 @@ airbrake_host: "https://your-errbit-host.ee"
# airbrake_env: "staging"
airbrake_project_id: "1"
airbrake_project_key: "api_key"

registry_api_url: 'http://registry:3000/api/v1/contact_requests/'
registry_api_key: 'testkey'

registry_demo_registrar_port: '3000'
registry_demo_registrar_results_url: 'http://registry.test/api/v1/accreditation_center/results'
registry_demo_registrar_api_user_url: 'http://registry.test/api/v1/accreditation_center/show_api_user'
registry_demo_accredited_users_url: 'http://registry.test/api/v1/accreditation_center/list_accreditated_api_users'
a_and_aaaa_validation_timeout: '1'

5 changes: 5 additions & 0 deletions config/cable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ production:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: domain_name_registry_production

demo:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: domain_name_registry_demo
4 changes: 4 additions & 0 deletions config/database.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ staging:
<<: *default
database: registry_staging

demo:
<<: *default
database: registry_demo

whois_staging:
<<: *default
database: registry_whois_staging
Expand Down
4 changes: 4 additions & 0 deletions config/database_development.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ whois_test:
api_log_test:
<<: *default
database: registry_api_log_test

demo:
<<: *default
database: registry_demo
7 changes: 7 additions & 0 deletions config/database_registrant.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ production:
host: localhost # registry production mirror location
username: registrant_read_only
password: registrant_read_only_pwd

demo:
<<: *default
database: registry_demo # registry production mirror database name
host: localhost # registry production mirror location
username: registrant_read_only
password: registrant_read_only_pwd
4 changes: 4 additions & 0 deletions config/database_travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ test:
<<: *default
database: registry_test

demo:
<<: *default
database: registry_demo

whois_test:
<<: *default
database: registry_whois_test
Expand Down
Loading

0 comments on commit 03c8737

Please sign in to comment.