From 162c2cf21b6879c7096d308e2f60da6984f823b0 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sat, 23 Oct 2021 01:26:58 +0200 Subject: [PATCH] Don't add author_signature if author also is parent author This fully completes #64 --- lib/diaspora_federation/entities/relayable.rb | 5 +++-- .../entities/relayable_spec.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) 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