Only add optional nil values to relayable XML when needed for signature order
This commit is contained in:
parent
f5ff4a71e6
commit
bb40d6190d
3 changed files with 41 additions and 2 deletions
|
|
@ -100,7 +100,9 @@ module DiasporaFederation
|
||||||
# The order for signing
|
# The order for signing
|
||||||
# @return [Array]
|
# @return [Array]
|
||||||
def signature_order
|
def signature_order
|
||||||
@signature_order || self.class.class_props.keys - %i[author_signature parent_author_signature parent]
|
@signature_order || self.class.class_props.keys.reject {|key|
|
||||||
|
self.class.optional_props.include?(key) && public_send(key).nil?
|
||||||
|
} - %i[author_signature parent_author_signature parent]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
include Entities::Relayable
|
include Entities::Relayable
|
||||||
|
|
||||||
property :property, :string
|
property :property, :string, optional: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,43 @@ XML
|
||||||
expect(xml.at_xpath("new_property").text).to be_empty
|
expect(xml.at_xpath("new_property").text).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "adds nil properties to xml when needed for signature_order" do
|
||||||
|
expected_xml = <<-XML
|
||||||
|
<some_relayable>
|
||||||
|
<author>#{author}</author>
|
||||||
|
<guid>#{guid}</guid>
|
||||||
|
<parent_guid>#{parent_guid}</parent_guid>
|
||||||
|
<property/>
|
||||||
|
<new_property>#{new_property}</new_property>
|
||||||
|
<author_signature>aa</author_signature>
|
||||||
|
<parent_author_signature>bb</parent_author_signature>
|
||||||
|
</some_relayable>
|
||||||
|
XML
|
||||||
|
|
||||||
|
signature_order = [:author, :guid, :parent_guid, :property, "new_property"]
|
||||||
|
xml = Entities::SomeRelayable.new(
|
||||||
|
hash_with_fake_signatures.merge(property: nil), signature_order, "new_property" => new_property
|
||||||
|
).to_xml
|
||||||
|
|
||||||
|
expect(xml.to_s.strip).to eq(expected_xml.strip)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not add nil properties to xml when not needed for signature_order" do
|
||||||
|
expected_xml = <<-XML
|
||||||
|
<some_relayable>
|
||||||
|
<author>#{author}</author>
|
||||||
|
<guid>#{guid}</guid>
|
||||||
|
<parent_guid>#{parent_guid}</parent_guid>
|
||||||
|
<author_signature>aa</author_signature>
|
||||||
|
<parent_author_signature>bb</parent_author_signature>
|
||||||
|
</some_relayable>
|
||||||
|
XML
|
||||||
|
|
||||||
|
xml = Entities::SomeRelayable.new(hash_with_fake_signatures.merge(property: nil)).to_xml
|
||||||
|
|
||||||
|
expect(xml.to_s.strip).to eq(expected_xml.strip)
|
||||||
|
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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue