convert string in xml_order to symbol if needed

This commit is contained in:
Benjamin Neff 2016-07-23 00:10:41 +02:00
parent 6e40bd9709
commit 36a787dd87
2 changed files with 20 additions and 7 deletions

View file

@ -162,7 +162,12 @@ module DiasporaFederation
# The order for signing
# @return [Array]
def signature_order
xml_order.nil? ? self.class::LEGACY_SIGNATURE_ORDER : xml_order.reject {|name| name =~ /signature/ }
if xml_order
prop_names = self.class.class_props.keys.map(&:to_s)
xml_order.reject {|name| name =~ /signature/ }.map {|name| prop_names.include?(name) ? name.to_sym : name }
else
self.class::LEGACY_SIGNATURE_ORDER
end
end
# @return [String] signature data string

View file

@ -146,12 +146,7 @@ module DiasporaFederation
end
describe "#to_xml" do
it "adds new unknown xml elements to the xml again" do
hash.merge!(author_signature: "aa", parent_author_signature: "bb")
xml_order = [:author, :guid, :parent_guid, :property, "new_property"]
xml = SomeRelayable.new(hash, xml_order, "new_property" => new_property).to_xml
expected_xml = <<-XML
let(:expected_xml) { <<-XML }
<some_relayable>
<diaspora_handle>#{author}</diaspora_handle>
<guid>#{guid}</guid>
@ -163,6 +158,19 @@ module DiasporaFederation
</some_relayable>
XML
it "adds new unknown xml elements to the xml again" do
hash.merge!(author_signature: "aa", parent_author_signature: "bb")
xml_order = [:author, :guid, :parent_guid, :property, "new_property"]
xml = SomeRelayable.new(hash, xml_order, "new_property" => new_property).to_xml
expect(xml.to_s.strip).to eq(expected_xml.strip)
end
it "converts strings in xml_order to symbol if needed" do
hash.merge!(author_signature: "aa", parent_author_signature: "bb")
xml_order = %w(author guid parent_guid property new_property)
xml = SomeRelayable.new(hash, xml_order, "new_property" => new_property).to_xml
expect(xml.to_s.strip).to eq(expected_xml.strip)
end