mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 13:44:47 +02:00
Pull out ident parsing from Epp::Contact class
This commit is contained in:
parent
043037225b
commit
bacdebd17c
3 changed files with 132 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
||||||
require 'deserializers/xml/legal_document'
|
require 'deserializers/xml/legal_document'
|
||||||
|
require 'deserializers/xml/ident'
|
||||||
|
|
||||||
class Epp::Contact < Contact
|
class Epp::Contact < Contact
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
@ -40,8 +41,8 @@ class Epp::Contact < Contact
|
||||||
|
|
||||||
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
||||||
|
|
||||||
|
ident_attrs = ::Deserializers::Xml::Ident.new(f).call
|
||||||
at.merge!(ident_attrs(f.css('ident').first)) if new_record
|
at.merge!(ident_attrs) if new_record
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,25 +57,6 @@ class Epp::Contact < Contact
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ident_attrs(ident_frame)
|
|
||||||
return {} unless ident_attr_valid?(ident_frame)
|
|
||||||
|
|
||||||
{
|
|
||||||
ident: ident_frame.text,
|
|
||||||
ident_type: ident_frame.attr('type'),
|
|
||||||
ident_country_code: ident_frame.attr('cc')
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def ident_attr_valid?(ident_frame)
|
|
||||||
return false if ident_frame.blank?
|
|
||||||
return false if ident_frame.try('text').blank?
|
|
||||||
return false if ident_frame.attr('type').blank?
|
|
||||||
return false if ident_frame.attr('cc').blank?
|
|
||||||
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def legal_document_attrs(legal_frame)
|
def legal_document_attrs(legal_frame)
|
||||||
return [] if legal_frame.blank?
|
return [] if legal_frame.blank?
|
||||||
return [] if legal_frame.try('text').blank?
|
return [] if legal_frame.try('text').blank?
|
||||||
|
|
34
lib/deserializers/xml/ident.rb
Normal file
34
lib/deserializers/xml/ident.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
module Deserializers
|
||||||
|
module Xml
|
||||||
|
class Ident
|
||||||
|
attr_reader :frame
|
||||||
|
|
||||||
|
def initialize(frame)
|
||||||
|
@frame = frame.css('ident').first
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
if valid?
|
||||||
|
{
|
||||||
|
ident: frame.text,
|
||||||
|
ident_type: frame.attr('type'),
|
||||||
|
ident_country_code: frame.attr('cc')
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def valid?
|
||||||
|
return false if frame.blank?
|
||||||
|
return false if frame.try('text').blank?
|
||||||
|
return false if frame.attr('type').blank?
|
||||||
|
return false if frame.attr('cc').blank?
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
95
test/lib/deserializers/xml/ident_test.rb
Normal file
95
test/lib/deserializers/xml/ident_test.rb
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
require 'test_helper'
|
||||||
|
require 'deserializers/xml/ident'
|
||||||
|
|
||||||
|
class DeserializersXmlIdentTest < ActiveSupport::TestCase
|
||||||
|
def test_returns_empty_hash_when_not_present
|
||||||
|
xml_string = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<update>
|
||||||
|
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>john-001</contact:id>
|
||||||
|
<contact:chg>
|
||||||
|
<contact:postalInfo>
|
||||||
|
<contact:name>new name</contact:name>
|
||||||
|
</contact:postalInfo>
|
||||||
|
<contact:voice>+123.4</contact:voice>
|
||||||
|
<contact:email>new-email@inbox.test</contact:email>
|
||||||
|
</contact:chg>
|
||||||
|
</contact:update>
|
||||||
|
</update>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
nokogiri_frame = Nokogiri::XML(xml_string).remove_namespaces!
|
||||||
|
instance = ::Deserializers::Xml::Ident.new(nokogiri_frame)
|
||||||
|
assert_equal instance.call, {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_empty_hash_when_not_valid
|
||||||
|
xml_string = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<delete>
|
||||||
|
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>FIRST0:SH2027223711</contact:id>
|
||||||
|
<contact:authInfo>
|
||||||
|
<contact:pw>wrong password</contact:pw>
|
||||||
|
</contact:authInfo>
|
||||||
|
</contact:delete>
|
||||||
|
</delete>
|
||||||
|
<extension>
|
||||||
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
|
<eis:ident cc="EE">37605030299</eis:ident>
|
||||||
|
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
||||||
|
</eis:extdata>
|
||||||
|
</extension>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
nokogiri_frame = Nokogiri::XML(xml_string).remove_namespaces!
|
||||||
|
instance = ::Deserializers::Xml::Ident.new(nokogiri_frame)
|
||||||
|
assert_equal instance.call, {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_complete_hash_when_valid
|
||||||
|
xml_string = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<delete>
|
||||||
|
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>FIRST0:SH2027223711</contact:id>
|
||||||
|
<contact:authInfo>
|
||||||
|
<contact:pw>wrong password</contact:pw>
|
||||||
|
</contact:authInfo>
|
||||||
|
</contact:delete>
|
||||||
|
</delete>
|
||||||
|
<extension>
|
||||||
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
|
<eis:ident type="priv" cc="EE">37605030299</eis:ident>
|
||||||
|
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
||||||
|
</eis:extdata>
|
||||||
|
</extension>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
nokogiri_frame = Nokogiri::XML(xml_string).remove_namespaces!
|
||||||
|
instance = ::Deserializers::Xml::Ident.new(nokogiri_frame)
|
||||||
|
|
||||||
|
expected_result = {
|
||||||
|
ident: '37605030299',
|
||||||
|
ident_type: 'priv',
|
||||||
|
ident_country_code: 'EE'
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal instance.call, expected_result
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue