Rubocop autocorrect

This commit is contained in:
Martin Lensment 2014-08-25 14:14:25 +03:00
parent f8c48a7456
commit 6c5c0b38c8
59 changed files with 533 additions and 546 deletions

View file

@ -1,11 +1,20 @@
Style/LineLength: AllCops:
RunRailsCops: true
Metrics/LineLength:
Max: 120 Max: 120
Documentation: Documentation:
Enabled: false Enabled: false
Style/CyclomaticComplexity:
Severity: warning
Style/Semicolon: Style/Semicolon:
AllowAsExpressionSeparator: true AllowAsExpressionSeparator: true
Style/AndOr:
Enabled: false
Style/BracesAroundHashParameters:
Enabled: false
Style/IndentHash:
Enabled: false

View file

@ -37,7 +37,7 @@ gem 'nokogiri', '~> 1.6.2.1'
# For punycode # For punycode
gem 'simpleidn', '~> 0.0.5' gem 'simpleidn', '~> 0.0.5'
#for EE-id validation # for EE-id validation
gem 'isikukood' gem 'isikukood'
gem 'bootstrap-sass', '~> 3.2.0.1' gem 'bootstrap-sass', '~> 3.2.0.1'

View file

@ -12,7 +12,7 @@ module Epp::Common
end end
def proxy def proxy
@svTRID = "ccReg-#{'%010d' % rand(10 ** 10)}" @svTRID = "ccReg-#{'%010d' % rand(10**10)}"
send(params[:command]) send(params[:command])
end end
@ -36,7 +36,7 @@ module Epp::Common
@current_epp_user ||= EppUser.find(epp_session[:epp_user_id]) if epp_session[:epp_user_id] @current_epp_user ||= EppUser.find(epp_session[:epp_user_id]) if epp_session[:epp_user_id]
end end
def handle_errors(obj=nil) def handle_errors(obj = nil)
@errors ||= [] @errors ||= []
if obj if obj
obj.construct_epp_errors obj.construct_epp_errors
@ -44,7 +44,7 @@ module Epp::Common
end end
# for debugging # for debugging
@errors << {code: '1', msg: 'handle_errors was executed when there were actually no errors'} if @errors.blank? @errors << { code: '1', msg: 'handle_errors was executed when there were actually no errors' } if @errors.blank?
render '/epp/error' render '/epp/error'
end end
@ -55,13 +55,13 @@ module Epp::Common
def xml_attrs_present?(ph, attributes) def xml_attrs_present?(ph, attributes)
attributes.each do |x| attributes.each do |x|
epp_errors << {code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: x.last)} unless has_attribute(ph, x) epp_errors << { code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: x.last) } unless has_attribute(ph, x)
end end
epp_errors.empty? epp_errors.empty?
end end
def has_attribute(ph, path) def has_attribute(ph, path)
path.inject(ph) do |location, key| path.reduce(ph) do |location, key|
location.respond_to?(:keys) ? location[key] : nil location.respond_to?(:keys) ? location[key] : nil
end end
end end

View file

@ -1,8 +1,8 @@
module Shared::UserStamper module Shared::UserStamper
extend ActiveSupport::Concern extend ActiveSupport::Concern
def stamp obj def stamp(obj)
return false if obj.nil? || !obj.has_attribute?( :created_by_id && :updated_by_id ) return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
if obj.new_record? if obj.new_record?
obj.created_by_id = current_epp_user.id obj.created_by_id = current_epp_user.id
@ -10,6 +10,6 @@ module Shared::UserStamper
obj.updated_by_id = current_epp_user.id obj.updated_by_id = current_epp_user.id
end end
return true true
end end
end end

View file

@ -5,6 +5,7 @@ class Epp::CommandsController < ApplicationController
include Shared::UserStamper include Shared::UserStamper
private private
def create def create
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}") send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
end end

View file

@ -2,7 +2,7 @@ class Epp::ErrorsController < ApplicationController
include Epp::Common include Epp::Common
def error def error
epp_errors << {code: params[:code], msg: params[:msg]} epp_errors << { code: params[:code], msg: params[:msg] }
render '/epp/error' render '/epp/error'
end end
end end

View file

@ -2,6 +2,7 @@ class Epp::SessionsController < ApplicationController
include Epp::Common include Epp::Common
private private
def hello def hello
render 'greeting' render 'greeting'
end end

View file

@ -16,11 +16,12 @@ class SettingGroupsController < ApplicationController
end end
private private
def set_setting_group def set_setting_group
@setting_group = SettingGroup.find(params[:id]) @setting_group = SettingGroup.find(params[:id])
end end
def setting_group_params def setting_group_params
params.require(:setting_group).permit(settings_attributes: [ :value, :id ]) params.require(:setting_group).permit(settings_attributes: [:value, :id])
end end
end end

View file

@ -1,6 +1,6 @@
module Epp::ContactsHelper module Epp::ContactsHelper
def create_contact def create_contact
@contact = Contact.new( contact_and_address_attributes ) @contact = Contact.new(contact_and_address_attributes)
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact) handle_errors(@contact)
@ -29,7 +29,7 @@ module Epp::ContactsHelper
def check_contact def check_contact
ph = params_hash['epp']['command']['check']['check'] ph = params_hash['epp']['command']['check']['check']
@contacts = Contact.check_availability( ph[:id] ) @contacts = Contact.check_availability(ph[:id])
render '/epp/contacts/check' render '/epp/contacts/check'
end end
@ -41,40 +41,41 @@ module Epp::ContactsHelper
end end
## HELPER METHODS ## HELPER METHODS
private private
## CREATE ## CREATE
def validate_contact_create_request def validate_contact_create_request
@ph = params_hash['epp']['command']['create']['create'] @ph = params_hash['epp']['command']['create']['create']
xml_attrs_present?(@ph, [['id'], xml_attrs_present?(@ph, [['id'],
['authInfo', 'pw'], %w(authInfo pw),
['postalInfo', 'name'], %w(postalInfo name),
['postalInfo', 'addr', 'city'], %w(postalInfo addr city),
['postalInfo', 'addr', 'cc']]) %w(postalInfo addr cc)])
end end
## UPDATE ## UPDATE
def validate_contact_update_request def validate_contact_update_request
@ph = params_hash['epp']['command']['update']['update'] @ph = params_hash['epp']['command']['update']['update']
xml_attrs_present?(@ph, [['id'] ]) xml_attrs_present?(@ph, [['id']])
end end
## DELETE ## DELETE
def validate_contact_delete_request def validate_contact_delete_request
@ph = params_hash['epp']['command']['delete']['delete'] @ph = params_hash['epp']['command']['delete']['delete']
xml_attrs_present?(@ph, [ ['id'] ] ) xml_attrs_present?(@ph, [['id']])
end end
## CHECK ## CHECK
def validate_contact_check_request def validate_contact_check_request
@ph = params_hash['epp']['command']['check']['check'] @ph = params_hash['epp']['command']['check']['check']
xml_attrs_present?(@ph, [ ['id'] ]) xml_attrs_present?(@ph, [['id']])
end end
## INFO ## INFO
def validate_contact_info_request def validate_contact_info_request
@ph = params_hash['epp']['command']['info']['info'] @ph = params_hash['epp']['command']['info']['info']
xml_attrs_present?(@ph, [ ['id'] ]) xml_attrs_present?(@ph, [['id']])
end end
## SHARED ## SHARED
@ -91,22 +92,22 @@ module Epp::ContactsHelper
pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || [] pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || []
id = @ph[:id] id = @ph[:id]
return true if ( !find_contact.nil? && find_contact.auth_info_matches(pw) ) return true if !find_contact.nil? && find_contact.auth_info_matches(pw)
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } } epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
return false false
end end
def contact_and_address_attributes( type=:create ) def contact_and_address_attributes(type = :create)
case type case type
when :update when :update
contact_hash = Contact.extract_attributes(@ph[:chg], type) contact_hash = Contact.extract_attributes(@ph[:chg], type)
contact_hash[:address_attributes] = contact_hash[:address_attributes] =
Address.extract_attributes(( @ph.try(:[], :chg).try(:[], :postalInfo).try(:[], :addr) || [] ), type) Address.extract_attributes(( @ph.try(:[], :chg).try(:[], :postalInfo).try(:[], :addr) || []), type)
else else
contact_hash = Contact.extract_attributes(@ph, type) contact_hash = Contact.extract_attributes(@ph, type)
contact_hash[:address_attributes] = contact_hash[:address_attributes] =
Address.extract_attributes(( @ph.try(:[], :postalInfo).try(:[], :addr) || [] ), type) Address.extract_attributes(( @ph.try(:[], :postalInfo).try(:[], :addr) || []), type)
end end
contact_hash[:ident_type] = ident_type unless ident_type.nil? contact_hash[:ident_type] = ident_type unless ident_type.nil?
contact_hash contact_hash
@ -118,6 +119,6 @@ module Epp::ContactsHelper
return nil unless result return nil unless result
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) } Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
return nil nil
end end
end end

View file

@ -48,6 +48,7 @@ module Epp::DomainsHelper
end end
### HELPER METHODS ### ### HELPER METHODS ###
private private
## CREATE ## CREATE
@ -95,7 +96,7 @@ module Epp::DomainsHelper
def find_domain def find_domain
domain = Domain.find_by(name: @ph[:name]) domain = Domain.find_by(name: @ph[:name])
unless domain unless domain
epp_errors << {code: '2303', msg: I18n.t('errors.messages.epp_domain_not_found'), value: {obj: 'name', val: @ph[:name]}} epp_errors << { code: '2303', msg: I18n.t('errors.messages.epp_domain_not_found'), value: { obj: 'name', val: @ph[:name] } }
end end
domain domain
end end

View file

@ -3,7 +3,7 @@ class Address < ActiveRecord::Base
belongs_to :country belongs_to :country
class << self class << self
def extract_attributes ah, type=:create def extract_attributes(ah, _type = :create)
address_hash = {} address_hash = {}
address_hash = ({ address_hash = ({
country_id: Country.find_by(iso: ah[:cc]).try(:id), country_id: Country.find_by(iso: ah[:cc]).try(:id),
@ -14,7 +14,7 @@ class Address < ActiveRecord::Base
zip: ah[:pc] zip: ah[:pc]
}) if ah.is_a?(Hash) }) if ah.is_a?(Hash)
address_hash.delete_if { |k, v| v.nil? } address_hash.delete_if { |_k, v| v.nil? }
end end
end end
end end

View file

@ -22,21 +22,21 @@ module EppErrors
values.each do |err| values.each do |err|
if err.is_a?(Hash) if err.is_a?(Hash)
next unless code = find_epp_code(err[:msg]) next unless code = find_epp_code(err[:msg])
err_msg = {code: code, msg: err[:msg]} err_msg = { code: code, msg: err[:msg] }
err_msg[:value] = {val: err[:val], obj: err[:obj]} if err[:val] err_msg[:value] = { val: err[:val], obj: err[:obj] } if err[:val]
epp_errors << err_msg epp_errors << err_msg
else else
next unless code = find_epp_code(err) next unless code = find_epp_code(err)
err = {code: code, msg: err} err = { code: code, msg: err }
# If we have setting relation, then still add the value to the error message # If we have setting relation, then still add the value to the error message
# If this sort of exception happens again, some other logic has to be implemented # If this sort of exception happens again, some other logic has to be implemented
if self.class.reflect_on_association(key) && key == :setting if self.class.reflect_on_association(key) && key == :setting
err[:value] = {val: send(key).value, obj: self.class::EPP_ATTR_MAP[key]} err[:value] = { val: send(key).value, obj: self.class::EPP_ATTR_MAP[key] }
#if the key represents other relations, skip value # if the key represents other relations, skip value
elsif !self.class.reflect_on_association(key) elsif !self.class.reflect_on_association(key)
err[:value] = {val: send(key), obj: self.class::EPP_ATTR_MAP[key]} err[:value] = { val: send(key), obj: self.class::EPP_ATTR_MAP[key] }
end end
epp_errors << err epp_errors << err

View file

@ -1,6 +1,6 @@
class Contact < ActiveRecord::Base class Contact < ActiveRecord::Base
#TODO Foreign contact will get email with activation link/username/temp password # TODO Foreign contact will get email with activation link/username/temp password
#TODO Phone number validation, in first phase very minimam in order to support current registries # TODO Phone number validation, in first phase very minimam in order to support current registries
include EppErrors include EppErrors
@ -19,23 +19,23 @@ class Contact < ActiveRecord::Base
validate :ident_must_be_valid validate :ident_must_be_valid
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ #/\+\d{3}\.\d+/ validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ # /\+\d{3}\.\d+/
validates :email, format: /@/ validates :email, format: /@/
validates_uniqueness_of :code, message: :epp_id_taken validates_uniqueness_of :code, message: :epp_id_taken
IDENT_TYPE_ICO = 'ico' IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [ IDENT_TYPES = [
IDENT_TYPE_ICO, #Company registry code (or similar) IDENT_TYPE_ICO, # Company registry code (or similar)
"op", #Estonian ID 'op', # Estonian ID
"passport", #Passport number 'passport', # Passport number
"birthday" #Birthday date 'birthday' # Birthday date
] ]
def ident_must_be_valid def ident_must_be_valid
#TODO Ident can also be passport number or company registry code. # TODO Ident can also be passport number or company registry code.
#so have to make changes to validations (and doc/schema) accordingly # so have to make changes to validations (and doc/schema) accordingly
return true unless ident.present? && ident_type.present? && ident_type == "op" return true unless ident.present? && ident_type.present? && ident_type == 'op'
code = Isikukood.new(ident) code = Isikukood.new(ident)
errors.add(:ident, 'bad format') unless code.valid? errors.add(:ident, 'bad format') unless code.valid?
end end
@ -56,22 +56,22 @@ class Contact < ActiveRecord::Base
updated_by ? updated_by.username : nil updated_by ? updated_by.username : nil
end end
def auth_info_matches pw def auth_info_matches(pw)
return true if auth_info == pw return true if auth_info == pw
return false false
end end
#Find a way to use self.domains with contact # Find a way to use self.domains with contact
def domains_owned def domains_owned
Domain.find_by(owner_contact_id: id) Domain.find_by(owner_contact_id: id)
end end
def relations_with_domain? def relations_with_domain?
return true if domain_contacts.present? || domains_owned.present? return true if domain_contacts.present? || domains_owned.present?
return false false
end end
#should use only in transaction # should use only in transaction
def destroy_and_clean def destroy_and_clean
clean_up_address clean_up_address
@ -84,15 +84,15 @@ class Contact < ActiveRecord::Base
def epp_code_map def epp_code_map
{ {
'2302' => [ #Object exists '2302' => [ # Object exists
[:code, :epp_id_taken] [:code, :epp_id_taken]
], ],
'2303' => #Object does not exist '2303' => # Object does not exist
[:not_found, :epp_obj_does_not_exist], [:not_found, :epp_obj_does_not_exist],
'2305' => [ #Association exists '2305' => [ # Association exists
[:domains, :exist] [:domains, :exist]
], ],
'2005' => [ #Value syntax error '2005' => [ # Value syntax error
[:phone, :invalid], [:phone, :invalid],
[:email, :invalid] [:email, :invalid]
] ]
@ -100,10 +100,7 @@ class Contact < ActiveRecord::Base
end end
class << self class << self
def extract_attributes(ph, type = :create)
def extract_attributes ph, type=:create
contact_hash = { contact_hash = {
phone: ph[:voice], phone: ph[:voice],
ident: ph[:ident], ident: ph[:ident],
@ -117,7 +114,7 @@ class Contact < ActiveRecord::Base
contact_hash[:code] = ph[:id] if type == :create contact_hash[:code] = ph[:id] if type == :create
contact_hash.delete_if { |k, v| v.nil? } contact_hash.delete_if { |_k, v| v.nil? }
end end
def check_availability(codes) def check_availability(codes)
@ -126,9 +123,9 @@ class Contact < ActiveRecord::Base
res = [] res = []
codes.each do |x| codes.each do |x|
if Contact.find_by(code: x) if Contact.find_by(code: x)
res << {code: x, avail: 0, reason: 'in use'} res << { code: x, avail: 0, reason: 'in use' }
else else
res << {code: x, avail: 1} res << { code: x, avail: 1 }
end end
end end
@ -141,6 +138,4 @@ class Contact < ActiveRecord::Base
def clean_up_address def clean_up_address
address.destroy if address address.destroy if address
end end
end end

View file

@ -1,3 +1,2 @@
class Country < ActiveRecord::Base class Country < ActiveRecord::Base
end end

View file

@ -1,6 +1,6 @@
class Domain < ActiveRecord::Base class Domain < ActiveRecord::Base
#TODO whois requests ip whitelist for full info for own domains and partial info for other domains # TODO whois requests ip whitelist for full info for own domains and partial info for other domains
#TODO most inputs should be trimmed before validatation, probably some global logic? # TODO most inputs should be trimmed before validatation, probably some global logic?
include EppErrors include EppErrors
@ -15,18 +15,18 @@ class Domain < ActiveRecord::Base
has_many :domain_contacts has_many :domain_contacts
has_many :tech_contacts, -> { has_many :tech_contacts, -> do
where(domain_contacts: {contact_type: DomainContact::TECH}) where(domain_contacts: { contact_type: DomainContact::TECH })
}, through: :domain_contacts, source: :contact end, through: :domain_contacts, source: :contact
has_many :admin_contacts, -> { has_many :admin_contacts, -> do
where(domain_contacts: {contact_type: DomainContact::ADMIN}) where(domain_contacts: { contact_type: DomainContact::ADMIN })
}, through: :domain_contacts, source: :contact end, through: :domain_contacts, source: :contact
has_and_belongs_to_many :nameservers has_and_belongs_to_many :nameservers
has_many :domain_statuses, -> { has_many :domain_statuses, -> {
joins(:setting).where(settings: {setting_group_id: SettingGroup.domain_statuses.id}) joins(:setting).where(settings: { setting_group_id: SettingGroup.domain_statuses.id })
} }
delegate :code, to: :owner_contact, prefix: true delegate :code, to: :owner_contact, prefix: true
@ -123,14 +123,14 @@ class Domain < ActiveRecord::Base
def attach_nameservers(ns_list) def attach_nameservers(ns_list)
ns_list.each do |ns_attrs| ns_list.each do |ns_attrs|
self.nameservers.build(ns_attrs) nameservers.build(ns_attrs)
end end
end end
def attach_statuses(status_list) def attach_statuses(status_list)
status_list.each do |x| status_list.each do |x|
setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value]) setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value])
self.domain_statuses.build( domain_statuses.build(
setting: setting, setting: setting,
description: x[:description] description: x[:description]
) )
@ -139,9 +139,9 @@ class Domain < ActiveRecord::Base
def detach_contacts(contact_list) def detach_contacts(contact_list)
to_delete = [] to_delete = []
contact_list.each do |k, v| contact_list.each do |_k, v|
v.each do |x| v.each do |x|
contact = domain_contacts.joins(:contact).where(contacts: {code: x[:contact]}) contact = domain_contacts.joins(:contact).where(contacts: { code: x[:contact] })
if contact.blank? if contact.blank?
errors.add(:domain_contacts, { errors.add(:domain_contacts, {
obj: 'contact', obj: 'contact',
@ -154,13 +154,13 @@ class Domain < ActiveRecord::Base
end end
end end
self.domain_contacts.delete(to_delete) domain_contacts.delete(to_delete)
end end
def detach_nameservers(ns_list) def detach_nameservers(ns_list)
to_delete = [] to_delete = []
ns_list.each do |ns_attrs| ns_list.each do |ns_attrs|
nameserver = self.nameservers.where(ns_attrs) nameserver = nameservers.where(ns_attrs)
if nameserver.blank? if nameserver.blank?
errors.add(:nameservers, { errors.add(:nameservers, {
obj: 'hostObj', obj: 'hostObj',
@ -172,13 +172,13 @@ class Domain < ActiveRecord::Base
end end
end end
self.nameservers.delete(to_delete) nameservers.delete(to_delete)
end end
def detach_statuses(status_list) def detach_statuses(status_list)
to_delete = [] to_delete = []
status_list.each do |x| status_list.each do |x|
status = domain_statuses.joins(:setting).where(settings: {value: x[:value]}) status = domain_statuses.joins(:setting).where(settings: { value: x[:value] })
if status.blank? if status.blank?
errors.add(:domain_statuses, { errors.add(:domain_statuses, {
obj: 'status', obj: 'status',
@ -190,19 +190,19 @@ class Domain < ActiveRecord::Base
end end
end end
self.domain_statuses.delete(to_delete) domain_statuses.delete(to_delete)
end end
### RENEW ### ### RENEW ###
def renew(cur_exp_date, period, unit='y') def renew(cur_exp_date, period, unit = 'y')
# TODO Check how much time before domain exp date can it be renewed # TODO Check how much time before domain exp date can it be renewed
validate_exp_dates(cur_exp_date) validate_exp_dates(cur_exp_date)
return false if errors.any? return false if errors.any?
p = self.class.convert_period_to_time(period, unit) p = self.class.convert_period_to_time(period, unit)
self.valid_to = self.valid_to + p self.valid_to = valid_to + p
self.period = period self.period = period
self.period_unit = unit self.period_unit = unit
save save
@ -215,7 +215,7 @@ class Domain < ActiveRecord::Base
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
unless nameservers.length.between?(min, max) unless nameservers.length.between?(min, max)
errors.add(:nameservers, :out_of_range, {min: min, max: max}) errors.add(:nameservers, :out_of_range, { min: min, max: max })
end end
end end
@ -226,11 +226,11 @@ class Domain < ActiveRecord::Base
def validate_period def validate_period
return unless period.present? return unless period.present?
if period_unit == 'd' if period_unit == 'd'
valid_values = ['365', '366', '710', '712', '1065', '1068'] valid_values = %w(365 366 710 712 1065 1068)
elsif period_unit == 'm' elsif period_unit == 'm'
valid_values = ['12', '24', '36'] valid_values = %w(12 24 36)
else else
valid_values = ['1', '2', '3'] valid_values = %w(1 2 3)
end end
errors.add(:period, :out_of_range) unless valid_values.include?(period.to_s) errors.add(:period, :out_of_range) unless valid_values.include?(period.to_s)
@ -258,7 +258,7 @@ class Domain < ActiveRecord::Base
[:valid_to, :epp_exp_dates_do_not_match] [:valid_to, :epp_exp_dates_do_not_match]
], ],
'2004' => [ # Parameter value range error '2004' => [ # Parameter value range error
[:nameservers, :out_of_range, {min: domain_validation_sg.setting(:ns_min_count).value, max: domain_validation_sg.setting(:ns_max_count).value}], [:nameservers, :out_of_range, { min: domain_validation_sg.setting(:ns_min_count).value, max: domain_validation_sg.setting(:ns_max_count).value }],
[:period, :out_of_range] [:period, :out_of_range]
], ],
'2303' => [ # Object does not exist '2303' => [ # Object does not exist
@ -277,7 +277,7 @@ class Domain < ActiveRecord::Base
# For domain transfer # For domain transfer
def authenticate(pw) def authenticate(pw)
errors.add(:auth_info, {msg: errors.generate_message(:auth_info, :wrong_pw)}) if pw != auth_info errors.add(:auth_info, { msg: errors.generate_message(:auth_info, :wrong_pw) }) if pw != auth_info
errors.empty? errors.empty?
end end
@ -351,20 +351,20 @@ class Domain < ActiveRecord::Base
res = [] res = []
domains.each do |x| domains.each do |x|
if !DomainNameValidator.validate_format(x) unless DomainNameValidator.validate_format(x)
res << {name: x, avail: 0, reason: 'invalid format'} res << { name: x, avail: 0, reason: 'invalid format' }
next next
end end
if !DomainNameValidator.validate_reservation(x) unless DomainNameValidator.validate_reservation(x)
res << {name: x, avail: 0, reason: I18n.t('errors.messages.epp_domain_reserved')} res << { name: x, avail: 0, reason: I18n.t('errors.messages.epp_domain_reserved') }
next next
end end
if Domain.find_by(name: x) if Domain.find_by(name: x)
res << {name: x, avail: 0, reason: 'in use'} res << { name: x, avail: 0, reason: 'in use' }
else else
res << {name: x, avail: 1} res << { name: x, avail: 1 }
end end
end end

View file

@ -1,5 +1,5 @@
class EppUser < ActiveRecord::Base class EppUser < ActiveRecord::Base
#TODO should have max request limit per day # TODO should have max request limit per day
belongs_to :registrar belongs_to :registrar
has_many :contacts has_many :contacts
end end

View file

@ -1,3 +1,2 @@
class ReservedDomain < ActiveRecord::Base class ReservedDomain < ActiveRecord::Base
end end

View file

@ -1,7 +1,7 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
#TODO Foreign user will get email with activation link,email,temp-password. # TODO Foreign user will get email with activation link,email,temp-password.
#After activisation, system should require to change temp password. # After activisation, system should require to change temp password.
#TODO Estonian id validation # TODO Estonian id validation
belongs_to :role belongs_to :role
end end

View file

@ -1,5 +1,5 @@
class DomainNameValidator < ActiveModel::EachValidator class DomainNameValidator < ActiveModel::EachValidator
#TODO # TODO
# validates lenght of 2-63 # validates lenght of 2-63
# validates/honours Estonian additional letters zäõüö # validates/honours Estonian additional letters zäõüö
# honours punicode and all interfces honors utf8 # honours punicode and all interfces honors utf8

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
begin begin
load File.expand_path("../spring", __FILE__) load File.expand_path('../spring', __FILE__)
rescue LoadError rescue LoadError
end end
APP_PATH = File.expand_path('../../config/application', __FILE__) APP_PATH = File.expand_path('../../config/application', __FILE__)

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
begin begin
load File.expand_path("../spring", __FILE__) load File.expand_path('../spring', __FILE__)
rescue LoadError rescue LoadError
end end
require_relative '../config/boot' require_relative '../config/boot'

View file

@ -7,7 +7,7 @@
# #
require 'pathname' require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath) Pathname.new(__FILE__).realpath)
require 'rubygems' require 'rubygems'

View file

@ -4,15 +4,15 @@
# It gets overwritten when you run the `spring binstub` command # It gets overwritten when you run the `spring binstub` command
unless defined?(Spring) unless defined?(Spring)
require "rubygems" require 'rubygems'
require "bundler" require 'bundler'
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) ENV['GEM_PATH'] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
ENV["GEM_HOME"] = "" ENV['GEM_HOME'] = ''
Gem.paths = ENV Gem.paths = ENV
gem "spring", match[1] gem 'spring', match[1]
require "spring/binstub" require 'spring/binstub'
end end
end end

View file

@ -1,12 +1,12 @@
require File.expand_path('../boot', __FILE__) require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want: # Pick the frameworks you want:
require "active_model/railtie" require 'active_model/railtie'
require "active_record/railtie" require 'active_record/railtie'
require "action_controller/railtie" require 'action_controller/railtie'
require "action_mailer/railtie" require 'action_mailer/railtie'
require "action_view/railtie" require 'action_view/railtie'
require "sprockets/railtie" require 'sprockets/railtie'
# require "rails/test_unit/railtie" # require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems # Require the gems listed in Gemfile, including any gems

View file

@ -1 +1 @@
Dir[File.join(Rails.root, "lib", "ext", "*.rb")].each {|x| require x } Dir[File.join(Rails.root, 'lib', 'ext', '*.rb')].each { |x| require x }

View file

@ -1,8 +1,8 @@
class Init < ActiveRecord::Migration class Init < ActiveRecord::Migration
def change def change
create_table :domains do |t| create_table :domains do |t|
t.string :name #ascii, utf8 will be converted on the fly t.string :name # ascii, utf8 will be converted on the fly
t.integer :registrar_id #registripidaja t.integer :registrar_id # registripidaja
t.datetime :registered_at t.datetime :registered_at
t.string :status t.string :status
t.datetime :valid_from t.datetime :valid_from
@ -12,17 +12,17 @@ class Init < ActiveRecord::Migration
t.integer :technical_contact_id t.integer :technical_contact_id
t.integer :ns_set_id t.integer :ns_set_id
t.string :auth_info t.string :auth_info
#t.integer :keyset_id #dnssec # t.integer :keyset_id #dnssec
t.timestamps t.timestamps
end end
# this will be a huge table? # this will be a huge table?
create_table :contacts do |t| create_table :contacts do |t|
t.string :code #CID:STRING:OID t.string :code # CID:STRING:OID
t.string :name t.string :name
t.string :type #organisation / juridical / citizen #rails specific variable t.string :type # organisation / juridical / citizen #rails specific variable
t.string :reg_no #identity code or registration number for organisation t.string :reg_no # identity code or registration number for organisation
# can a person have one or more of these contacts? # can a person have one or more of these contacts?
t.string :phone t.string :phone
@ -32,11 +32,11 @@ class Init < ActiveRecord::Migration
t.timestamps t.timestamps
end end
create_table :addresses do |t| #needs a better name? create_table :addresses do |t| # needs a better name?
t.integer :contact_id t.integer :contact_id
t.integer :country_id t.integer :country_id
t.string :city t.string :city
t.string :address #Street + house + apartment #needs a better name t.string :address # Street + house + apartment #needs a better name
t.string :zip t.string :zip
t.timestamps t.timestamps
@ -60,7 +60,7 @@ class Init < ActiveRecord::Migration
t.timestamps t.timestamps
end end
#legal documents # legal documents
# create_table :documents do |t| # create_table :documents do |t|
# t.integer :domain_id # t.integer :domain_id
# t.string :name # t.string :name
@ -70,13 +70,13 @@ class Init < ActiveRecord::Migration
# end # end
create_table :ns_sets do |t| create_table :ns_sets do |t|
t.string :code #NSSID:STRING:OID t.string :code # NSSID:STRING:OID
t.integer :registrar_id t.integer :registrar_id
t.string :auth_info #password for transferring between registrants t.string :auth_info # password for transferring between registrants
t.string :report_level t.string :report_level
#t.integer :technical_contact_id # reference to technical contact - # t.integer :technical_contact_id # reference to technical contact -
#does each ns_set have spearate technical contacts or can the contacts be inherited from the registrar? # does each ns_set have spearate technical contacts or can the contacts be inherited from the registrar?
t.timestamps t.timestamps
end end
@ -94,13 +94,13 @@ class Init < ActiveRecord::Migration
t.timestamps t.timestamps
end end
#devise for login # devise for login
#cancan for securing # cancan for securing
#what to do with API users? # what to do with API users?
create_table :users do |t| create_table :users do |t|
t.string :username t.string :username
t.string :password t.string :password
t.integer :role_id #can user have more than one role? t.integer :role_id # can user have more than one role?
t.timestamps t.timestamps
end end
@ -117,7 +117,7 @@ class Init < ActiveRecord::Migration
end end
create_table :rights do |t| create_table :rights do |t|
t.string :code #LOG_IN, SEE_DOMAINS, etc t.string :code # LOG_IN, SEE_DOMAINS, etc
t.timestamps t.timestamps
end end

View file

@ -6,7 +6,7 @@ class CreateEppSessions < ActiveRecord::Migration
t.timestamps t.timestamps
end end
add_index :epp_sessions, :session_id, :unique => true add_index :epp_sessions, :session_id, unique: true
add_index :epp_sessions, :updated_at add_index :epp_sessions, :updated_at
end end
end end

View file

@ -4,7 +4,7 @@ class PopulateSettings < ActiveRecord::Migration
code: 'domain_validation', code: 'domain_validation',
settings: [ settings: [
Setting.create(code: 'ns_min_count', value: 1), Setting.create(code: 'ns_min_count', value: 1),
Setting.create(code: 'ns_max_count', value: 13), Setting.create(code: 'ns_max_count', value: 13)
] ]
) )
end end

View file

@ -11,181 +11,181 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140819103517) do ActiveRecord::Schema.define(version: 20_140_819_103_517) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension 'plpgsql'
create_table "addresses", force: true do |t| create_table 'addresses', force: true do |t|
t.integer "contact_id" t.integer 'contact_id'
t.integer "country_id" t.integer 'country_id'
t.string "city" t.string 'city'
t.string "street" t.string 'street'
t.string "zip" t.string 'zip'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
t.string "street2" t.string 'street2'
t.string "street3" t.string 'street3'
end end
create_table "contacts", force: true do |t| create_table 'contacts', force: true do |t|
t.string "code" t.string 'code'
t.string "name" t.string 'name'
t.string "type" t.string 'type'
t.string "reg_no" t.string 'reg_no'
t.string "phone" t.string 'phone'
t.string "email" t.string 'email'
t.string "fax" t.string 'fax'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
t.string "ident" t.string 'ident'
t.string "ident_type" t.string 'ident_type'
t.string "org_name" t.string 'org_name'
t.integer "created_by_id" t.integer 'created_by_id'
t.integer "updated_by_id" t.integer 'updated_by_id'
t.string "auth_info" t.string 'auth_info'
end end
create_table "countries", force: true do |t| create_table 'countries', force: true do |t|
t.string "iso" t.string 'iso'
t.string "name" t.string 'name'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "domain_contacts", force: true do |t| create_table 'domain_contacts', force: true do |t|
t.integer "contact_id" t.integer 'contact_id'
t.integer "domain_id" t.integer 'domain_id'
t.string "contact_type" t.string 'contact_type'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "domain_statuses", force: true do |t| create_table 'domain_statuses', force: true do |t|
t.integer "domain_id" t.integer 'domain_id'
t.integer "setting_id" t.integer 'setting_id'
t.string "description" t.string 'description'
end end
create_table "domains", force: true do |t| create_table 'domains', force: true do |t|
t.string "name" t.string 'name'
t.integer "registrar_id" t.integer 'registrar_id'
t.datetime "registered_at" t.datetime 'registered_at'
t.string "status" t.string 'status'
t.datetime "valid_from" t.datetime 'valid_from'
t.datetime "valid_to" t.datetime 'valid_to'
t.integer "owner_contact_id" t.integer 'owner_contact_id'
t.integer "admin_contact_id" t.integer 'admin_contact_id'
t.integer "technical_contact_id" t.integer 'technical_contact_id'
t.integer "ns_set_id" t.integer 'ns_set_id'
t.string "auth_info" t.string 'auth_info'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
t.string "name_dirty" t.string 'name_dirty'
t.string "name_puny" t.string 'name_puny'
t.integer "period" t.integer 'period'
t.string "period_unit", limit: 1 t.string 'period_unit', limit: 1
end end
create_table "domains_nameservers", force: true do |t| create_table 'domains_nameservers', force: true do |t|
t.integer "domain_id" t.integer 'domain_id'
t.integer "nameserver_id" t.integer 'nameserver_id'
end end
create_table "epp_sessions", force: true do |t| create_table 'epp_sessions', force: true do |t|
t.string "session_id" t.string 'session_id'
t.text "data" t.text 'data'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "epp_sessions", ["session_id"], name: "index_epp_sessions_on_session_id", unique: true, using: :btree add_index 'epp_sessions', ['session_id'], name: 'index_epp_sessions_on_session_id', unique: true, using: :btree
add_index "epp_sessions", ["updated_at"], name: "index_epp_sessions_on_updated_at", using: :btree add_index 'epp_sessions', ['updated_at'], name: 'index_epp_sessions_on_updated_at', using: :btree
create_table "epp_users", force: true do |t| create_table 'epp_users', force: true do |t|
t.integer "registrar_id" t.integer 'registrar_id'
t.string "username" t.string 'username'
t.string "password" t.string 'password'
t.boolean "active", default: false t.boolean 'active', default: false
t.text "csr" t.text 'csr'
t.text "crt" t.text 'crt'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "nameservers", force: true do |t| create_table 'nameservers', force: true do |t|
t.string "hostname" t.string 'hostname'
t.string "ipv4" t.string 'ipv4'
t.integer "ns_set_id" t.integer 'ns_set_id'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
t.string "ipv6" t.string 'ipv6'
end end
create_table "nameservers_ns_sets", force: true do |t| create_table 'nameservers_ns_sets', force: true do |t|
t.integer "nameserver_id" t.integer 'nameserver_id'
t.integer "ns_set_id" t.integer 'ns_set_id'
end end
create_table "ns_sets", force: true do |t| create_table 'ns_sets', force: true do |t|
t.string "code" t.string 'code'
t.integer "registrar_id" t.integer 'registrar_id'
t.string "auth_info" t.string 'auth_info'
t.string "report_level" t.string 'report_level'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "registrars", force: true do |t| create_table 'registrars', force: true do |t|
t.string "name" t.string 'name'
t.string "reg_no" t.string 'reg_no'
t.string "vat_no" t.string 'vat_no'
t.string "address" t.string 'address'
t.integer "country_id" t.integer 'country_id'
t.string "billing_address" t.string 'billing_address'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "reserved_domains", force: true do |t| create_table 'reserved_domains', force: true do |t|
t.string "name" t.string 'name'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "rights", force: true do |t| create_table 'rights', force: true do |t|
t.string "code" t.string 'code'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "rights_roles", force: true do |t| create_table 'rights_roles', force: true do |t|
t.integer "right_id" t.integer 'right_id'
t.integer "role_id" t.integer 'role_id'
end end
create_table "roles", force: true do |t| create_table 'roles', force: true do |t|
t.string "name" t.string 'name'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
create_table "setting_groups", force: true do |t| create_table 'setting_groups', force: true do |t|
t.string "code" t.string 'code'
end end
create_table "settings", force: true do |t| create_table 'settings', force: true do |t|
t.integer "setting_group_id" t.integer 'setting_group_id'
t.string "code" t.string 'code'
t.string "value" t.string 'value'
end end
create_table "users", force: true do |t| create_table 'users', force: true do |t|
t.string "username" t.string 'username'
t.string "password" t.string 'password'
t.integer "role_id" t.integer 'role_id'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
end end

View file

@ -3,7 +3,7 @@ require 'builder'
class Builder::XmlMarkup class Builder::XmlMarkup
def epp_head def epp_head
self.instruct! self.instruct!
self.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd') do epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd') do
yield yield
end end
end end

View file

@ -13,7 +13,7 @@ end
desc 'Run all but EPP specs' desc 'Run all but EPP specs'
RSpec::Core::RakeTask.new('test:other') do |t| RSpec::Core::RakeTask.new('test:other') do |t|
t.rspec_opts = "--tag ~epp" t.rspec_opts = '--tag ~epp'
end end
Rake::Task[:default].prerequisites.clear Rake::Task[:default].prerequisites.clear

View file

@ -1,17 +1,17 @@
require 'rails_helper' require 'rails_helper'
describe 'EPP Contact', epp: true do describe 'EPP Contact', epp: true do
let(:server) { Epp::Server.new({server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701}) } let(:server) { Epp::Server.new({ server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701 }) }
context 'with valid user' do context 'with valid user' do
before(:each) { before(:each) do
Fabricate(:epp_user) Fabricate(:epp_user)
Fabricate(:domain_validation_setting_group) Fabricate(:domain_validation_setting_group)
} end
context 'create command' do context 'create command' do
it "fails if request is invalid" do it 'fails if request is invalid' do
response = epp_request(contact_create_xml( { authInfo: [false], addr: { cc: false, city: false } } ), :xml) response = epp_request(contact_create_xml({ authInfo: [false], addr: { cc: false, city: false } }), :xml)
expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:result_code]).to eq('2003')
expect(response[:results][1][:result_code]).to eq('2003') expect(response[:results][1][:result_code]).to eq('2003')
@ -52,7 +52,7 @@ describe 'EPP Contact', epp: true do
crDate = response[:parsed].css('resData creData crDate').first crDate = response[:parsed].css('resData creData crDate').first
expect(id.text).to eq('sh8013') expect(id.text).to eq('sh8013')
#5 seconds for what-ever weird lag reasons might happen # 5 seconds for what-ever weird lag reasons might happen
expect(crDate.text.to_time).to be_within(5).of(Time.now) expect(crDate.text.to_time).to be_within(5).of(Time.now)
end end
@ -69,18 +69,16 @@ describe 'EPP Contact', epp: true do
end end
end end
context 'update command' do context 'update command' do
it "fails if request is invalid" do it 'fails if request is invalid' do
response = epp_request('contacts/update_missing_attr.xml') response = epp_request('contacts/update_missing_attr.xml')
#response = epp_request(contact_update_xml( {id: false} ), :xml) # response = epp_request(contact_update_xml( {id: false} ), :xml)
expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:result_code]).to eq('2003')
expect(response[:results][0][:msg]).to eq('Required parameter missing: id') expect(response[:results][0][:msg]).to eq('Required parameter missing: id')
expect(response[:results].count).to eq 1 expect(response[:results].count).to eq 1
end end
it 'fails with wrong authentication info' do it 'fails with wrong authentication info' do
Fabricate(:contact, code: 'sh8013', auth_info: 'secure_password') Fabricate(:contact, code: 'sh8013', auth_info: 'secure_password')
@ -102,7 +100,7 @@ describe 'EPP Contact', epp: true do
it 'is succesful' do it 'is succesful' do
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR') Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
#response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml) # response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml)
response = epp_request('contacts/update.xml') response = epp_request('contacts/update.xml')
expect(response[:msg]).to eq('Command completed successfully') expect(response[:msg]).to eq('Command completed successfully')
@ -114,7 +112,7 @@ describe 'EPP Contact', epp: true do
it 'returns phone and email error' do it 'returns phone and email error' do
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR') Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
#response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml) # response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml)
response = epp_request('contacts/update_with_errors.xml') response = epp_request('contacts/update_with_errors.xml')
expect(response[:results][0][:result_code]).to eq('2005') expect(response[:results][0][:result_code]).to eq('2005')
@ -126,7 +124,7 @@ describe 'EPP Contact', epp: true do
end end
context 'delete command' do context 'delete command' do
it "fails if request is invalid" do it 'fails if request is invalid' do
response = epp_request('contacts/delete_missing_attr.xml') response = epp_request('contacts/delete_missing_attr.xml')
expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:result_code]).to eq('2003')
@ -135,7 +133,7 @@ describe 'EPP Contact', epp: true do
end end
it 'deletes contact' do it 'deletes contact' do
Fabricate(:contact, code: "dwa1234") Fabricate(:contact, code: 'dwa1234')
response = epp_request('contacts/delete.xml') response = epp_request('contacts/delete.xml')
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully') expect(response[:msg]).to eq('Command completed successfully')
@ -163,10 +161,9 @@ describe 'EPP Contact', epp: true do
end end
end end
context 'check command' do context 'check command' do
it "fails if request is invalid" do it 'fails if request is invalid' do
response = epp_request(contact_check_xml( ids: [ false ] ), :xml) response = epp_request(contact_check_xml(ids: [false]), :xml)
expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:result_code]).to eq('2003')
expect(response[:results][0][:msg]).to eq('Required parameter missing: id') expect(response[:results][0][:msg]).to eq('Required parameter missing: id')
@ -176,7 +173,7 @@ describe 'EPP Contact', epp: true do
it 'returns info about contact availability' do it 'returns info about contact availability' do
Fabricate(:contact, code: 'check-1234') Fabricate(:contact, code: 'check-1234')
response = epp_request(contact_check_xml( ids: [{ id: 'check-1234'}, { id: 'check-4321' }] ), :xml) response = epp_request(contact_check_xml(ids: [{ id: 'check-1234' }, { id: 'check-4321' }]), :xml)
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully') expect(response[:msg]).to eq('Command completed successfully')
@ -191,7 +188,7 @@ describe 'EPP Contact', epp: true do
end end
context 'info command' do context 'info command' do
it "fails if request invalid" do it 'fails if request invalid' do
response = epp_request('contacts/delete_missing_attr.xml') response = epp_request('contacts/delete_missing_attr.xml')
expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:result_code]).to eq('2003')
@ -207,7 +204,7 @@ describe 'EPP Contact', epp: true do
end end
it 'returns info about contact' do it 'returns info about contact' do
Fabricate(:contact, name: "Johnny Awesome", created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR') Fabricate(:contact, name: 'Johnny Awesome', created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR')
Fabricate(:address) Fabricate(:address)
response = epp_request('contacts/info.xml') response = epp_request('contacts/info.xml')
@ -220,7 +217,7 @@ describe 'EPP Contact', epp: true do
end end
it 'doesn\'t display unassociated object' do it 'doesn\'t display unassociated object' do
Fabricate(:contact, name:"Johnny Awesome", code: 'info-4444') Fabricate(:contact, name: 'Johnny Awesome', code: 'info-4444')
response = epp_request('contacts/info.xml') response = epp_request('contacts/info.xml')
expect(response[:result_code]).to eq('2201') expect(response[:result_code]).to eq('2201')

View file

@ -1,7 +1,7 @@
require 'rails_helper' require 'rails_helper'
describe 'EPP Domain', epp: true do describe 'EPP Domain', epp: true do
let(:server) { server = Epp::Server.new({server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701}) } let(:server) { server = Epp::Server.new({ server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701 }) }
context 'with valid user' do context 'with valid user' do
before(:each) do before(:each) do
@ -30,11 +30,11 @@ describe 'EPP Domain', epp: true do
end end
context 'with citizen as an owner' do context 'with citizen as an owner' do
before(:each) { before(:each) do
Fabricate(:contact, code: 'jd1234') Fabricate(:contact, code: 'jd1234')
Fabricate(:contact, code: 'sh8013') Fabricate(:contact, code: 'sh8013')
Fabricate(:contact, code: 'sh801333') Fabricate(:contact, code: 'sh801333')
} end
it 'creates a domain' do it 'creates a domain' do
response = epp_request(domain_create_xml, :xml) response = epp_request(domain_create_xml, :xml)
@ -88,7 +88,7 @@ describe 'EPP Domain', epp: true do
it 'does not create domain with too many nameservers' do it 'does not create domain with too many nameservers' do
nameservers = [] nameservers = []
14.times {|i| nameservers << {hostObj: "ns#{i}.example.net"}} 14.times { |i| nameservers << { hostObj: "ns#{i}.example.net" } }
xml = domain_create_xml(nameservers: nameservers) xml = domain_create_xml(nameservers: nameservers)
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
@ -97,7 +97,7 @@ describe 'EPP Domain', epp: true do
end end
it 'returns error when invalid nameservers are present' do it 'returns error when invalid nameservers are present' do
xml = domain_create_xml(nameservers: [{hostObj: 'invalid1-'}, {hostObj: '-invalid2'}]) xml = domain_create_xml(nameservers: [{ hostObj: 'invalid1-' }, { hostObj: '-invalid2' }])
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2005') expect(response[:result_code]).to eq('2005')
@ -144,14 +144,14 @@ describe 'EPP Domain', epp: true do
end end
context 'with juridical persion as an owner' do context 'with juridical persion as an owner' do
before(:each) { before(:each) do
Fabricate(:contact, code: 'jd1234', ident_type: 'ico') Fabricate(:contact, code: 'jd1234', ident_type: 'ico')
Fabricate(:contact, code: 'sh8013') Fabricate(:contact, code: 'sh8013')
Fabricate(:contact, code: 'sh801333') Fabricate(:contact, code: 'sh801333')
} end
it 'creates a domain with contacts' do it 'creates a domain with contacts' do
xml = domain_create_xml(contacts: [{contact_value: 'sh8013', contact_type: 'admin'}]) xml = domain_create_xml(contacts: [{ contact_value: 'sh8013', contact_type: 'admin' }])
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
@ -166,7 +166,7 @@ describe 'EPP Domain', epp: true do
end end
it 'does not create a domain without admin contact' do it 'does not create a domain without admin contact' do
xml = domain_create_xml(contacts: [{contact_value: 'sh8013', contact_type: 'tech'}]) xml = domain_create_xml(contacts: [{ contact_value: 'sh8013', contact_type: 'tech' }])
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2306') expect(response[:result_code]).to eq('2306')
@ -217,12 +217,12 @@ describe 'EPP Domain', epp: true do
expect(inf_data.css('name').text).to eq('example.ee') expect(inf_data.css('name').text).to eq('example.ee')
expect(inf_data.css('registrant').text).to eq(d.owner_contact_code) expect(inf_data.css('registrant').text).to eq(d.owner_contact_code)
admin_contacts_from_request = inf_data.css('contact[type="admin"]').collect{|x| x.text } admin_contacts_from_request = inf_data.css('contact[type="admin"]').map { |x| x.text }
admin_contacts_existing = d.admin_contacts.pluck(:code) admin_contacts_existing = d.admin_contacts.pluck(:code)
expect(admin_contacts_from_request).to eq(admin_contacts_existing) expect(admin_contacts_from_request).to eq(admin_contacts_existing)
hosts_from_request = inf_data.css('hostObj').collect{|x| x.text } hosts_from_request = inf_data.css('hostObj').map { |x| x.text }
hosts_existing = d.nameservers.pluck(:hostname) hosts_existing = d.nameservers.pluck(:hostname)
expect(hosts_from_request).to eq(hosts_existing) expect(hosts_from_request).to eq(hosts_existing)

View file

@ -64,12 +64,12 @@ describe 'EPP Helper', epp: true do
name: 'one.ee', name: 'one.ee',
period_value: '345', period_value: '345',
period_unit: 'd', period_unit: 'd',
nameservers: [{hostObj: 'ns1.test.net'}, {hostObj: 'ns2.test.net'}], nameservers: [{ hostObj: 'ns1.test.net' }, { hostObj: 'ns2.test.net' }],
registrant: '32fsdaf', registrant: '32fsdaf',
contacts: [ contacts: [
{contact_value: '2323rafaf', contact_type: 'admin'}, { contact_value: '2323rafaf', contact_type: 'admin' },
{contact_value: '3dgxx', contact_type: 'tech'}, { contact_value: '3dgxx', contact_type: 'tech' },
{contact_value: '345xxv', contact_type: 'tech'} { contact_value: '345xxv', contact_type: 'tech' }
], ],
pw: 'sdgdgd4esfsa' pw: 'sdgdgd4esfsa'
) )
@ -124,7 +124,6 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_info_xml).to_s.squish generated = Nokogiri::XML(domain_info_xml).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
@ -145,7 +144,6 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_info_xml(name_value: 'one.ee', name_hosts: 'sub', pw: 'b3rafsla')).to_s.squish generated = Nokogiri::XML(domain_info_xml(name_value: 'one.ee', name_hosts: 'sub', pw: 'b3rafsla')).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
end end
@ -165,7 +163,6 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_check_xml).to_s.squish generated = Nokogiri::XML(domain_check_xml).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
@ -185,7 +182,6 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_check_xml(names: ['example.ee', 'example2.ee', 'example3.ee'])).to_s.squish generated = Nokogiri::XML(domain_check_xml(names: ['example.ee', 'example2.ee', 'example3.ee'])).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
end end
@ -207,7 +203,6 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_renew_xml).to_s.squish generated = Nokogiri::XML(domain_renew_xml).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
@ -227,7 +222,6 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_renew_xml(name: 'one.ee', curExpDate: '2009-11-15', period_value: '365', period_unit: 'd')).to_s.squish generated = Nokogiri::XML(domain_renew_xml(name: 'one.ee', curExpDate: '2009-11-15', period_value: '365', period_unit: 'd')).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
end end

View file

@ -1,7 +1,7 @@
require 'rails_helper' require 'rails_helper'
describe 'EPP Session', epp: true do describe 'EPP Session', epp: true do
let(:server) { server = Epp::Server.new({server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701}) } let(:server) { server = Epp::Server.new({ server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701 }) }
context 'when not connected' do context 'when not connected' do
it 'greets client upon connection' do it 'greets client upon connection' do

View file

@ -1,4 +1,4 @@
Fabricator(:epp_session) do Fabricator(:epp_session) do
session_id 'test' session_id 'test'
data { {epp_user_id: 1} } data { { epp_user_id: 1 } }
end end

View file

@ -1,23 +1,29 @@
Fabricator(:setting_group) do Fabricator(:setting_group) do
code 'domain_validation' code 'domain_validation'
settings { [ settings do
[
Fabricate(:setting, code: 'ns_min_count', value: 1), Fabricate(:setting, code: 'ns_min_count', value: 1),
Fabricate(:setting, code: 'ns_max_count', value: 13) Fabricate(:setting, code: 'ns_max_count', value: 13)
]} ]
end
end end
Fabricator(:domain_validation_setting_group, from: :setting_group) do Fabricator(:domain_validation_setting_group, from: :setting_group) do
code 'domain_validation' code 'domain_validation'
settings { [ settings do
[
Fabricate(:setting, code: 'ns_min_count', value: 1), Fabricate(:setting, code: 'ns_min_count', value: 1),
Fabricate(:setting, code: 'ns_max_count', value: 13) Fabricate(:setting, code: 'ns_max_count', value: 13)
]} ]
end
end end
Fabricator(:domain_statuses_setting_group, from: :setting_group) do Fabricator(:domain_statuses_setting_group, from: :setting_group) do
code 'domain_statuses' code 'domain_statuses'
settings { [ settings do
[
Fabricate(:setting, code: 'client_hold', value: 'clientHold'), Fabricate(:setting, code: 'client_hold', value: 'clientHold'),
Fabricate(:setting, code: 'client_update_prohibited', value: 'clientUpdateProhibited') Fabricate(:setting, code: 'client_update_prohibited', value: 'clientUpdateProhibited')
]} ]
end
end end

View file

@ -1,22 +1,19 @@
require "rails_helper" require 'rails_helper'
describe Address do describe Address do
it { should belong_to(:contact) } it { should belong_to(:contact) }
it { should belong_to(:country) } it { should belong_to(:country) }
end end
describe Address, '.extract_params' do describe Address, '.extract_params' do
it 'returns params hash'do it 'returns params hash'do
Fabricate(:country, iso:'EE') Fabricate(:country, iso: 'EE')
ph = { postalInfo: { name: "fred", addr: { cc: 'EE', city: 'Village', street: [ 'street1', 'street2' ] } } } ph = { postalInfo: { name: 'fred', addr: { cc: 'EE', city: 'Village', street: %w(street1 street2) } } }
expect(Address.extract_attributes(ph[:postalInfo][:addr])).to eq( { expect(Address.extract_attributes(ph[:postalInfo][:addr])).to eq({
city: 'Village', city: 'Village',
country_id: 1, country_id: 1,
street: 'street1', street: 'street1',
street2: 'street2' street2: 'street2'
} ) })
end end
end end

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe Contact do describe Contact do
it { should have_one(:address) } it { should have_one(:address) }
@ -7,12 +7,12 @@ describe Contact do
before(:each) { @contact = Fabricate(:contact) } before(:each) { @contact = Fabricate(:contact) }
it 'phone should return false' do it 'phone should return false' do
@contact.phone = "32341" @contact.phone = '32341'
expect(@contact.valid?).to be false expect(@contact.valid?).to be false
end end
it 'ident should return false' do it 'ident should return false' do
@contact.ident = "123abc" @contact.ident = '123abc'
expect(@contact.valid?).to be false expect(@contact.valid?).to be false
end end
@ -21,11 +21,11 @@ describe Contact do
expect(@contact.valid?).to eq false expect(@contact.valid?).to eq false
expect(@contact.errors.messages).to match_array({ expect(@contact.errors.messages).to match_array({
:code=>["Required parameter missing - code"], code: ['Required parameter missing - code'],
:name=>["Required parameter missing - name"], name: ['Required parameter missing - name'],
:phone=>["Required parameter missing - phone", "Phone nr is invalid"], phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
:email=>["Required parameter missing - email", "Email is invalid"], email: ['Required parameter missing - email', 'Email is invalid'],
:ident=>["Required parameter missing - ident"] ident: ['Required parameter missing - ident']
}) })
end end
end end
@ -60,7 +60,7 @@ describe Contact, '#relations_with_domain?' do
end end
describe Contact, '#crID' do describe Contact, '#crID' do
before(:each) { Fabricate(:contact, code: "asd12", created_by: Fabricate(:epp_user)) } before(:each) { Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user)) }
it 'should return username of creator' do it 'should return username of creator' do
expect(Contact.first.crID).to eq('gitlab') expect(Contact.first.crID).to eq('gitlab')
@ -71,9 +71,8 @@ describe Contact, '#crID' do
end end
end end
describe Contact, '#upID' do describe Contact, '#upID' do
before(:each) { Fabricate(:contact, code: "asd12", created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user)) } before(:each) { Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user)) }
it 'should return username of updater' do it 'should return username of updater' do
expect(Contact.first.upID).to eq('gitlab') expect(Contact.first.upID).to eq('gitlab')
@ -84,45 +83,42 @@ describe Contact, '#upID' do
end end
end end
describe Contact, '.extract_params' do describe Contact, '.extract_params' do
it 'returns params hash'do it 'returns params hash'do
ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: "fred", addr: { cc: 'EE' } } } ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: 'fred', addr: { cc: 'EE' } } }
expect(Contact.extract_attributes(ph)).to eq( { expect(Contact.extract_attributes(ph)).to eq({
code: '123123', code: '123123',
email: 'jdoe@example.com', email: 'jdoe@example.com',
name: 'fred' name: 'fred'
} ) })
end end
end end
describe Contact, '.check_availability' do describe Contact, '.check_availability' do
before(:each) { before(:each) do
Fabricate(:contact, code: "asd12") Fabricate(:contact, code: 'asd12')
Fabricate(:contact, code: "asd13") Fabricate(:contact, code: 'asd13')
} end
it 'should return array if argument is string' do it 'should return array if argument is string' do
response = Contact.check_availability("asd12") response = Contact.check_availability('asd12')
expect(response.class).to be Array expect(response.class).to be Array
expect(response.length).to eq(1) expect(response.length).to eq(1)
end end
it 'should return in_use and available codes' do it 'should return in_use and available codes' do
response = Contact.check_availability(["asd12","asd13","asd14"]) response = Contact.check_availability(%w(asd12 asd13 asd14))
expect(response.class).to be Array expect(response.class).to be Array
expect(response.length).to eq(3) expect(response.length).to eq(3)
expect(response[0][:avail]).to eq(0) expect(response[0][:avail]).to eq(0)
expect(response[0][:code]).to eq("asd12") expect(response[0][:code]).to eq('asd12')
expect(response[1][:avail]).to eq(0) expect(response[1][:avail]).to eq(0)
expect(response[1][:code]).to eq("asd13") expect(response[1][:code]).to eq('asd13')
expect(response[2][:avail]).to eq(1) expect(response[2][:avail]).to eq(1)
expect(response[2][:code]).to eq("asd14") expect(response[2][:code]).to eq('asd14')
end end
end end

View file

@ -1,8 +1,8 @@
require "rails_helper" require 'rails_helper'
describe Domain do describe Domain do
it { should belong_to(:registrar) } it { should belong_to(:registrar) }
it { should have_and_belong_to_many(:nameservers)} it { should have_and_belong_to_many(:nameservers) }
it { should belong_to(:owner_contact) } it { should belong_to(:owner_contact) }
it { should have_many(:tech_contacts) } it { should have_many(:tech_contacts) }
it { should have_many(:admin_contacts) } it { should have_many(:admin_contacts) }
@ -44,9 +44,9 @@ describe Domain do
expect(d.errors.messages).to match_array({ expect(d.errors.messages).to match_array({
name: ['is missing'], name: ['is missing'],
period: ['is not a number'], period: ['is not a number'],
owner_contact: ["Registrant is missing"], owner_contact: ['Registrant is missing'],
admin_contacts: ["Admin contact is missing"], admin_contacts: ['Admin contact is missing'],
nameservers: ["Nameservers count must be between 1-13"] nameservers: ['Nameservers count must be between 1-13']
}) })
sg = SettingGroup.domain_validation sg = SettingGroup.domain_validation

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe EppSession do describe EppSession do
let(:epp_session) { Fabricate(:epp_session) } let(:epp_session) { Fabricate(:epp_session) }

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe EppUser do describe EppUser do
it { should belong_to(:registrar) } it { should belong_to(:registrar) }

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe Nameserver do describe Nameserver do
it { should have_and_belong_to_many(:domains) } it { should have_and_belong_to_many(:domains) }

View file

@ -1,6 +1,6 @@
require "rails_helper" require 'rails_helper'
describe NsSet do describe NsSet do
it { should belong_to(:registrar)} it { should belong_to(:registrar) }
it { should have_and_belong_to_many(:nameservers) } it { should have_and_belong_to_many(:nameservers) }
end end

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe Registrar do describe Registrar do
it { should belong_to(:country) } it { should belong_to(:country) }

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe Right do describe Right do
it { should have_and_belong_to_many(:roles) } it { should have_and_belong_to_many(:roles) }

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe Role do describe Role do
it { should have_and_belong_to_many(:rights) } it { should have_and_belong_to_many(:rights) }

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe SettingGroup do describe SettingGroup do
it { should have_many(:settings) } it { should have_many(:settings) }

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe Setting do describe Setting do
it { should belong_to(:setting_group) } it { should belong_to(:setting_group) }

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
describe User do describe User do
it { should belong_to(:role) } it { should belong_to(:role) }

View file

@ -1,7 +1,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install' # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test' ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper' require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__) require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails' require 'rspec/rails'
require 'shoulda/matchers' require 'shoulda/matchers'
require 'capybara/poltergeist' require 'capybara/poltergeist'
@ -13,7 +13,7 @@ require 'capybara/poltergeist'
# run twice. It is recommended that you do not name files matching this glob to # run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern # end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run. # Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line. # If you are not using ActiveRecord, you can remove this line.

View file

@ -14,65 +14,63 @@
# users commonly want. # users commonly want.
# #
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config| RSpec.configure do |_config|
# The settings below are suggested to provide a good initial experience # The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content. # with RSpec, but feel free to customize to your heart's content.
=begin # # These two settings work together to allow you to limit a spec run
# These two settings work together to allow you to limit a spec run # # to individual examples or groups you care about by tagging them with
# to individual examples or groups you care about by tagging them with # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
# `:focus` metadata. When nothing is tagged with `:focus`, all examples # # get run.
# get run. # config.filter_run :focus
config.filter_run :focus # config.run_all_when_everything_filtered = true
config.run_all_when_everything_filtered = true #
# # Many RSpec users commonly either run the entire suite or an individual
# Many RSpec users commonly either run the entire suite or an individual # # file, and it's useful to allow more verbose output when running an
# file, and it's useful to allow more verbose output when running an # # individual spec file.
# individual spec file. # if config.files_to_run.one?
if config.files_to_run.one? # # Use the documentation formatter for detailed output,
# Use the documentation formatter for detailed output, # # unless a formatter has already been configured
# unless a formatter has already been configured # # (e.g. via a command-line flag).
# (e.g. via a command-line flag). # config.default_formatter = 'doc'
config.default_formatter = 'doc' # end
end #
# # Print the 10 slowest examples and example groups at the
# Print the 10 slowest examples and example groups at the # # end of the spec run, to help surface which specs are running
# end of the spec run, to help surface which specs are running # # particularly slow.
# particularly slow. # config.profile_examples = 10
config.profile_examples = 10 #
# # Run specs in random order to surface order dependencies. If you find an
# Run specs in random order to surface order dependencies. If you find an # # order dependency and want to debug it, you can fix the order by providing
# order dependency and want to debug it, you can fix the order by providing # # the seed, which is printed after each run.
# the seed, which is printed after each run. # # --seed 1234
# --seed 1234 # config.order = :random
config.order = :random #
# # Seed global randomization in this process using the `--seed` CLI option.
# Seed global randomization in this process using the `--seed` CLI option. # # Setting this allows you to use `--seed` to deterministically reproduce
# Setting this allows you to use `--seed` to deterministically reproduce # # test failures related to randomization by passing the same `--seed` value
# test failures related to randomization by passing the same `--seed` value # # as the one that triggered the failure.
# as the one that triggered the failure. # Kernel.srand config.seed
Kernel.srand config.seed #
# # rspec-expectations config goes here. You can use an alternate
# rspec-expectations config goes here. You can use an alternate # # assertion/expectation library such as wrong or the stdlib/minitest
# assertion/expectation library such as wrong or the stdlib/minitest # # assertions if you prefer.
# assertions if you prefer. # config.expect_with :rspec do |expectations|
config.expect_with :rspec do |expectations| # # Enable only the newer, non-monkey-patching expect syntax.
# Enable only the newer, non-monkey-patching expect syntax. # # For more details, see:
# For more details, see: # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax # expectations.syntax = :expect
expectations.syntax = :expect # end
end #
# # rspec-mocks config goes here. You can use an alternate test double
# rspec-mocks config goes here. You can use an alternate test double # # library (such as bogus or mocha) by changing the `mock_with` option here.
# library (such as bogus or mocha) by changing the `mock_with` option here. # config.mock_with :rspec do |mocks|
config.mock_with :rspec do |mocks| # # Enable only the newer, non-monkey-patching expect syntax.
# Enable only the newer, non-monkey-patching expect syntax. # # For more details, see:
# For more details, see: # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # mocks.syntax = :expect
mocks.syntax = :expect #
# # Prevents you from mocking or stubbing a method that does not exist on
# Prevents you from mocking or stubbing a method that does not exist on # # a real object. This is generally recommended.
# a real object. This is generally recommended. # mocks.verify_partial_doubles = true
mocks.verify_partial_doubles = true # end
end
=end
end end

View file

@ -1,28 +1,24 @@
module Epp module Epp
def read_body filename def read_body(filename)
File.read("spec/epp/requests/#{filename}") File.read("spec/epp/requests/#{filename}")
end end
# handles connection and login automatically # handles connection and login automatically
def epp_request(data, type=:filename) def epp_request(data, type = :filename)
begin
return parse_response(server.request(read_body(data))) if type == :filename return parse_response(server.request(read_body(data))) if type == :filename
return parse_response(server.request(data)) return parse_response(server.request(data))
rescue Exception => e rescue => e
e e
end end
end
def epp_plain_request(data, type=:filename) def epp_plain_request(data, type = :filename)
begin
return parse_response(server.send_request(read_body(data))) if type == :filename return parse_response(server.send_request(read_body(data))) if type == :filename
return parse_response(server.send_request(data)) return parse_response(server.send_request(data))
rescue Exception => e rescue => e
e e
end end
end
def parse_response raw def parse_response(raw)
res = Nokogiri::XML(raw) res = Nokogiri::XML(raw)
obj = { obj = {
@ -33,7 +29,7 @@ module Epp
} }
res.css('epp response result').each do |x| res.css('epp response result').each do |x|
obj[:results] << {result_code: x[:code], msg: x.css('msg').text, value: x.css('value > *').try(:first).try(:text)} obj[:results] << { result_code: x[:code], msg: x.css('msg').text, value: x.css('value > *').try(:first).try(:text) }
end end
obj[:result_code] = obj[:results][0][:result_code] obj[:result_code] = obj[:results][0][:result_code]
@ -42,26 +38,26 @@ module Epp
obj obj
end end
#print output # print output
def po(r) def po(r)
puts r[:parsed].to_s puts r[:parsed].to_s
end end
### REQUEST TEMPLATES ### ### REQUEST TEMPLATES ###
def domain_create_xml(xml_params={}) def domain_create_xml(xml_params = {})
xml_params[:nameservers] = xml_params[:nameservers] || [{hostObj: 'ns1.example.net'}, {hostObj: 'ns2.example.net'}] xml_params[:nameservers] = xml_params[:nameservers] || [{ hostObj: 'ns1.example.net' }, { hostObj: 'ns2.example.net' }]
xml_params[:contacts] = xml_params[:contacts] || [ xml_params[:contacts] = xml_params[:contacts] || [
{contact_value: 'sh8013', contact_type: 'admin'}, { contact_value: 'sh8013', contact_type: 'admin' },
{contact_value: 'sh8013', contact_type: 'tech'}, { contact_value: 'sh8013', contact_type: 'tech' },
{contact_value: 'sh801333', contact_type: 'tech'} { contact_value: 'sh801333', contact_type: 'tech' }
] ]
# {hostAttr: {hostName: 'ns1.example.net', hostAddr_value: '192.0.2.2', hostAddr_ip}} # {hostAttr: {hostName: 'ns1.example.net', hostAddr_value: '192.0.2.2', hostAddr_ip}}
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no') xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do xml.command do
xml.create do xml.create do
@ -93,10 +89,10 @@ module Epp
end end
end end
def domain_renew_xml(xml_params={}) def domain_renew_xml(xml_params = {})
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no') xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do xml.command do
xml.renew do xml.renew do
@ -111,11 +107,11 @@ module Epp
end end
end end
def domain_check_xml(xml_params={}) def domain_check_xml(xml_params = {})
xml_params[:names] = xml_params[:names] || ['example.ee'] xml_params[:names] = xml_params[:names] || ['example.ee']
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no') xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do xml.command do
xml.check do xml.check do
@ -130,14 +126,14 @@ module Epp
end end
end end
def domain_info_xml(xml_params={}) def domain_info_xml(xml_params = {})
xml_params[:name_value] = xml_params[:name_value] || 'example.ee' xml_params[:name_value] = xml_params[:name_value] || 'example.ee'
xml_params[:name_hosts] = xml_params[:name_hosts] || 'all' xml_params[:name_hosts] = xml_params[:name_hosts] || 'all'
xml_params[:pw] = xml_params[:pw] || '2fooBAR' xml_params[:pw] = xml_params[:pw] || '2fooBAR'
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no') xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do xml.command do
xml.info do xml.info do

View file

@ -1,8 +1,6 @@
module EppContactXmlBuilder module EppContactXmlBuilder
def contact_check_xml(xml_params = {})
def contact_check_xml(xml_params={}) xml_params[:ids] = xml_params[:ids] || [{ id: 'check-1234' }, { id: 'check-4321' }]
xml_params[:ids] = xml_params[:ids] || [ { id: 'check-1234' }, { id: 'check-4321' } ]
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
@ -23,15 +21,14 @@ module EppContactXmlBuilder
end end
end end
def contact_create_xml(xml_params={}) def contact_create_xml(xml_params = {})
#xml_params[:ids] = xml_params[:ids] || [ { id: 'check-1234' }, { id: 'check-4321' } ] # xml_params[:ids] = xml_params[:ids] || [ { id: 'check-1234' }, { id: 'check-4321' } ]
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
xml_params[:addr] = xml_params[:addr] || { street: '123 Example Dr.', street2: 'Suite 100', street3: nil, xml_params[:addr] = xml_params[:addr] || { street: '123 Example Dr.', street2: 'Suite 100', street3: nil,
city: 'Megaton' , sp: 'F3 ' , pc: '201-33' , cc: 'EE' } city: 'Megaton', sp: 'F3 ', pc: '201-33', cc: 'EE' }
xml_params[:authInfo] = xml_params[:authInfo] || { pw: 'Aas34fq' } xml_params[:authInfo] = xml_params[:authInfo] || { pw: 'Aas34fq' }
xml.instruct!(:xml, standalone: 'no') xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do xml.command do
@ -40,31 +37,31 @@ module EppContactXmlBuilder
xml.tag!('contact:id', xml_params[:id], 'sh8013') unless xml_params[:id] == false xml.tag!('contact:id', xml_params[:id], 'sh8013') unless xml_params[:id] == false
unless xml_params[:postalInfo] == [false] unless xml_params[:postalInfo] == [false]
xml.tag!('contact:postalInfo') do xml.tag!('contact:postalInfo') do
xml.tag!('contact:name', ( xml_params[:name] || 'Sillius Soddus' )) unless xml_params[:name] == false xml.tag!('contact:name', ( xml_params[:name] || 'Sillius Soddus')) unless xml_params[:name] == false
xml.tag!('contact:org', ( xml_params[:org_name] || 'Example Inc.' )) unless xml_params[:org_name] == false xml.tag!('contact:org', ( xml_params[:org_name] || 'Example Inc.')) unless xml_params[:org_name] == false
unless xml_params[:addr] == [false] unless xml_params[:addr] == [false]
xml.tag!('contact:addr') do xml.tag!('contact:addr') do
xml.tag!('contact:street', xml_params[:addr][:street] ) unless xml_params[:addr][:street] == false xml.tag!('contact:street', xml_params[:addr][:street]) unless xml_params[:addr][:street] == false
xml.tag!('contact:street', xml_params[:addr][:street2] ) unless xml_params[:addr][:street2] == false xml.tag!('contact:street', xml_params[:addr][:street2]) unless xml_params[:addr][:street2] == false
xml.tag!('contact:street', xml_params[:addr][:street3] ) unless xml_params[:addr][:street3] == false xml.tag!('contact:street', xml_params[:addr][:street3]) unless xml_params[:addr][:street3] == false
xml.tag!('contact:city' , xml_params[:addr][:city] ) unless xml_params[:addr][:city] == false xml.tag!('contact:city', xml_params[:addr][:city]) unless xml_params[:addr][:city] == false
xml.tag!('contact:sp' , xml_params[:addr][:sp] ) unless xml_params[:addr][:sp] == false xml.tag!('contact:sp', xml_params[:addr][:sp]) unless xml_params[:addr][:sp] == false
xml.tag!('contact:pc' , xml_params[:addr][:pc] ) unless xml_params[:addr][:pc] == false xml.tag!('contact:pc', xml_params[:addr][:pc]) unless xml_params[:addr][:pc] == false
xml.tag!('contact:cc' , xml_params[:addr][:cc] ) unless xml_params[:addr][:cc] == false xml.tag!('contact:cc', xml_params[:addr][:cc]) unless xml_params[:addr][:cc] == false
end end
end end
end end
end end
xml.tag!('contact:voice', (xml_params[:voice] || '+372.1234567')) unless xml_params[:voice] == false xml.tag!('contact:voice', (xml_params[:voice] || '+372.1234567')) unless xml_params[:voice] == false
xml.tag!('contact:fax', (xml_params[:fax] || '123123' )) unless xml_params[:fax] == false xml.tag!('contact:fax', (xml_params[:fax] || '123123')) unless xml_params[:fax] == false
xml.tag!('contact:email', (xml_params[:email] || 'example@test.example')) unless xml_params[:email] == false xml.tag!('contact:email', (xml_params[:email] || 'example@test.example')) unless xml_params[:email] == false
xml.tag!('contact:ident', (xml_params[:ident] || '37605030299'), type: 'op') unless xml_params[:ident] == false xml.tag!('contact:ident', (xml_params[:ident] || '37605030299'), type: 'op') unless xml_params[:ident] == false
unless xml_params[:authInfo] == [false] unless xml_params[:authInfo] == [false]
xml.tag!('contact:authInfo') do xml.tag!('contact:authInfo') do
xml.tag!('contact:pw', xml_params[:authInfo][:pw] ) unless xml_params[:authInfo][:pw] == false xml.tag!('contact:pw', xml_params[:authInfo][:pw]) unless xml_params[:authInfo][:pw] == false
end end
end end
#Disclosure logic # Disclosure logic
end end
end end
xml.clTRID 'ABC-12345' xml.clTRID 'ABC-12345'
@ -72,20 +69,20 @@ module EppContactXmlBuilder
end end
end end
#CONTACT UPDATE NEEDS WORK USE ON YOUR OWN RISK # CONTACT UPDATE NEEDS WORK USE ON YOUR OWN RISK
def contact_update_xml(xml_params={}) def contact_update_xml(xml_params = {})
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
#postalInfo = xml_params.try(:chg).try(:postalInfo) # postalInfo = xml_params.try(:chg).try(:postalInfo)
#addr = postalInfo.try(:addr) # addr = postalInfo.try(:addr)
postalInfo = xml_params[:chg][:postalInfo] rescue nil postalInfo = xml_params[:chg][:postalInfo] rescue nil
addr = postalInfo[:addr] rescue nil addr = postalInfo[:addr] rescue nil
if !addr unless addr
addr = { street: 'Downtown', city: 'Stockholm', cc: 'SE' } addr = { street: 'Downtown', city: 'Stockholm', cc: 'SE' }
end end
if !postalInfo unless postalInfo
postalInfo = { name: 'Jane Doe', org: 'Fake Inc.', voice: '+321.12345', fax: '12312312', addr: addr } postalInfo = { name: 'Jane Doe', org: 'Fake Inc.', voice: '+321.12345', fax: '12312312', addr: addr }
end end
@ -96,37 +93,36 @@ module EppContactXmlBuilder
xml_params[:chg][:authInfo] = xml_params[:chg][:authInfo] || { pw: 'ccds4324pok' } xml_params[:chg][:authInfo] = xml_params[:chg][:authInfo] || { pw: 'ccds4324pok' }
xml.instruct!(:xml, standalone: 'no') xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do xml.command do
xml.update do xml.update do
xml.tag!('contact:update', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do xml.tag!('contact:update', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
xml.tag!('contact:id', (xml_params[:id] || 'sh8013') ) unless xml_params[:id] == false xml.tag!('contact:id', (xml_params[:id] || 'sh8013')) unless xml_params[:id] == false
unless xml_params[:chg] == [ false ] unless xml_params[:chg] == [false]
xml.tag!('contact:chg') do xml.tag!('contact:chg') do
xml.tag!('contact:voice', xml_params[:chg][:phone] || '+123.321123' ) unless xml_params[:chg][:phone] == false xml.tag!('contact:voice', xml_params[:chg][:phone] || '+123.321123') unless xml_params[:chg][:phone] == false
xml.tag!('contact:email', xml_params[:chg][:email] || 'jane@doe.com' ) unless xml_params[:chg][:email] == false xml.tag!('contact:email', xml_params[:chg][:email] || 'jane@doe.com') unless xml_params[:chg][:email] == false
unless xml_params[:chg][:postalInfo] == false unless xml_params[:chg][:postalInfo] == false
xml.tag!('contact:postalInfo') do xml.tag!('contact:postalInfo') do
xml.tag!('contact:name', xml_params[:chg][:postalInfo][:name] ) unless xml_params[:chg][:postalInfo][:name] == false xml.tag!('contact:name', xml_params[:chg][:postalInfo][:name]) unless xml_params[:chg][:postalInfo][:name] == false
xml.tag!('contact:org', xml_params[:chg][:postalInfo][:org] ) unless xml_params[:chg][:postalInfo][:org] == false xml.tag!('contact:org', xml_params[:chg][:postalInfo][:org]) unless xml_params[:chg][:postalInfo][:org] == false
unless xml_params[:chg][:postalInfo][:addr] == false unless xml_params[:chg][:postalInfo][:addr] == false
xml.tag!('contact:addr') do xml.tag!('contact:addr') do
xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street] ) unless xml_params[:chg][:postalInfo][:addr][:street] == false xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street]) unless xml_params[:chg][:postalInfo][:addr][:street] == false
xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street2] ) unless xml_params[:chg][:postalInfo][:addr][:street2] == false xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street2]) unless xml_params[:chg][:postalInfo][:addr][:street2] == false
xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street3] ) unless xml_params[:chg][:postalInfo][:addr][:street3] == false xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street3]) unless xml_params[:chg][:postalInfo][:addr][:street3] == false
xml.tag!('contact:city' , xml_params[:chg][:postalInfo][:addr][:city] ) unless xml_params[:chg][:postalInfo][:addr][:city] == false xml.tag!('contact:city', xml_params[:chg][:postalInfo][:addr][:city]) unless xml_params[:chg][:postalInfo][:addr][:city] == false
xml.tag!('contact:sp' , xml_params[:chg][:postalInfo][:addr][:sp] ) unless xml_params[:chg][:postalInfo][:addr][:sp] == false xml.tag!('contact:sp', xml_params[:chg][:postalInfo][:addr][:sp]) unless xml_params[:chg][:postalInfo][:addr][:sp] == false
xml.tag!('contact:pc' , xml_params[:chg][:postalInfo][:addr][:pc] ) unless xml_params[:chg][:postalInfo][:addr][:pc] == false xml.tag!('contact:pc', xml_params[:chg][:postalInfo][:addr][:pc]) unless xml_params[:chg][:postalInfo][:addr][:pc] == false
xml.tag!('contact:cc' , xml_params[:chg][:postalInfo][:addr][:cc] ) unless xml_params[:chg][:postalInfo][:addr][:cc] == false xml.tag!('contact:cc', xml_params[:chg][:postalInfo][:addr][:cc]) unless xml_params[:chg][:postalInfo][:addr][:cc] == false
end end
end end
end end
end end
unless xml_params[:chg][:authInfo] == [false] unless xml_params[:chg][:authInfo] == [false]
xml.tag!('contact:authInfo') do xml.tag!('contact:authInfo') do
xml.tag!('contact:pw', xml_params[:chg][:authInfo][:pw] ) unless xml_params[:chg][:authInfo][:pw] == false xml.tag!('contact:pw', xml_params[:chg][:authInfo][:pw]) unless xml_params[:chg][:authInfo][:pw] == false
end end
end end
end end