don't include signatures in xml_order on receive

This commit is contained in:
Benjamin Neff 2016-07-25 01:29:51 +02:00
parent ba129aafa3
commit 41de99bd5e
2 changed files with 11 additions and 6 deletions

View file

@ -72,7 +72,7 @@ module DiasporaFederation
# @param [Hash] additional_xml_elements additional xml elements # @param [Hash] additional_xml_elements additional xml elements
# @see DiasporaFederation::Entity#initialize # @see DiasporaFederation::Entity#initialize
def initialize(data, xml_order=nil, additional_xml_elements={}) 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 @additional_xml_elements = additional_xml_elements
super(data) super(data)
@ -164,7 +164,7 @@ module DiasporaFederation
def signature_order def signature_order
if xml_order if xml_order
prop_names = self.class.class_props.keys.map(&:to_s) 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 else
self.class::LEGACY_SIGNATURE_ORDER self.class::LEGACY_SIGNATURE_ORDER
end end

View file

@ -183,6 +183,13 @@ XML
expect(xml.at_xpath("new_property").text).to be_empty expect(xml.at_xpath("new_property").text).to be_empty
end 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 it "computes correct signatures for the entity" do
expect_callback(:fetch_private_key, author).and_return(author_pkey) expect_callback(:fetch_private_key, author).and_return(author_pkey)
expect_callback(:fetch_private_key, local_parent.author).and_return(parent_pkey) expect_callback(:fetch_private_key, local_parent.author).and_return(parent_pkey)
@ -273,12 +280,10 @@ XML
) )
end 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) entity = SomeRelayable.from_xml(Nokogiri::XML::Document.parse(new_xml).root)
expect(entity.xml_order).to eq( expect(entity.xml_order).to eq([:author, :guid, :parent_guid, "new_property", :property])
[:author, :guid, :parent_guid, "new_property", :property, :author_signature, :parent_author_signature]
)
end end
it "creates Entity with empty 'additional_xml_elements' if the xml has only known properties" do it "creates Entity with empty 'additional_xml_elements' if the xml has only known properties" do