From cf5da6e1ab9738b7b2b3f4a64f6015af12521c9e Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 3 Feb 2016 01:58:35 +0100 Subject: [PATCH] move guid and diaspora_id to Relayable --- lib/diaspora_federation/entities/comment.rb | 12 --------- lib/diaspora_federation/entities/like.rb | 16 ++---------- lib/diaspora_federation/entities/message.rb | 12 --------- .../entities/participation.rb | 14 +--------- .../entities/poll_participation.rb | 12 --------- lib/diaspora_federation/entities/relayable.rb | 26 ++++++++++++++----- .../salmon/encrypted_slap.rb | 2 +- .../entities/comment_spec.rb | 4 +-- .../diaspora_federation/entities/like_spec.rb | 12 ++++----- .../entities/message_spec.rb | 4 +-- .../entities/participation_spec.rb | 10 +++---- .../entities/poll_participation_spec.rb | 4 +-- spec/support/shared_entity_specs.rb | 2 +- 13 files changed, 41 insertions(+), 89 deletions(-) diff --git a/lib/diaspora_federation/entities/comment.rb b/lib/diaspora_federation/entities/comment.rb index b9f4f3a..9508713 100644 --- a/lib/diaspora_federation/entities/comment.rb +++ b/lib/diaspora_federation/entities/comment.rb @@ -8,24 +8,12 @@ module DiasporaFederation # @deprecated LEGACY_SIGNATURE_ORDER = %i(guid parent_guid text diaspora_id).freeze - # @!attribute [r] guid - # a random string of at least 16 chars. - # @see Validation::Rule::Guid - # @return [String] comment guid - property :guid - include Relayable # @!attribute [r] text # @return [String] the comment text property :text - # @!attribute [r] diaspora_id - # The diaspora ID of the author. - # @see Person#diaspora_id - # @return [String] diaspora ID - property :diaspora_id, xml_name: :diaspora_handle - # The {Comment} parent is a Post # @return [String] parent type def parent_type diff --git a/lib/diaspora_federation/entities/like.rb b/lib/diaspora_federation/entities/like.rb index bf1ee42..854c213 100644 --- a/lib/diaspora_federation/entities/like.rb +++ b/lib/diaspora_federation/entities/like.rb @@ -8,32 +8,20 @@ module DiasporaFederation # @deprecated LEGACY_SIGNATURE_ORDER = %i(positive guid parent_type parent_guid diaspora_id).freeze + include Relayable + # @!attribute [r] positive # If +true+ set a like, if +false+, set a dislike (dislikes are currently not # implemented in the Diaspora frontend). # @return [Boolean] is it a like or a dislike property :positive - # @!attribute [r] guid - # a random string of at least 16 chars. - # @see Validation::Rule::Guid - # @return [String] like guid - property :guid - # @!attribute [r] parent_type # A string describing the type of the parent. # Can be "Post" or "Comment" (Comments are currently not implemented in the # Diaspora Frontend). # @return [String] parent type property :parent_type, xml_name: :target_type - - include Relayable - - # @!attribute [r] diaspora_id - # The diaspora ID of the person who posts a like - # @see Person#diaspora_id - # @return [String] diaspora ID - property :diaspora_id, xml_name: :diaspora_handle end end end diff --git a/lib/diaspora_federation/entities/message.rb b/lib/diaspora_federation/entities/message.rb index 6a168bf..dbe8348 100644 --- a/lib/diaspora_federation/entities/message.rb +++ b/lib/diaspora_federation/entities/message.rb @@ -8,12 +8,6 @@ module DiasporaFederation # @deprecated LEGACY_SIGNATURE_ORDER = %i(guid parent_guid text created_at diaspora_id conversation_guid).freeze - # @!attribute [r] guid - # a random string of at least 16 chars. - # @see Validation::Rule::Guid - # @return [String] message guid - property :guid - include Relayable # @!attribute [r] text @@ -26,12 +20,6 @@ module DiasporaFederation # @return [Time] creation time property :created_at, default: -> { Time.now.utc } - # @!attribute [r] diaspora_id - # The diaspora ID of the message author. - # @see Person#diaspora_id - # @return [String] diaspora ID - property :diaspora_id, xml_name: :diaspora_handle - # @!attribute [r] conversation_guid # guid of a conversation this message belongs to # @see Conversation#guid diff --git a/lib/diaspora_federation/entities/participation.rb b/lib/diaspora_federation/entities/participation.rb index 203c2e1..1de9e52 100644 --- a/lib/diaspora_federation/entities/participation.rb +++ b/lib/diaspora_federation/entities/participation.rb @@ -8,25 +8,13 @@ module DiasporaFederation # @deprecated LEGACY_SIGNATURE_ORDER = %i(guid parent_type parent_guid diaspora_id).freeze - # @!attribute [r] guid - # a random string of at least 16 chars. - # @see Validation::Rule::Guid - # @return [String] participation guid - property :guid + include Relayable # @!attribute [r] parent_type # a string describing a type of the target to subscribe on. # currently only "Post" is supported. # @return [String] parent type property :parent_type, xml_name: :target_type - - include Relayable - - # @!attribute [r] diaspora_id - # The diaspora ID of the person who subscribes on a post - # @see Person#diaspora_id - # @return [String] diaspora ID - property :diaspora_id, xml_name: :diaspora_handle end end end diff --git a/lib/diaspora_federation/entities/poll_participation.rb b/lib/diaspora_federation/entities/poll_participation.rb index 9504f1e..61ce0a6 100644 --- a/lib/diaspora_federation/entities/poll_participation.rb +++ b/lib/diaspora_federation/entities/poll_participation.rb @@ -8,20 +8,8 @@ module DiasporaFederation # @deprecated LEGACY_SIGNATURE_ORDER = %i(guid parent_guid diaspora_id poll_answer_guid).freeze - # @!attribute [r] guid - # a random string of at least 16 chars. - # @see Validation::Rule::Guid - # @return [String] guid - property :guid - include Relayable - # @!attribute [r] diaspora_id - # The diaspora ID of the person who voted in the poll - # @see Person#diaspora_id - # @return [String] diaspora ID - property :diaspora_id, xml_name: :diaspora_handle - # @!attribute [r] poll_answer_guid # guid of the answer selected by the user. # @see PollAnswer#guid diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index bdf48c9..c67990e 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -12,10 +12,26 @@ module DiasporaFederation # on inclusion of this module the required properties for a relayable are added to the object that includes it # + # @!attribute [r] diaspora_id + # The diaspora ID of the author. + # @see Person#diaspora_id + # @return [String] diaspora ID + # + # @!attribute [r] guid + # a random string of at least 16 chars. + # @see Validation::Rule::Guid + # @return [String] comment guid + # # @!attribute [r] parent_guid # @see StatusMessage#guid # @return [String] parent guid # + # @!attribute [r] author_signature + # Contains a signature of the entity using the private key of the author of a post itself. + # The presence of this signature is mandatory. Without it the entity won't be accepted by + # a target pod. + # @return [String] author signature + # # @!attribute [r] parent_author_signature # Contains a signature of the entity using the private key of the author of a parent post # This signature is required only when federation from upstream (parent) post author to @@ -24,18 +40,14 @@ module DiasporaFederation # # @return [String] parent author signature # - # @!attribute [r] author_signature - # Contains a signature of the entity using the private key of the author of a post itself. - # The presence of this signature is mandatory. Without it the entity won't be accepted by - # a target pod. - # @return [String] author signature - # # @param [Entity] entity the entity in which it is included def self.included(entity) entity.class_eval do + property :diaspora_id, xml_name: :diaspora_handle + property :guid property :parent_guid - property :parent_author_signature, default: nil property :author_signature, default: nil + property :parent_author_signature, default: nil end end diff --git a/lib/diaspora_federation/salmon/encrypted_slap.rb b/lib/diaspora_federation/salmon/encrypted_slap.rb index 74ee725..32d2bcf 100644 --- a/lib/diaspora_federation/salmon/encrypted_slap.rb +++ b/lib/diaspora_federation/salmon/encrypted_slap.rb @@ -54,7 +54,7 @@ module DiasporaFederation # recipient_pubkey = however_you_retrieve_the_recipients_public_key() # entity = YourEntity.new(attr: "val") # - # slap_xml = EncryptedSlap.generate_xml(author_id, author_privkey, entity, recipient_pubkey) + # slap_xml = EncryptedSlap.prepare(author_id, author_privkey, entity).generate_xml(recipient_pubkey) # # @example Parsing a Salmon Slap # recipient_privkey = however_you_retrieve_the_recipients_private_key() diff --git a/spec/lib/diaspora_federation/entities/comment_spec.rb b/spec/lib/diaspora_federation/entities/comment_spec.rb index d6c0613..a64b859 100644 --- a/spec/lib/diaspora_federation/entities/comment_spec.rb +++ b/spec/lib/diaspora_federation/entities/comment_spec.rb @@ -6,12 +6,12 @@ module DiasporaFederation let(:xml) { <<-XML + #{data[:diaspora_id]} #{data[:guid]} #{parent.guid} - #{data[:parent_author_signature]} #{data[:author_signature]} + #{data[:parent_author_signature]} #{data[:text]} - #{data[:diaspora_id]} XML } diff --git a/spec/lib/diaspora_federation/entities/like_spec.rb b/spec/lib/diaspora_federation/entities/like_spec.rb index 3097ab0..11d2e2a 100644 --- a/spec/lib/diaspora_federation/entities/like_spec.rb +++ b/spec/lib/diaspora_federation/entities/like_spec.rb @@ -13,13 +13,13 @@ module DiasporaFederation let(:xml) { <<-XML - #{data[:positive]} - #{data[:guid]} - #{parent.entity_type} - #{parent.guid} - #{data[:parent_author_signature]} - #{data[:author_signature]} #{data[:diaspora_id]} + #{data[:guid]} + #{parent.guid} + #{data[:author_signature]} + #{data[:parent_author_signature]} + #{data[:positive]} + #{parent.entity_type} XML } diff --git a/spec/lib/diaspora_federation/entities/message_spec.rb b/spec/lib/diaspora_federation/entities/message_spec.rb index 42b9dcb..92510b2 100644 --- a/spec/lib/diaspora_federation/entities/message_spec.rb +++ b/spec/lib/diaspora_federation/entities/message_spec.rb @@ -6,13 +6,13 @@ module DiasporaFederation let(:xml) { <<-XML + #{data[:diaspora_id]} #{data[:guid]} #{parent.guid} - #{data[:parent_author_signature]} #{data[:author_signature]} + #{data[:parent_author_signature]} #{data[:text]} #{data[:created_at]} - #{data[:diaspora_id]} #{data[:conversation_guid]} XML diff --git a/spec/lib/diaspora_federation/entities/participation_spec.rb b/spec/lib/diaspora_federation/entities/participation_spec.rb index b6768e9..30ef57b 100644 --- a/spec/lib/diaspora_federation/entities/participation_spec.rb +++ b/spec/lib/diaspora_federation/entities/participation_spec.rb @@ -13,12 +13,12 @@ module DiasporaFederation let(:xml) { <<-XML - #{data[:guid]} - #{parent.entity_type} - #{parent.guid} - #{data[:parent_author_signature]} - #{data[:author_signature]} #{data[:diaspora_id]} + #{data[:guid]} + #{parent.guid} + #{data[:author_signature]} + #{data[:parent_author_signature]} + #{parent.entity_type} XML } diff --git a/spec/lib/diaspora_federation/entities/poll_participation_spec.rb b/spec/lib/diaspora_federation/entities/poll_participation_spec.rb index 160fb86..d1bc5f2 100644 --- a/spec/lib/diaspora_federation/entities/poll_participation_spec.rb +++ b/spec/lib/diaspora_federation/entities/poll_participation_spec.rb @@ -8,11 +8,11 @@ module DiasporaFederation let(:xml) { <<-XML + #{data[:diaspora_id]} #{data[:guid]} #{parent.guid} - #{data[:parent_author_signature]} #{data[:author_signature]} - #{data[:diaspora_id]} + #{data[:parent_author_signature]} #{data[:poll_answer_guid]} XML diff --git a/spec/support/shared_entity_specs.rb b/spec/support/shared_entity_specs.rb index ec7795c..4830b77 100644 --- a/spec/support/shared_entity_specs.rb +++ b/spec/support/shared_entity_specs.rb @@ -80,7 +80,7 @@ shared_examples "a relayable Entity" do end it "computes correct signatures for the entity" do - signed_string = instance.to_h.map {|name, value| value.to_s unless name =~ /signature/ }.compact.join(";") + signed_string = described_class::LEGACY_SIGNATURE_ORDER.map {|name| data[name] }.join(";") xml = DiasporaFederation::Salmon::XmlPayload.pack(instance)