diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index ef514ca..0a8be18 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -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 diff --git a/spec/lib/diaspora_federation/entities/relayable_spec.rb b/spec/lib/diaspora_federation/entities/relayable_spec.rb index 8b5ad77..1bcf51a 100644 --- a/spec/lib/diaspora_federation/entities/relayable_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_spec.rb @@ -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 + + #{author} + #{guid} + #{parent_guid} + #{property} + + 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