Merge branch 'master' of github.com:domify/registry

This commit is contained in:
Priit Tark 2015-06-03 16:47:54 +03:00
commit a262e1e708
8 changed files with 45 additions and 16 deletions

View file

@ -77,7 +77,7 @@ class Epp::DomainsController < EppController
end end
def renew def renew
authorize! :renew, Epp::Domain authorize! :renew, @domain
handle_errors(@domain) and return unless @domain.renew( handle_errors(@domain) and return unless @domain.renew(
params[:parsed_frame].css('curExpDate').text, params[:parsed_frame].css('curExpDate').text,

View file

@ -28,7 +28,7 @@ class Ability
can(:info, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || pw.blank? ? true : d.auth_info == pw } can(:info, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || pw.blank? ? true : d.auth_info == pw }
can(:check, Epp::Domain) can(:check, Epp::Domain)
can(:create, Epp::Domain) can(:create, Epp::Domain)
can(:renew, Epp::Domain) can(:renew, Epp::Domain) { |d| d.registrar_id == @user.registrar_id }
can(:update, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw } can(:update, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw }
can(:transfer, Epp::Domain) { |d, pw| d.auth_info == pw } can(:transfer, Epp::Domain) { |d, pw| d.auth_info == pw }
can(:view_password, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw } can(:view_password, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw }

View file

@ -148,10 +148,10 @@ class Contact < ActiveRecord::Base
end end
# rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/CyclomaticComplexity
# used only for contact trasphere # used only for contact transfer
def generate_new_code! def generate_new_code!
return nil if registrar.blank? return nil if registrar.blank?
registrar.reload # for contact transfere registrar.reload # for contact transfer
self[:code] = "#{registrar.code}:#{SecureRandom.hex(4)}".upcase self[:code] = "#{registrar.code}:#{SecureRandom.hex(4)}".upcase
end end

View file

@ -467,7 +467,8 @@ class Epp::Domain < Domain
oc = c.deep_clone include: [:statuses] oc = c.deep_clone include: [:statuses]
oc.code = nil oc.code = nil
oc.registrar_id = registrar_id oc.registrar_id = registrar_id
oc.save! oc.prefix_code
oc.save!(validate: false)
oc oc
end end
@ -475,7 +476,7 @@ class Epp::Domain < Domain
oc = Contact.find(contact_id) # n+1 workaround oc = Contact.find(contact_id) # n+1 workaround
oc.registrar_id = registrar_id oc.registrar_id = registrar_id
oc.generate_new_code! oc.generate_new_code!
oc.save! oc.save!(validate: false)
oc oc
end end
@ -548,8 +549,9 @@ class Epp::Domain < Domain
save!(validate: false) save!(validate: false)
return dt return dt
rescue => _e rescue => e
add_epp_error('2306', nil, nil, I18n.t('action_failed_due_to_server_error')) add_epp_error('2306', nil, nil, I18n.t('action_failed_due_to_server_error'))
logger.error('DOMAIN TRANSFER FAILED')
logger.error(e) logger.error(e)
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end

View file

@ -31,9 +31,8 @@ class DomainNameValidator < ActiveModel::EachValidator
# rubocop: disable Metrics/LineLength # rubocop: disable Metrics/LineLength
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ # äõöüšž unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ # äõöüšž
regexp = /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/ regexp = /\A[a-zA-Z0-9#{unicode_chars.source}][a-zA-Z0-9#{unicode_chars.source}-]{0,61}[a-zA-Z0-9#{unicode_chars.source}]#{general_domains.source}\z/
# rubocop: enable Metrics/LineLength # rubocop: enable Metrics/LineLength
# rubocop: disable Style/DoubleNegation # rubocop: disable Style/DoubleNegation
!!(value =~ regexp) !!(value =~ regexp)
# rubocop: enable Style/DoubleNegation # rubocop: enable Style/DoubleNegation

View file

@ -1,4 +1,5 @@
- content_for :actions do - content_for :actions do
- if @data.css('pw').text.present?
= link_to(t(:edit), edit_registrar_domains_path(domain_name: params[:domain_name]), = link_to(t(:edit), edit_registrar_domains_path(domain_name: params[:domain_name]),
class: 'btn btn-default') class: 'btn btn-default')
= link_to(t(:renew), renew_registrar_domains_path(domain_name: params[:domain_name]), = link_to(t(:renew), renew_registrar_domains_path(domain_name: params[:domain_name]),

View file

@ -1993,6 +1993,21 @@ describe 'EPP Domain', epp: true do
response[:results][0][:value].should == '4' response[:results][0][:value].should == '4'
end end
it 'does not renew foreign domain' do
login_as :registrar2 do
exp_date = 1.year.since.to_date
xml = @epp_xml.domain.renew(
name: { value: domain.name },
curExpDate: { value: exp_date.to_s },
period: { value: '1', attrs: { unit: 'y' } }
)
response = epp_plain_request(xml)
response[:results][0][:msg].should == 'Authorization error'
response[:results][0][:result_code].should == '2201'
end
end
### INFO ### ### INFO ###
it 'returns domain info' do it 'returns domain info' do
domain.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.') domain.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.')

View file

@ -294,6 +294,18 @@ describe Domain do
d.errors.full_messages.should == ["Domain name Domain name is invalid"] d.errors.full_messages.should == ["Domain name Domain name is invalid"]
end end
it 'should not be valid with at character' do
d = Fabricate.build(:domain, name: 'dass@sf.ee')
d.valid?
d.errors.full_messages.should == ["Domain name Domain name is invalid"]
end
it 'should not be valid with invalid characters' do
d = Fabricate.build(:domain, name: '@ba)s(?ä_:-df.ee')
d.valid?
d.errors.full_messages.should == ["Domain name Domain name is invalid"]
end
it 'should be valid when name length is two pynicodes' do it 'should be valid when name length is two pynicodes' do
d = Fabricate.build(:domain, name: "xn--4caa.ee") d = Fabricate.build(:domain, name: "xn--4caa.ee")
d.valid? d.valid?