From 8a4519d83e9544b006df49e3a1bbec7504f63ae2 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 14:45:56 +0200 Subject: [PATCH 1/8] domain bullet updated --- app/controllers/epp/domains_controller.rb | 6 ++- app/models/domain.rb | 64 ++++++++++++++--------- config/environments/test.rb | 1 + 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 2d21406af..ca6432dde 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -153,7 +153,11 @@ class Epp::DomainsController < EppController def find_domain domain_name = params[:parsed_frame].css('name').text.strip.downcase - @domain = Epp::Domain.find_by(name: domain_name) + if params[:action] == 'transfer' + @domain = Epp::Domain.includes(:registrar).where(name: domain_name).first + else + @domain = Epp::Domain.where(name: domain_name).first + end unless @domain epp_errors << { diff --git a/app/models/domain.rb b/app/models/domain.rb index 38329506d..c7d4ff193 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -241,40 +241,52 @@ class Domain < ActiveRecord::Base # rubocop:disable Metrics/MethodLength def update_whois_body self.whois_body = <<-EOS - This Whois Server contains information on - Estonian Top Level Domain ee TLD + This Whois Server contains information on + Estonian Top Level Domain ee TLD - domain: #{name} - registrar: #{registrar} - status: - registered: - changed: #{updated_at.to_s(:db)} - expire: - outzone: - delete: + domain: #{name} + registrar: #{registrar} + status: + registered: #{registered_at and registered_at.to_s(:db)} + changed: #{updated_at and updated_at.to_s(:db)} + expire: + outzone: + delete: - contact - name: - e-mail: - registrar: - created: + #{contacts_body} - contact: + nsset: + nserver: - nsset: - nserver: - - registrar: - org: - url: - phone: - address: - created: - changed: + registrar: #{registrar} + phone: #{registrar.phone} + address: #{registrar.address} + created: #{registrar.created_at.to_s(:db)} + changed: #{registrar.updated_at.to_s(:db)} EOS end # rubocop:enabled Metrics/MethodLength + def contacts_body + out = '' + admin_contacts.includes(:registrar).each do |c| + out << 'Admin contact:' + out << "name: #{c.name}" + out << "email: #{c.email}" + out << "registrar: #{c.registrar}" + out << "created: #{c.created_at.to_s(:db)}" + end + + tech_contacts.includes(:registrar).each do |c| + out << 'Tech contact:' + out << "name: #{c.name}" + out << "email: #{c.email}" + out << "registrar: #{c.registrar}" + out << "created: #{c.created_at.to_s(:db)}" + end + out + end + def whois_server_update(name, whois_body) wd = Whois::Domain.find_or_initialize_by(name: name) wd.whois_body = whois_body diff --git a/config/environments/test.rb b/config/environments/test.rb index d7db4fa70..471028f30 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -49,5 +49,6 @@ Rails.application.configure do Bullet.enable = true Bullet.bullet_logger = true Bullet.raise = true # raise an error if n+1 query occurs + # Bullet.unused_eager_loading_enable = false end end From d66001f8d9bda0619905af7a02d478b55c2a2761 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 14:50:40 +0200 Subject: [PATCH 2/8] Load zone file sql function --- lib/tasks/db.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 444acbab6..aa06aa273 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -25,6 +25,7 @@ namespace :db do puts "\n---------------------------- Import seed ----------------------------------------\n" Rake::Task['db:seed'].invoke + Rake::Task['zonefile:replace_procedure'].invoke puts "\n All done!\n\n" end From 45ab4ce2fafd597c3ca69a8070a9cbc27bd827fb Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 14:59:38 +0200 Subject: [PATCH 3/8] added webclient_cert_common_name --- Guardfile | 3 ++- app/api/repp/api.rb | 9 +++++++-- config/application-example.yml | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Guardfile b/Guardfile index 07e24bf93..ab7619ed7 100644 --- a/Guardfile +++ b/Guardfile @@ -9,7 +9,8 @@ group :red_green_refactor, halt_on_fail: true do # watch(%r{^(config|lib)/.*}) # end - guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do + # guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do + guard :rspec, cmd: 'spring rspec', notification: false do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } diff --git a/app/api/repp/api.rb b/app/api/repp/api.rb index df49bdf52..be22676e4 100644 --- a/app/api/repp/api.rb +++ b/app/api/repp/api.rb @@ -8,10 +8,15 @@ module Repp end before do + next if Rails.env.test? + message = 'Certificate mismatch! Cert common name should be:' + request_name = ENV['HTTP_SSL_CLIENT_S_DN_CN'] + if request.ip == ENV['webclient_ip'] - error! 'Certificate mismatch', 401 if env['HTTP_SSL_CLIENT_S_DN_CN'] != 'webclient' + webclient_cert_name = ENV['webclient_cert_common_name'] || 'webclient' + error! "#{message} #{webclient_cert_name}", 401 if webclient_cert_name != request_name else - error! 'Certificate mismatch', 401 if env['HTTP_SSL_CLIENT_S_DN_CN'] != @current_user.username + error! "#{message} #{@current_user.username}", 401 if @current_user.username != request_name end end diff --git a/config/application-example.yml b/config/application-example.yml index 8576d54ec..32d56ca5c 100644 --- a/config/application-example.yml +++ b/config/application-example.yml @@ -22,6 +22,7 @@ ca_key_password: 'your-root-key-password' # Used only by EPP server, you can leave it empty when running admin server: webclient_ip: '127.0.0.1' +webclient_cert_common_name: 'webclient' # DEPP configuration show_ds_data_fields: 'false' From f146bca5c74c59b1d332fcf53db800eb6a28f37e Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 15:01:51 +0200 Subject: [PATCH 4/8] replaced STDOUT with logger.info --- app/models/contact.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 0035965b7..48b4f35ac 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -174,9 +174,9 @@ class Contact < ActiveRecord::Base end def destroy_orphans - STDOUT << "#{Time.now.utc} - Destroying orphaned contacts\n" + logger.info "#{Time.now.utc} - Destroying orphaned contacts\n" count = find_orphans.destroy_all.count - STDOUT << "#{Time.now.utc} - Successfully destroyed #{count} orphaned contacts\n" + logger.info "#{Time.now.utc} - Successfully destroyed #{count} orphaned contacts\n" end end end From 0e3382f3484af6994e801d45069bcb8b04f19dea Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 15:13:06 +0200 Subject: [PATCH 5/8] Added test debugger for test signing --- app/models/certificate.rb | 3 +++ app/models/domain.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/certificate.rb b/app/models/certificate.rb index 072d98076..9a0cab4a1 100644 --- a/app/models/certificate.rb +++ b/app/models/certificate.rb @@ -58,6 +58,9 @@ class Certificate < ActiveRecord::Base errors.add(:base, I18n.t('failed_to_create_certificate')) logger.error('FAILED TO CREATE CLIENT CERTIFICATE') logger.error(err) + # rubocop:disable Rails/Output + puts "Certificate sign issue: #{err.inspect}" if Rails.env.test? + # rubocop:enable Rails/Output return false end end diff --git a/app/models/domain.rb b/app/models/domain.rb index c7d4ff193..0eda82bc1 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -265,7 +265,7 @@ class Domain < ActiveRecord::Base changed: #{registrar.updated_at.to_s(:db)} EOS end - # rubocop:enabled Metrics/MethodLength + # rubocop:enable Metrics/MethodLength def contacts_body out = '' From 311a2a4f2e770cd29d721bb255f3c51a0e71374f Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 15:22:32 +0200 Subject: [PATCH 6/8] Remove unneeded optimization --- app/controllers/epp/domains_controller.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index ca6432dde..755501017 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -153,11 +153,7 @@ class Epp::DomainsController < EppController def find_domain domain_name = params[:parsed_frame].css('name').text.strip.downcase - if params[:action] == 'transfer' - @domain = Epp::Domain.includes(:registrar).where(name: domain_name).first - else - @domain = Epp::Domain.where(name: domain_name).first - end + @domain = Epp::Domain.where(name: domain_name).first unless @domain epp_errors << { From c898ad57f5a900043306f9f19650f7ffe8324754 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 15:24:09 +0200 Subject: [PATCH 7/8] Fail fast in guard --- Guardfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Guardfile b/Guardfile index ab7619ed7..31958aa77 100644 --- a/Guardfile +++ b/Guardfile @@ -9,8 +9,8 @@ group :red_green_refactor, halt_on_fail: true do # watch(%r{^(config|lib)/.*}) # end - # guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do - guard :rspec, cmd: 'spring rspec', notification: false do + guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do + # guard :rspec, cmd: 'spring rspec', notification: false do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } From 251231cf3fa34016981fa1b32a03f16961184e9d Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 27 Mar 2015 15:37:39 +0200 Subject: [PATCH 8/8] contact generates code if custom code is empty --- app/models/epp/contact.rb | 2 +- spec/epp/contact_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 0f51b02c0..0bcc0cf2c 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -42,7 +42,7 @@ class Epp::Contact < Contact return super if frame.blank? custom_code = - if frame.css('id').present? + if frame.css('id').text.present? "#{registrar.code}:#{frame.css('id').text.parameterize}" else nil diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index ca5edd28f..7a2c26239 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -145,6 +145,24 @@ describe 'EPP Contact', epp: true do Contact.last.code.should == 'registrar1:12345' end + it 'should generate server id when id is empty' do + response = create_request({ id: { value: '' } }) + + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + + Contact.last.code.should_not == 'registrar1:' + end + + it 'should generate server id when id is empty' do + response = create_request + + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + + Contact.last.code.should_not == 'registrar1:' + end + it 'should return parameter value policy error for org' do response = create_request({ postalInfo: { org: { value: 'should not save' } } }) response[:msg].should ==