Don't add author_signature if author also is parent author

This fully completes #64
This commit is contained in:
Benjamin Neff 2021-10-23 01:26:58 +02:00
parent aa40c3e8cc
commit 162c2cf21b
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
2 changed files with 18 additions and 2 deletions

View file

@ -120,7 +120,7 @@ module DiasporaFederation
# @return [Hash] properties with updated signatures
def enriched_properties
super.merge(additional_data).tap do |hash|
hash[:author_signature] = author_signature || sign_with_author
hash[:author_signature] = author_signature || sign_with_author unless author == parent.root.author
end
end
@ -129,7 +129,8 @@ module DiasporaFederation
# @return [Hash] sorted xml elements
def xml_elements
data = super
order = signature_order + %i[author_signature]
order = signature_order
order += %i[author_signature] unless author == parent.root.author
order.map {|element| [element, data[element].to_s] }.to_h
end

View file

@ -237,6 +237,21 @@ module DiasporaFederation
}.to raise_error Entities::Relayable::AuthorPrivateKeyNotFound
end
it "does not add author_signature when author is also the root author" do
expected_xml = <<~XML
<some_relayable>
<author>#{author}</author>
<guid>#{guid}</guid>
<parent_guid>#{parent_guid}</parent_guid>
<property>#{property}</property>
</some_relayable>
XML
xml = Entities::SomeRelayable.new(hash.merge(parent: Fabricate(:related_entity, author: author))).to_xml
expect(xml.to_s.strip).to eq(expected_xml.strip)
end
it "adds 'false' booleans" do
expected_xml = <<~XML
<test_relayable_with_boolean>