mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 02:35:57 +02:00
All system now supports legacy CID format
This commit is contained in:
parent
1f504e08ea
commit
928ce24132
9 changed files with 137 additions and 56 deletions
|
@ -11,7 +11,7 @@ class Epp::ContactsController < EppController
|
|||
authorize! :check, Epp::Contact
|
||||
|
||||
ids = params[:parsed_frame].css('id').map(&:text)
|
||||
@results = Contact.check_availability(ids)
|
||||
@results = Epp::Contact.check_availability(ids)
|
||||
render_epp_response '/epp/contacts/check'
|
||||
end
|
||||
|
||||
|
@ -59,8 +59,9 @@ class Epp::ContactsController < EppController
|
|||
end
|
||||
|
||||
def find_contact
|
||||
code = params[:parsed_frame].css('id').text.strip.upcase
|
||||
@contact = Epp::Contact.find_by(code: code)
|
||||
code = params[:parsed_frame].css('id').text.strip.upcase.sub(/^CID:/, '')
|
||||
|
||||
@contact = Epp::Contact.find_by_epp_code(code)
|
||||
|
||||
if @contact.blank?
|
||||
epp_errors << {
|
||||
|
|
|
@ -54,21 +54,6 @@ class Contact < ActiveRecord::Base
|
|||
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v.name} (#{v.code})" } }
|
||||
end
|
||||
|
||||
def check_availability(codes)
|
||||
codes = [codes] if codes.is_a?(String)
|
||||
|
||||
res = []
|
||||
codes.each do |x|
|
||||
if Contact.find_by(code: x)
|
||||
res << { code: x, avail: 0, reason: 'in use' }
|
||||
else
|
||||
res << { code: x, avail: 1 }
|
||||
end
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
|
||||
def find_orphans
|
||||
Contact.where('
|
||||
NOT EXISTS(
|
||||
|
@ -125,7 +110,7 @@ class Contact < ActiveRecord::Base
|
|||
def code=(code)
|
||||
self[:code] = code if new_record? # cannot change code later
|
||||
end
|
||||
|
||||
|
||||
def prefix_code
|
||||
return nil if registrar.blank?
|
||||
code = self[:code]
|
||||
|
|
|
@ -6,6 +6,11 @@ class Epp::Contact < Contact
|
|||
self.inheritance_column = :sti_disabled
|
||||
|
||||
class << self
|
||||
# support legacy search
|
||||
def find_by_epp_code(code)
|
||||
find_by(code: code.sub(/^CID:/, ''))
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
# rubocop: disable Metrics/MethodLength
|
||||
|
@ -82,6 +87,22 @@ class Epp::Contact < Contact
|
|||
document_type: legal_frame.attr('type')
|
||||
}]
|
||||
end
|
||||
|
||||
def check_availability(codes)
|
||||
codes = [codes] if codes.is_a?(String)
|
||||
|
||||
res = []
|
||||
codes.each do |x|
|
||||
contact = find_by_epp_code(x)
|
||||
if contact
|
||||
res << { code: contact.code, avail: 0, reason: 'in use' }
|
||||
else
|
||||
res << { code: x, avail: 1 }
|
||||
end
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||
|
|
|
@ -84,7 +84,7 @@ class Epp::Domain < Domain
|
|||
|
||||
code = frame.css('registrant').first.try(:text)
|
||||
if code.present?
|
||||
oc = Contact.find_by(code: code).try(:id)
|
||||
oc = Epp::Contact.find_by_epp_code(code).try(:id)
|
||||
|
||||
if oc
|
||||
at[:registrant_id] = oc
|
||||
|
@ -206,7 +206,7 @@ class Epp::Domain < Domain
|
|||
frame.css('contact').each do |x|
|
||||
next if x['type'] != type
|
||||
|
||||
c = Contact.find_by(code: x.text)
|
||||
c = Epp::Contact.find_by_epp_code(x.text)
|
||||
unless c
|
||||
add_epp_error('2303', 'contact', x.text, [:domain_contacts, :not_found])
|
||||
next
|
||||
|
|
|
@ -790,6 +790,24 @@ describe 'EPP Contact', epp: true do
|
|||
ids[0].text.should == 'FIXED:CHECK-1234'
|
||||
ids[1].text.should == 'check-4321'
|
||||
end
|
||||
|
||||
it 'should support legacy CID farmat' do
|
||||
contact = Fabricate(:contact, code: 'check-LEGACY')
|
||||
contact.code.should == 'FIXED:CHECK-LEGACY'
|
||||
|
||||
response = epp_plain_request(check_multiple_legacy_contacts_xml, :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
ids = response[:parsed].css('resData chkData id')
|
||||
|
||||
ids[0].text.should == 'FIXED:CHECK-LEGACY'
|
||||
ids[1].text.should == 'FIXED:CHECK-LEGACY'
|
||||
|
||||
ids[0].attributes['avail'].text.should == '0'
|
||||
ids[1].attributes['avail'].text.should == '0'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'info command' do
|
||||
|
@ -819,10 +837,20 @@ describe 'EPP Contact', epp: true do
|
|||
end
|
||||
|
||||
it 'return info about contact' do
|
||||
@registrar1_contact = Fabricate(
|
||||
:contact, code: 'INFO-4444', registrar: @registrar1, name: 'Johnny Awesome')
|
||||
Fabricate(:contact, code: 'INFO-4444', name: 'Johnny Awesome')
|
||||
|
||||
response = info_request({ id: { value: @registrar1_contact.code } })
|
||||
response = info_request({ id: { value: 'FIXED:INFO-4444' } })
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
contact = response[:parsed].css('resData infData')
|
||||
contact.css('name').first.text.should == 'Johnny Awesome'
|
||||
end
|
||||
|
||||
it 'should honour legacy CID format' do
|
||||
Fabricate(:contact, code: 'INFO-5555', name: 'Johnny Awesome')
|
||||
|
||||
response = info_request({ id: { value: 'CID:FIXED:INFO-5555' } })
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
|
@ -937,4 +965,21 @@ describe 'EPP Contact', epp: true do
|
|||
</command>
|
||||
</epp>'
|
||||
end
|
||||
|
||||
def check_multiple_legacy_contacts_xml
|
||||
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<check>
|
||||
<contact:check
|
||||
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
||||
<contact:id>FIXED:CHECK-LEGACY</contact:id>
|
||||
<contact:id>CID:FIXED:CHECK-LEGACY</contact:id>
|
||||
</contact:check>
|
||||
</check>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1378,6 +1378,34 @@ describe 'EPP Domain', epp: true do
|
|||
d.auth_info.should == existing_pw
|
||||
end
|
||||
|
||||
it 'updates a domain with legacy CID format' do
|
||||
existing_pw = domain.auth_info
|
||||
|
||||
xml_params = {
|
||||
name: { value: domain.name },
|
||||
chg: [
|
||||
registrant: { value: 'CID:FIXED:CITIZEN_1234' }
|
||||
]
|
||||
}
|
||||
|
||||
response = epp_plain_request(domain_update_xml(xml_params, {}, {
|
||||
_anonymus: [
|
||||
legalDocument: {
|
||||
value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==',
|
||||
attrs: { type: 'pdf' }
|
||||
}
|
||||
]
|
||||
}), :xml)
|
||||
|
||||
response[:results][0][:msg].should == 'Command completed successfully'
|
||||
response[:results][0][:result_code].should == '1000'
|
||||
|
||||
d = Domain.last
|
||||
|
||||
d.registrant_code.should == 'FIXED:CITIZEN_1234'
|
||||
d.auth_info.should == existing_pw
|
||||
end
|
||||
|
||||
it 'updates domain and adds objects' do
|
||||
xml = domain_update_xml({
|
||||
name: { value: domain.name },
|
||||
|
|
|
@ -305,37 +305,6 @@ describe Contact do
|
|||
end
|
||||
end
|
||||
|
||||
describe Contact, '.check_availability' do
|
||||
before do
|
||||
Fabricate(:contact, code: 'asd12')
|
||||
Fabricate(:contact, code: 'asd13')
|
||||
end
|
||||
|
||||
it 'should return array if argument is string' do
|
||||
response = Contact.check_availability('asd12')
|
||||
response.class.should == Array
|
||||
response.length.should == 1
|
||||
end
|
||||
|
||||
it 'should return in_use and available codes' do
|
||||
code = Contact.first.code
|
||||
code_ = Contact.last.code
|
||||
|
||||
response = Contact.check_availability([code, code_, 'asd14'])
|
||||
response.class.should == Array
|
||||
response.length.should == 3
|
||||
|
||||
response[0][:avail].should == 0
|
||||
response[0][:code].should == code
|
||||
|
||||
response[1][:avail].should == 0
|
||||
response[1][:code].should == code_
|
||||
|
||||
response[2][:avail].should == 1
|
||||
response[2][:code].should == 'asd14'
|
||||
end
|
||||
end
|
||||
|
||||
describe Contact, '.destroy_orphans' do
|
||||
before do
|
||||
@contact_1 = Fabricate(:contact, code: 'asd12')
|
||||
|
|
32
spec/models/epp_contact_spec.rb
Normal file
32
spec/models/epp_contact_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Epp::Contact, '.check_availability' do
|
||||
before do
|
||||
Fabricate(:contact, code: 'asd12')
|
||||
Fabricate(:contact, code: 'asd13')
|
||||
end
|
||||
|
||||
it 'should return array if argument is string' do
|
||||
response = Epp::Contact.check_availability('asd12')
|
||||
response.class.should == Array
|
||||
response.length.should == 1
|
||||
end
|
||||
|
||||
it 'should return in_use and available codes' do
|
||||
code = Contact.first.code
|
||||
code_ = Contact.last.code
|
||||
|
||||
response = Epp::Contact.check_availability([code, code_, 'asd14'])
|
||||
response.class.should == Array
|
||||
response.length.should == 3
|
||||
|
||||
response[0][:avail].should == 0
|
||||
response[0][:code].should == code
|
||||
|
||||
response[1][:avail].should == 0
|
||||
response[1][:code].should == code_
|
||||
|
||||
response[2][:avail].should == 1
|
||||
response[2][:code].should == 'asd14'
|
||||
end
|
||||
end
|
|
@ -121,7 +121,7 @@ describe Registrar do
|
|||
i.description.should == 'add some money'
|
||||
end
|
||||
|
||||
fit 'should not allaw to use CID as code for leagcy reasons' do
|
||||
it 'should not allaw to use CID as code for leagcy reasons' do
|
||||
registrar = Fabricate.build(:registrar, code: 'CID')
|
||||
registrar.valid?
|
||||
registrar.errors.full_messages.should == ['Code is forbidden to use']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue