From 41de99bd5e4ed2779d574183a58f9ac9550c658a Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 25 Jul 2016 01:29:51 +0200 Subject: [PATCH] don't include signatures in xml_order on receive --- lib/diaspora_federation/entities/relayable.rb | 4 ++-- .../diaspora_federation/entities/relayable_spec.rb | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index ebb44d0..8669727 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -72,7 +72,7 @@ module DiasporaFederation # @param [Hash] additional_xml_elements additional xml elements # @see DiasporaFederation::Entity#initialize def initialize(data, xml_order=nil, additional_xml_elements={}) - @xml_order = xml_order + @xml_order = xml_order.try(:reject) {|name| name =~ /signature/ } @additional_xml_elements = additional_xml_elements super(data) @@ -164,7 +164,7 @@ module DiasporaFederation def signature_order 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 } + xml_order.map {|name| prop_names.include?(name) ? name.to_sym : name } else self.class::LEGACY_SIGNATURE_ORDER end diff --git a/spec/lib/diaspora_federation/entities/relayable_spec.rb b/spec/lib/diaspora_federation/entities/relayable_spec.rb index 2d70d74..1420926 100644 --- a/spec/lib/diaspora_federation/entities/relayable_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_spec.rb @@ -183,6 +183,13 @@ XML expect(xml.at_xpath("new_property").text).to be_empty end + it "filters signatures from order" do + xml_order = [:author, :guid, :parent_guid, :property, "new_property", :author_signature] + + expect(SomeRelayable.new(hash, xml_order).xml_order) + .to eq([:author, :guid, :parent_guid, :property, "new_property"]) + 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) @@ -273,12 +280,10 @@ XML ) end - it "hand over the order in the xml to the instance" do + it "hand over the order in the xml to the instance without signatures" do entity = SomeRelayable.from_xml(Nokogiri::XML::Document.parse(new_xml).root) - expect(entity.xml_order).to eq( - [:author, :guid, :parent_guid, "new_property", :property, :author_signature, :parent_author_signature] - ) + expect(entity.xml_order).to eq([:author, :guid, :parent_guid, "new_property", :property]) end it "creates Entity with empty 'additional_xml_elements' if the xml has only known properties" do