diff --git a/Guardfile b/Guardfile index 07e24bf93..31958aa77 100644 --- a/Guardfile +++ b/Guardfile @@ -10,6 +10,7 @@ group :red_green_refactor, halt_on_fail: true do # end 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/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 2d21406af..755501017 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -153,7 +153,7 @@ 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) + @domain = Epp::Domain.where(name: domain_name).first unless @domain epp_errors << { 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/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 diff --git a/app/models/domain.rb b/app/models/domain.rb index 38329506d..0eda82bc1 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -241,39 +241,51 @@ 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 + # rubocop:enable 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) 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/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' 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 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 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 ==