Rubocop upgraded #2711

This commit is contained in:
Priit Tark 2015-06-26 18:19:36 +03:00
parent 59c73fca9e
commit 7530d6ecab
33 changed files with 115 additions and 91 deletions

View file

@ -106,4 +106,12 @@ Style/EmptyLinesAroundBlockBody:
# The ABC size is a calculated magnitude, so this number can be a Fixnum or a Float. # The ABC size is a calculated magnitude, so this number can be a Fixnum or a Float.
Metrics/AbcSize: Metrics/AbcSize:
Max: 25 Max: 35
# Very strange intention requirement, disabled for now
Style/FirstParameterIndentation:
Enabled: false
# old school regex // works fine
Style/RegexpLiteral:
Enabled: false

View file

@ -106,8 +106,8 @@ group :development do
gem 'guard', '~> 2.6.1' # run tests automatically gem 'guard', '~> 2.6.1' # run tests automatically
gem 'guard-rspec', '~> 4.3.1' gem 'guard-rspec', '~> 4.3.1'
gem 'guard-rails', '~> 0.7.0' # run EPP server automatically gem 'guard-rails', '~> 0.7.0' # run EPP server automatically
gem 'rubocop', '~> 0.26.1' gem 'rubocop', '~> 0.32.1'
gem 'guard-rubocop', '~> 1.1.0' gem 'guard-rubocop', '~> 1.2.0'
# improved errors # improved errors
gem 'better_errors', '~> 2.1.1' # webconsole replacement gem 'better_errors', '~> 2.1.1' # webconsole replacement

View file

@ -217,7 +217,7 @@ GEM
guard-rspec (4.3.1) guard-rspec (4.3.1)
guard (~> 2.1) guard (~> 2.1)
rspec (>= 2.14, < 4.0) rspec (>= 2.14, < 4.0)
guard-rubocop (1.1.0) guard-rubocop (1.2.0)
guard (~> 2.0) guard (~> 2.0)
rubocop (~> 0.20) rubocop (~> 0.20)
gyoku (1.3.1) gyoku (1.3.1)
@ -304,7 +304,7 @@ GEM
nprogress-rails (0.1.6.7) nprogress-rails (0.1.6.7)
open4 (1.3.4) open4 (1.3.4)
orm_adapter (0.5.0) orm_adapter (0.5.0)
parser (2.3.0.pre.2) parser (2.2.2.5)
ast (>= 1.1, < 3.0) ast (>= 1.1, < 3.0)
pdfkit (0.6.2) pdfkit (0.6.2)
pg (0.18.2) pg (0.18.2)
@ -318,7 +318,7 @@ GEM
websocket-driver (>= 0.2.0) websocket-driver (>= 0.2.0)
polyamorous (1.2.0) polyamorous (1.2.0)
activerecord (>= 3.0) activerecord (>= 3.0)
powerpack (0.0.9) powerpack (0.1.1)
pry (0.10.1) pry (0.10.1)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
@ -406,10 +406,10 @@ GEM
rspec-mocks (~> 3.0.0) rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0) rspec-support (~> 3.0.0)
rspec-support (3.0.4) rspec-support (3.0.4)
rubocop (0.26.1) rubocop (0.32.1)
astrolabe (~> 1.3) astrolabe (~> 1.3)
parser (>= 2.2.0.pre.4, < 3.0) parser (>= 2.2.2.5, < 3.0)
powerpack (~> 0.0.6) powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0) rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4) ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.5) ruby-progressbar (1.7.5)
@ -546,7 +546,7 @@ DEPENDENCIES
guard (~> 2.6.1) guard (~> 2.6.1)
guard-rails (~> 0.7.0) guard-rails (~> 0.7.0)
guard-rspec (~> 4.3.1) guard-rspec (~> 4.3.1)
guard-rubocop (~> 1.1.0) guard-rubocop (~> 1.2.0)
haml-rails (~> 0.9.0) haml-rails (~> 0.9.0)
hashie-forbidden_attributes (~> 0.1.1) hashie-forbidden_attributes (~> 0.1.1)
html2haml (~> 2.0.0) html2haml (~> 2.0.0)
@ -579,7 +579,7 @@ DEPENDENCIES
rake rake
ransack (~> 1.5.1) ransack (~> 1.5.1)
rspec-rails (~> 3.0.2) rspec-rails (~> 3.0.2)
rubocop (~> 0.26.1) rubocop (~> 0.32.1)
rubycritic (~> 1.1.1) rubycritic (~> 1.1.1)
sass-rails (~> 5.0.3) sass-rails (~> 5.0.3)
sdoc (~> 0.4.0) sdoc (~> 0.4.0)

View file

@ -1,7 +1,6 @@
class Admin::ZonefilesController < ApplicationController class Admin::ZonefilesController < ApplicationController
authorize_resource class: false authorize_resource class: false
# TODO: Refactor this # TODO: Refactor this
# rubocop:disable Metrics/MethodLength
def create def create
if ZonefileSetting.pluck(:origin).include?(params[:origin]) if ZonefileSetting.pluck(:origin).include?(params[:origin])

View file

@ -29,7 +29,6 @@ class Epp::DomainsController < EppController
end end
end end
# rubocop:disable Metrics/CyclomaticComplexity
def update def update
authorize! :update, @domain, @password authorize! :update, @domain, @password
@ -44,7 +43,6 @@ class Epp::DomainsController < EppController
end end
end end
# rubocop:disable Metrics/CyclomaticComplexity
def delete def delete
authorize! :delete, @domain, @password authorize! :delete, @domain, @password
@ -66,7 +64,6 @@ class Epp::DomainsController < EppController
handle_errors(@domain) handle_errors(@domain)
end end
end end
# rubocop:enbale Metrics/CyclomaticComplexity
def check def check
authorize! :check, Epp::Domain authorize! :check, Epp::Domain
@ -88,8 +85,6 @@ class Epp::DomainsController < EppController
render_epp_response '/epp/domains/renew' render_epp_response '/epp/domains/renew'
end end
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/MethodLength
def transfer def transfer
authorize! :transfer, @domain, @password authorize! :transfer, @domain, @password
action = params[:parsed_frame].css('transfer').first[:op] action = params[:parsed_frame].css('transfer').first[:op]
@ -102,8 +97,6 @@ class Epp::DomainsController < EppController
handle_errors(@domain) handle_errors(@domain)
end end
end end
# rubocop: enable Metrics/MethodLength
# rubocop: enable Metrics/CyclomaticComplexity
private private

View file

@ -1,7 +1,6 @@
class Epp::KeyrelaysController < EppController class Epp::KeyrelaysController < EppController
skip_authorization_check # TODO: move authorization under ability skip_authorization_check # TODO: move authorization under ability
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
def keyrelay def keyrelay
# keyrelay temp turned off # keyrelay temp turned off
@ -30,7 +29,6 @@ class Epp::KeyrelaysController < EppController
exactly_one_of 'expiry > relative', 'expiry > absolute' exactly_one_of 'expiry > relative', 'expiry > absolute'
end end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
def find_domain def find_domain

View file

@ -7,6 +7,7 @@ class Epp::SessionsController < EppController
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/AbcSize
def login def login
cert_valid = true cert_valid = true
@api_user = ApiUser.find_by(login_params) @api_user = ApiUser.find_by(login_params)
@ -33,6 +34,9 @@ class Epp::SessionsController < EppController
render_epp_response('login_fail') render_epp_response('login_fail')
end end
end end
# rubocop: enable Metrics/AbcSize
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
def ip_white? def ip_white?
return true if request.ip == ENV['webclient_ip'] return true if request.ip == ENV['webclient_ip']
@ -58,9 +62,6 @@ class Epp::SessionsController < EppController
true true
end end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
def logout def logout
@api_user = current_user # cache current_user for logging @api_user = current_user # cache current_user for logging
epp_session.destroy epp_session.destroy

View file

@ -272,7 +272,6 @@ class EppController < ApplicationController
end end
# rubocop: enable Style/PredicateName # rubocop: enable Style/PredicateName
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
def write_to_epp_log def write_to_epp_log
# return nil if EPP_LOG_ENABLED # return nil if EPP_LOG_ENABLED
@ -295,7 +294,6 @@ class EppController < ApplicationController
ip: request.ip ip: request.ip
}) })
end end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
def iptables_counter_update def iptables_counter_update

View file

@ -9,7 +9,7 @@ class Registrant::DomainDeleteConfirmsController < RegistrantController
end end
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/AbcSize
def update def update
@domain = Domain.find(params[:id]) @domain = Domain.find(params[:id])
unless @domain.registrant_delete_confirmable?(params[:token]) unless @domain.registrant_delete_confirmable?(params[:token])
@ -39,5 +39,5 @@ class Registrant::DomainDeleteConfirmsController < RegistrantController
end end
end end
# rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/AbcSize
end end

View file

@ -9,7 +9,7 @@ class Registrant::DomainUpdateConfirmsController < RegistrantController
end end
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/AbcSize
def update def update
@domain = Domain.find(params[:id]) @domain = Domain.find(params[:id])
unless @domain.registrant_update_confirmable?(params[:token]) unless @domain.registrant_update_confirmable?(params[:token])
@ -39,5 +39,5 @@ class Registrant::DomainUpdateConfirmsController < RegistrantController
end end
end end
# rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/AbcSize
end end

View file

@ -4,6 +4,7 @@ class Registrant::SessionsController < Devise::SessionsController
def login def login
end end
# rubocop: disable Metrics/AbcSize
def id def id
if Rails.env.development? if Rails.env.development?
sign_in(RegistrantUser.find_or_create_by_idc_data('test'), event: :authentication) sign_in(RegistrantUser.find_or_create_by_idc_data('test'), event: :authentication)
@ -22,12 +23,14 @@ class Registrant::SessionsController < Devise::SessionsController
redirect_to registrant_login_url redirect_to registrant_login_url
end end
end end
# rubocop: enable Metrics/AbcSize
def login_mid def login_mid
@user = User.new @user = User.new
end end
def mid # rubocop: disable Metrics/MethodLength # rubocop: disable Metrics/MethodLength
def mid
phone = params[:user][:phone] phone = params[:user][:phone]
endpoint = "#{ENV['sk_digi_doc_service_endpoint']}" endpoint = "#{ENV['sk_digi_doc_service_endpoint']}"
client = Digidoc::Client.new(endpoint) client = Digidoc::Client.new(endpoint)
@ -64,8 +67,9 @@ class Registrant::SessionsController < Devise::SessionsController
render json: { message: t(:no_such_user) }, status: :unauthorized render json: { message: t(:no_such_user) }, status: :unauthorized
end end
end end
# rubocop: enable Metrics/MethodLength
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/AbcSize
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength # rubocop: disable Metrics/MethodLength
def mid_status def mid_status
@ -104,7 +108,7 @@ class Registrant::SessionsController < Devise::SessionsController
render json: { message: t(:internal_error) }, status: :bad_request render json: { message: t(:internal_error) }, status: :bad_request
end end
end end
# rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/AbcSize
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/MethodLength # rubocop: enable Metrics/MethodLength

View file

@ -14,11 +14,9 @@ class Registrar::SessionsController < Devise::SessionsController
# rubocop:disable Metrics/PerceivedComplexity # rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def create def create
@depp_user = Depp::User.new(params[:depp_user].merge( @depp_user = Depp::User.new(params[:depp_user].merge(pki: !(Rails.env.development? || Rails.env.test?)))
pki: !(Rails.env.development? || Rails.env.test?)
)
)
if @depp_user.pki && request.env['HTTP_SSL_CLIENT_S_DN_CN'].blank? if @depp_user.pki && request.env['HTTP_SSL_CLIENT_S_DN_CN'].blank?
@depp_user.errors.add(:base, :webserver_missing_user_name_directive) @depp_user.errors.add(:base, :webserver_missing_user_name_directive)
@ -64,6 +62,7 @@ class Registrar::SessionsController < Devise::SessionsController
# rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity # rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
def id def id
@user = ApiUser.find_by_idc_data(request.env['SSL_CLIENT_S_DN']) @user = ApiUser.find_by_idc_data(request.env['SSL_CLIENT_S_DN'])
@ -121,7 +120,7 @@ class Registrar::SessionsController < Devise::SessionsController
end end
# rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/MethodLength
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/AbcSize
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength # rubocop: disable Metrics/MethodLength
def mid_status def mid_status
@ -159,7 +158,7 @@ class Registrar::SessionsController < Devise::SessionsController
render json: { message: t(:internal_error) }, status: :bad_request render json: { message: t(:internal_error) }, status: :bad_request
end end
end end
# rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/AbcSize
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/MethodLength # rubocop: enable Metrics/MethodLength

View file

@ -3,6 +3,7 @@ class Ability
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/LineLength # rubocop: disable Metrics/LineLength
# rubocop: disable Metrics/AbcSize
def initialize(user) def initialize(user)
alias_action :show, to: :view alias_action :show, to: :view
alias_action :show, :create, :update, :destroy, to: :crud alias_action :show, :create, :update, :destroy, to: :crud

View file

@ -1,9 +1,9 @@
require 'open3' require 'open3'
# rubocop: disable Metrics/ClassLength
class ApiUser < User class ApiUser < User
include EppErrors include EppErrors
def epp_code_map # rubocop:disable Metrics/MethodLength
def epp_code_map
{ {
'2306' => [ # Parameter policy error '2306' => [ # Parameter policy error
[:password, :blank] [:password, :blank]
@ -77,4 +77,3 @@ class ApiUser < User
end end
end end
end end
# rubocop: enable Metrics/ClassLength

View file

@ -27,6 +27,7 @@ class BankStatement < ActiveRecord::Base
File.open(import_file_path, 'w') { |f| f.write(th6_file.open.read) } File.open(import_file_path, 'w') { |f| f.write(th6_file.open.read) }
end end
# rubocop: disable Metrics/AbcSize
def parse_th6_row(row) def parse_th6_row(row)
return parse_th6_header(row) if row[4, 3].strip == '000' return parse_th6_header(row) if row[4, 3].strip == '000'
return if row[4, 3].strip == '999' # skip footer return if row[4, 3].strip == '999' # skip footer
@ -47,6 +48,7 @@ class BankStatement < ActiveRecord::Base
reference_no: row[280, 35].strip reference_no: row[280, 35].strip
} }
end end
# rubocop: enable Metrics/AbcSize
def parse_th6_header(row) def parse_th6_header(row)
self.bank_code = row[7, 3].strip self.bank_code = row[7, 3].strip

View file

@ -76,6 +76,7 @@ class Certificate < ActiveRecord::Base
@cached_status = REVOKED @cached_status = REVOKED
end end
# rubocop: disable Metrics/AbcSize
def sign! def sign!
csr_file = Tempfile.new('client_csr') csr_file = Tempfile.new('client_csr')
csr_file.write(csr) csr_file.write(csr)
@ -107,6 +108,7 @@ class Certificate < ActiveRecord::Base
return false return false
end end
end end
# rubocop: enable Metrics/AbcSize
def revoke! def revoke!
crt_file = Tempfile.new('client_crt') crt_file = Tempfile.new('client_crt')

View file

@ -20,7 +20,6 @@ module Depp
class << self class << self
attr_reader :epp_xml, :user attr_reader :epp_xml, :user
# rubocop: disable Metrics/MethodLength
def new_from_params(params) def new_from_params(params)
new( new(
id: params[:code], id: params[:code],
@ -43,8 +42,8 @@ module Depp
country_code: params[:country_code] country_code: params[:country_code]
) )
end end
# rubocop: enable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def find_by_id(id) def find_by_id(id)
data = info_xml(id) data = info_xml(id)
@ -77,6 +76,7 @@ module Depp
statuses: data.css('status').map { |s| [s['s'], s.text] } statuses: data.css('status').map { |s| [s['s'], s.text] }
) )
end end
# rubocop:enable Metrics/AbcSize
def user=(user) def user=(user)
@user = user @user = user
@ -171,6 +171,7 @@ module Depp
end end
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def update_attributes(params) def update_attributes(params)
self.ident_country_code = params[:ident_country_code] self.ident_country_code = params[:ident_country_code]
self.ident_type = params[:ident_type] self.ident_type = params[:ident_type]
@ -214,6 +215,7 @@ module Depp
data = Depp::Contact.user.request(update_xml) data = Depp::Contact.user.request(update_xml)
handle_errors(data) handle_errors(data)
end end
# rubocop:enbale Metrics/AbcSize
# rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/MethodLength
def delete def delete

View file

@ -130,7 +130,9 @@ module Depp
ret.with_indifferent_access ret.with_indifferent_access
end end
def construct_params_from_server_data(data) # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def construct_params_from_server_data(data)
ret = default_params ret = default_params
ret[:name] = data.css('name').text ret[:name] = data.css('name').text
ret[:registrant] = data.css('registrant').text ret[:registrant] = data.css('registrant').text
@ -176,6 +178,8 @@ module Depp
ret ret
end end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
def construct_custom_params_hash(domain_params) def construct_custom_params_hash(domain_params)
custom_params = {} custom_params = {}

View file

@ -8,7 +8,7 @@ module Depp
self.epp_xml = EppXml::Keyrelay.new(cl_trid_prefix: current_user.tag) self.epp_xml = EppXml::Keyrelay.new(cl_trid_prefix: current_user.tag)
end end
def keyrelay(params) # rubocop:disable Metrics/MethodLength def keyrelay(params)
custom_params = {} custom_params = {}
if params[:legal_document].present? if params[:legal_document].present?
type = params[:legal_document].original_filename.split('.').last.downcase type = params[:legal_document].original_filename.split('.').last.downcase

View file

@ -36,6 +36,7 @@ module Depp
Nokogiri::XML(e.response_xml.to_s).remove_namespaces! Nokogiri::XML(e.response_xml.to_s).remove_namespaces!
end end
# rubocop:disable Metrics/AbcSize
def repp_request(path, params = {}) def repp_request(path, params = {})
client_cert = File.read(ENV['cert_path']) client_cert = File.read(ENV['cert_path'])
client_key = File.read(ENV['key_path']) client_key = File.read(ENV['key_path'])
@ -51,8 +52,7 @@ module Depp
use_ssl: (uri.scheme == 'https'), use_ssl: (uri.scheme == 'https'),
verify_mode: OpenSSL::SSL::VERIFY_NONE, verify_mode: OpenSSL::SSL::VERIFY_NONE,
cert: OpenSSL::X509::Certificate.new(client_cert), cert: OpenSSL::X509::Certificate.new(client_cert),
key: OpenSSL::PKey::RSA.new(client_key) key: OpenSSL::PKey::RSA.new(client_key)) do |http|
) do |http|
http.request(req) http.request(req)
end end
@ -67,6 +67,7 @@ module Depp
ret ret
end end
# rubocop:enable Metrics/AbcSize
private private

View file

@ -114,7 +114,7 @@ class Dnskey < ActiveRecord::Base
end end
def bin_to_hex(s) def bin_to_hex(s)
s.each_byte.map { |b| sprintf('%02X', b) }.join s.each_byte.map { |b| format('%02X', b) }.join
end end
end end
end end

View file

@ -207,6 +207,7 @@ class Domain < ActiveRecord::Base
STDOUT << "#{Time.zone.now.utc} - Successfully set delete_candidate to #{d.count} domains\n" STDOUT << "#{Time.zone.now.utc} - Successfully set delete_candidate to #{d.count} domains\n"
end end
# rubocop:disable Rails/FindEach
def destroy_delete_candidates def destroy_delete_candidates
STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test? STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test?
@ -223,6 +224,7 @@ class Domain < ActiveRecord::Base
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test? STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test?
end end
# rubocop:enable Rails/FindEach
end end
def name=(value) def name=(value)
@ -410,8 +412,8 @@ class Domain < ActiveRecord::Base
res = '' res = ''
parts = name.split('.') parts = name.split('.')
parts.each do |x| parts.each do |x|
res += sprintf('%02X', x.length) # length of label in hex res += format('%02X', x.length) # length of label in hex
res += x.each_byte.map { |b| sprintf('%02X', b) }.join # label res += x.each_byte.map { |b| format('%02X', b) }.join # label
end end
res += '00' res += '00'

View file

@ -1,4 +1,3 @@
# rubocop: disable Metrics/ClassLength
class Epp::Contact < Contact class Epp::Contact < Contact
include EppErrors include EppErrors
@ -15,6 +14,7 @@ class Epp::Contact < Contact
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength # rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/AbcSize
def attrs_from(frame, rem = nil) def attrs_from(frame, rem = nil)
f = frame f = frame
at = {}.with_indifferent_access at = {}.with_indifferent_access
@ -53,6 +53,7 @@ class Epp::Contact < Contact
# rubocop: enable Metrics/MethodLength # rubocop: enable Metrics/MethodLength
# rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/AbcSize
def new(frame, registrar) def new(frame, registrar)
return super if frame.blank? return super if frame.blank?
@ -149,4 +150,3 @@ class Epp::Contact < Contact
super(at) super(at)
end end
end end
# rubocop: enable Metrics/ClassLength

View file

@ -88,6 +88,7 @@ class Epp::Domain < Domain
# rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength # rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/AbcSize
def attrs_from(frame, current_user, action = nil) def attrs_from(frame, current_user, action = nil)
at = {}.with_indifferent_access at = {}.with_indifferent_access
@ -130,6 +131,7 @@ class Epp::Domain < Domain
# rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
# rubocop: enable Metrics/MethodLength # rubocop: enable Metrics/MethodLength
# rubocop: enable Metrics/AbcSize
def nameservers_attrs(frame, action) def nameservers_attrs(frame, action)
ns_list = nameservers_from(frame) ns_list = nameservers_from(frame)
@ -358,6 +360,7 @@ class Epp::Domain < Domain
}] }]
end end
# rubocop: disable Metrics/AbcSize
def update(frame, current_user, verify = true) def update(frame, current_user, verify = true)
return super if frame.blank? return super if frame.blank?
at = {}.with_indifferent_access at = {}.with_indifferent_access
@ -380,6 +383,7 @@ class Epp::Domain < Domain
self.deliver_emails = true # turn on email delivery for epp self.deliver_emails = true # turn on email delivery for epp
errors.empty? && super(at) errors.empty? && super(at)
end end
# rubocop: enable Metrics/AbcSize
def apply_pending_update! def apply_pending_update!
preclean_pendings preclean_pendings
@ -524,6 +528,7 @@ class Epp::Domain < Domain
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength # rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/AbcSize
def query_transfer(frame, current_user) def query_transfer(frame, current_user)
return false unless can_be_transferred_to?(current_user.registrar) return false unless can_be_transferred_to?(current_user.registrar)
@ -565,6 +570,7 @@ class Epp::Domain < Domain
end end
end end
end end
# rubocop: enable Metrics/AbcSize
# rubocop: enable Metrics/MethodLength # rubocop: enable Metrics/MethodLength
def approve_transfer(frame, current_user) def approve_transfer(frame, current_user)
@ -621,13 +627,14 @@ class Epp::Domain < Domain
end end
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def keyrelay(parsed_frame, requester) def keyrelay(parsed_frame, requester)
if registrar == requester if registrar == requester
errors.add(:base, :domain_already_belongs_to_the_querying_registrar) and return false errors.add(:base, :domain_already_belongs_to_the_querying_registrar) and return false
end end
abs_datetime = parsed_frame.css('absolute').text abs_datetime = parsed_frame.css('absolute').text
abs_datetime = DateTime.parse(abs_datetime) if abs_datetime.present? abs_datetime = DateTime.zone.parse(abs_datetime) if abs_datetime.present?
transaction do transaction do
kr = keyrelays.build( kr = keyrelays.build(
@ -664,6 +671,7 @@ class Epp::Domain < Domain
true true
end end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/MethodLength
### VALIDATIONS ### ### VALIDATIONS ###

View file

@ -47,8 +47,7 @@ class Nameserver < ActiveRecord::Base
def replace_hostname_ends(domains, old_end, new_end) def replace_hostname_ends(domains, old_end, new_end)
domains = domains.where('EXISTS( domains = domains.where('EXISTS(
select 1 from nameservers ns where ns.domain_id = domains.id AND ns.hostname LIKE ? select 1 from nameservers ns where ns.domain_id = domains.id AND ns.hostname LIKE ?
)', "%#{old_end}" )', "%#{old_end}")
)
count, success_count = 0.0, 0.0 count, success_count = 0.0, 0.0
domains.each do |d| domains.each do |d|

View file

@ -73,7 +73,9 @@ class Registrar < ActiveRecord::Base
end end
end end
def issue_prepayment_invoice(amount, description = nil) # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def issue_prepayment_invoice(amount, description = nil)
# Currently only EIS can issue invoices # Currently only EIS can issue invoices
eis = self.class.eis eis = self.class.eis
@ -122,6 +124,8 @@ class Registrar < ActiveRecord::Base
] ]
) )
end end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
def cash_account def cash_account
accounts.find_by(account_type: Account::CASH) accounts.find_by(account_type: Account::CASH)

View file

@ -30,6 +30,7 @@ class WhoisRecord < ActiveRecord::Base
end end
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def generate_json def generate_json
h = HashWithIndifferentAccess.new h = HashWithIndifferentAccess.new
return h if domain.blank? return h if domain.blank?
@ -108,6 +109,7 @@ More information at http://internet.ee
EOS EOS
end end
# rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
def contacts_body(admins, techs) def contacts_body(admins, techs)
admins ||= [] admins ||= []

View file

@ -9,7 +9,7 @@ class DateTimeIso8601Validator < ActiveModel::EachValidator
return true if value.empty? return true if value.empty?
begin begin
DateTime.parse(value) DateTime.zone.parse(value)
rescue => _e rescue => _e
return false return false
end end

View file

@ -1,7 +1,7 @@
class ObjectCountValidator < ActiveModel::EachValidator class ObjectCountValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
min, max = options[:min].call, options[:max].call min, max = options[:min].call, options[:max].call
return if value.reject(&:marked_for_destruction?).length.between?(min, max) return if value.count { |i| !i.marked_for_destruction? }.between?(min, max)
association = options[:association] || attribute association = options[:association] || attribute
record.errors.add(association, :out_of_range, { min: min, max: max }) record.errors.add(association, :out_of_range, { min: min, max: max })
end end

View file

@ -151,7 +151,7 @@ describe 'EPP Contact', epp: true do
id.text.length.should == 15 id.text.length.should == 15
# 5 seconds for what-ever weird lag reasons might happen # 5 seconds for what-ever weird lag reasons might happen
cr_date.text.to_time.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 add registrar prefix for code when missing' do it 'should add registrar prefix for code when missing' do

View file

@ -89,8 +89,8 @@ describe 'EPP Domain', epp: true do
cre_data = response[:parsed].css('creData') cre_data = response[:parsed].css('creData')
cre_data.css('name').text.should == dn cre_data.css('name').text.should == dn
cre_data.css('crDate').text.should == d.created_at.to_time.utc.iso8601 cre_data.css('crDate').text.should == d.created_at.in_time_zone.utc.utc.iso8601
cre_data.css('exDate').text.should == d.valid_to.to_time.utc.iso8601 cre_data.css('exDate').text.should == d.valid_to.in_time_zone.utc.utc.iso8601
response[:clTRID].should == 'ABC-12345' response[:clTRID].should == 'ABC-12345'
@ -746,10 +746,10 @@ describe 'EPP Domain', epp: true do
trn_data.css('name').text.should == domain.name trn_data.css('name').text.should == domain.name
trn_data.css('trStatus').text.should == 'serverApproved' trn_data.css('trStatus').text.should == 'serverApproved'
trn_data.css('reID').text.should == 'REGDOMAIN2' trn_data.css('reID').text.should == 'REGDOMAIN2'
trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.iso8601 trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601
trn_data.css('acID').text.should == 'REGDOMAIN1' trn_data.css('acID').text.should == 'REGDOMAIN1'
trn_data.css('acDate').text.should == dtl.transferred_at.to_time.utc.iso8601 trn_data.css('acDate').text.should == dtl.transferred_at.in_time_zone.utc.utc.iso8601
trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.iso8601 trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601
domain.registrar.should == @registrar2 domain.registrar.should == @registrar2
@ -791,10 +791,10 @@ describe 'EPP Domain', epp: true do
trn_data.css('name').text.should == domain.name trn_data.css('name').text.should == domain.name
trn_data.css('trStatus').text.should == 'pending' trn_data.css('trStatus').text.should == 'pending'
trn_data.css('reID').text.should == 'REGDOMAIN1' trn_data.css('reID').text.should == 'REGDOMAIN1'
trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.iso8601 trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601
trn_data.css('acDate').text.should == dtl.wait_until.to_time.utc.iso8601 trn_data.css('acDate').text.should == dtl.wait_until.in_time_zone.utc.utc.iso8601
trn_data.css('acID').text.should == 'REGDOMAIN2' trn_data.css('acID').text.should == 'REGDOMAIN2'
trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.iso8601 trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601
domain.registrar.should == @registrar2 domain.registrar.should == @registrar2
@ -806,10 +806,10 @@ describe 'EPP Domain', epp: true do
trn_data.css('name').text.should == domain.name trn_data.css('name').text.should == domain.name
trn_data.css('trStatus').text.should == 'pending' trn_data.css('trStatus').text.should == 'pending'
trn_data.css('reID').text.should == 'REGDOMAIN1' trn_data.css('reID').text.should == 'REGDOMAIN1'
trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.iso8601 trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601
trn_data.css('acDate').text.should == dtl.wait_until.to_time.utc.iso8601 trn_data.css('acDate').text.should == dtl.wait_until.in_time_zone.utc.utc.iso8601
trn_data.css('acID').text.should == 'REGDOMAIN2' trn_data.css('acID').text.should == 'REGDOMAIN2'
trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.iso8601 trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601
domain.registrar.should == @registrar2 domain.registrar.should == @registrar2
@ -1213,9 +1213,9 @@ describe 'EPP Domain', epp: true do
trn_data.css('name').text.should == domain.name trn_data.css('name').text.should == domain.name
trn_data.css('trStatus').text.should == 'clientApproved' trn_data.css('trStatus').text.should == 'clientApproved'
trn_data.css('reID').text.should == 'REGDOMAIN2' trn_data.css('reID').text.should == 'REGDOMAIN2'
trn_data.css('reDate').text.should == dtl.transfer_requested_at.to_time.utc.iso8601 trn_data.css('reDate').text.should == dtl.transfer_requested_at.in_time_zone.utc.utc.iso8601
trn_data.css('acID').text.should == 'REGDOMAIN1' trn_data.css('acID').text.should == 'REGDOMAIN1'
trn_data.css('exDate').text.should == domain.valid_to.to_time.utc.iso8601 trn_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601
end end
it 'rejects a domain transfer' do it 'rejects a domain transfer' do
@ -2187,8 +2187,8 @@ describe 'EPP Domain', epp: true do
ns1.css('hostName').last.text.should == 'ns1.example.com' ns1.css('hostName').last.text.should == 'ns1.example.com'
ns1.css('hostAddr').first.text.should == '192.168.1.1' ns1.css('hostAddr').first.text.should == '192.168.1.1'
ns1.css('hostAddr').last.text.should == '1080:0:0:0:8:800:200C:417A' ns1.css('hostAddr').last.text.should == '1080:0:0:0:8:800:200C:417A'
inf_data.css('crDate').text.should == domain.created_at.to_time.utc.iso8601 inf_data.css('crDate').text.should == domain.created_at.in_time_zone.utc.utc.iso8601
inf_data.css('exDate').text.should == domain.valid_to.to_time.utc.iso8601 inf_data.css('exDate').text.should == domain.valid_to.in_time_zone.utc.utc.iso8601
inf_data.css('pw').text.should == domain.auth_info inf_data.css('pw').text.should == domain.auth_info
ds_data_1 = response[:parsed].css('dsData')[0] ds_data_1 = response[:parsed].css('dsData')[0]
@ -2217,7 +2217,7 @@ describe 'EPP Domain', epp: true do
response = epp_plain_request(domain_info_xml(name: { value: domain.name })) response = epp_plain_request(domain_info_xml(name: { value: domain.name }))
inf_data = response[:parsed].css('resData infData') inf_data = response[:parsed].css('resData infData')
inf_data.css('upDate').text.should == domain.updated_at.to_time.utc.iso8601 inf_data.css('upDate').text.should == domain.updated_at.in_time_zone.utc.utc.iso8601
end end
it 'returns domain info with different nameservers' do it 'returns domain info with different nameservers' do

View file

@ -33,7 +33,6 @@ end
module Autodoc module Autodoc
class Document class Document
# rubocop:disable Metrics/AbcSize
def route_info_doc def route_info_doc
return unless example.metadata[:route_info_doc] return unless example.metadata[:route_info_doc]
route = request.env["rack.routing_args"][:route_info] route = request.env["rack.routing_args"][:route_info]
@ -57,7 +56,6 @@ module Autodoc
pretty_table(rows).join("\n") pretty_table(rows).join("\n")
end end
# rubocop:enable Metrics/AbcSize
def pretty_table(rows) def pretty_table(rows)
# longest_in_col = 0 # longest_in_col = 0