From ba129aafa38f978f69565d39b7a881a245b03bab Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sat, 23 Jul 2016 00:29:44 +0200 Subject: [PATCH] add missing properties from xml_order to xml --- lib/diaspora_federation/entities/relayable.rb | 2 +- spec/lib/diaspora_federation/entities/relayable_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index a442788..ebb44d0 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -153,7 +153,7 @@ module DiasporaFederation # @return [Hash] sorted xml elements with updated signatures def xml_elements xml_data = super.merge(additional_xml_elements) - signature_order.map {|element| [element, xml_data[element]] }.to_h.tap do |xml_elements| + signature_order.map {|element| [element, xml_data[element] || ""] }.to_h.tap do |xml_elements| xml_elements[:author_signature] = author_signature || sign_with_author xml_elements[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s end diff --git a/spec/lib/diaspora_federation/entities/relayable_spec.rb b/spec/lib/diaspora_federation/entities/relayable_spec.rb index 5ab0fae..2d70d74 100644 --- a/spec/lib/diaspora_federation/entities/relayable_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_spec.rb @@ -174,6 +174,15 @@ XML expect(xml.to_s.strip).to eq(expected_xml.strip) end + it "adds missing properties from xml_order to xml" 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).to_xml + + expect(xml.at_xpath("new_property").text).to be_empty + end + it "computes correct signatures for the entity" do expect_callback(:fetch_private_key, author).and_return(author_pkey) expect_callback(:fetch_private_key, local_parent.author).and_return(parent_pkey)