mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 10:45:58 +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
|
authorize! :check, Epp::Contact
|
||||||
|
|
||||||
ids = params[:parsed_frame].css('id').map(&:text)
|
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'
|
render_epp_response '/epp/contacts/check'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,8 +59,9 @@ class Epp::ContactsController < EppController
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_contact
|
def find_contact
|
||||||
code = params[:parsed_frame].css('id').text.strip.upcase
|
code = params[:parsed_frame].css('id').text.strip.upcase.sub(/^CID:/, '')
|
||||||
@contact = Epp::Contact.find_by(code: code)
|
|
||||||
|
@contact = Epp::Contact.find_by_epp_code(code)
|
||||||
|
|
||||||
if @contact.blank?
|
if @contact.blank?
|
||||||
epp_errors << {
|
epp_errors << {
|
||||||
|
|
|
@ -54,21 +54,6 @@ class Contact < ActiveRecord::Base
|
||||||
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v.name} (#{v.code})" } }
|
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v.name} (#{v.code})" } }
|
||||||
end
|
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
|
def find_orphans
|
||||||
Contact.where('
|
Contact.where('
|
||||||
NOT EXISTS(
|
NOT EXISTS(
|
||||||
|
|
|
@ -6,6 +6,11 @@ class Epp::Contact < Contact
|
||||||
self.inheritance_column = :sti_disabled
|
self.inheritance_column = :sti_disabled
|
||||||
|
|
||||||
class << self
|
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/PerceivedComplexity
|
||||||
# rubocop: disable Metrics/CyclomaticComplexity
|
# rubocop: disable Metrics/CyclomaticComplexity
|
||||||
# rubocop: disable Metrics/MethodLength
|
# rubocop: disable Metrics/MethodLength
|
||||||
|
@ -82,6 +87,22 @@ class Epp::Contact < Contact
|
||||||
document_type: legal_frame.attr('type')
|
document_type: legal_frame.attr('type')
|
||||||
}]
|
}]
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Epp::Domain < Domain
|
||||||
|
|
||||||
code = frame.css('registrant').first.try(:text)
|
code = frame.css('registrant').first.try(:text)
|
||||||
if code.present?
|
if code.present?
|
||||||
oc = Contact.find_by(code: code).try(:id)
|
oc = Epp::Contact.find_by_epp_code(code).try(:id)
|
||||||
|
|
||||||
if oc
|
if oc
|
||||||
at[:registrant_id] = oc
|
at[:registrant_id] = oc
|
||||||
|
@ -206,7 +206,7 @@ class Epp::Domain < Domain
|
||||||
frame.css('contact').each do |x|
|
frame.css('contact').each do |x|
|
||||||
next if x['type'] != type
|
next if x['type'] != type
|
||||||
|
|
||||||
c = Contact.find_by(code: x.text)
|
c = Epp::Contact.find_by_epp_code(x.text)
|
||||||
unless c
|
unless c
|
||||||
add_epp_error('2303', 'contact', x.text, [:domain_contacts, :not_found])
|
add_epp_error('2303', 'contact', x.text, [:domain_contacts, :not_found])
|
||||||
next
|
next
|
||||||
|
|
|
@ -790,6 +790,24 @@ describe 'EPP Contact', epp: true do
|
||||||
ids[0].text.should == 'FIXED:CHECK-1234'
|
ids[0].text.should == 'FIXED:CHECK-1234'
|
||||||
ids[1].text.should == 'check-4321'
|
ids[1].text.should == 'check-4321'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'info command' do
|
context 'info command' do
|
||||||
|
@ -819,10 +837,20 @@ describe 'EPP Contact', epp: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'return info about contact' do
|
it 'return info about contact' do
|
||||||
@registrar1_contact = Fabricate(
|
Fabricate(:contact, code: 'INFO-4444', name: 'Johnny Awesome')
|
||||||
:contact, code: 'INFO-4444', registrar: @registrar1, 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[:msg].should == 'Command completed successfully'
|
||||||
response[:result_code].should == '1000'
|
response[:result_code].should == '1000'
|
||||||
|
|
||||||
|
@ -937,4 +965,21 @@ describe 'EPP Contact', epp: true do
|
||||||
</command>
|
</command>
|
||||||
</epp>'
|
</epp>'
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1378,6 +1378,34 @@ describe 'EPP Domain', epp: true do
|
||||||
d.auth_info.should == existing_pw
|
d.auth_info.should == existing_pw
|
||||||
end
|
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
|
it 'updates domain and adds objects' do
|
||||||
xml = domain_update_xml({
|
xml = domain_update_xml({
|
||||||
name: { value: domain.name },
|
name: { value: domain.name },
|
||||||
|
|
|
@ -305,37 +305,6 @@ describe Contact do
|
||||||
end
|
end
|
||||||
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
|
describe Contact, '.destroy_orphans' do
|
||||||
before do
|
before do
|
||||||
@contact_1 = Fabricate(:contact, code: 'asd12')
|
@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'
|
i.description.should == 'add some money'
|
||||||
end
|
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 = Fabricate.build(:registrar, code: 'CID')
|
||||||
registrar.valid?
|
registrar.valid?
|
||||||
registrar.errors.full_messages.should == ['Code is forbidden to use']
|
registrar.errors.full_messages.should == ['Code is forbidden to use']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue