Merge all the entities left from the @Raven24's gem.
These are: AccountDeletion, Comment, Conversation, Like, Message, RelayableRetraction, Reshare, Retraction, SignedRetraction
This commit is contained in:
parent
761534f13c
commit
f12a4c21db
48 changed files with 907 additions and 16 deletions
|
|
@ -15,3 +15,12 @@ require "diaspora_federation/entities/photo"
|
|||
require "diaspora_federation/entities/status_message"
|
||||
require "diaspora_federation/entities/request"
|
||||
require "diaspora_federation/entities/participation"
|
||||
require "diaspora_federation/entities/like"
|
||||
require "diaspora_federation/entities/comment"
|
||||
require "diaspora_federation/entities/account_deletion"
|
||||
require "diaspora_federation/entities/message"
|
||||
require "diaspora_federation/entities/conversation"
|
||||
require "diaspora_federation/entities/relayable_retraction"
|
||||
require "diaspora_federation/entities/reshare"
|
||||
require "diaspora_federation/entities/retraction"
|
||||
require "diaspora_federation/entities/signed_retraction"
|
||||
|
|
|
|||
7
lib/diaspora_federation/entities/account_deletion.rb
Normal file
7
lib/diaspora_federation/entities/account_deletion.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class AccountDeletion < Entity
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
end
|
||||
end
|
||||
end
|
||||
12
lib/diaspora_federation/entities/comment.rb
Normal file
12
lib/diaspora_federation/entities/comment.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class Comment < Entity
|
||||
property :guid
|
||||
property :parent_guid
|
||||
property :parent_author_signature
|
||||
property :author_signature
|
||||
property :text
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
end
|
||||
end
|
||||
end
|
||||
12
lib/diaspora_federation/entities/conversation.rb
Normal file
12
lib/diaspora_federation/entities/conversation.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class Conversation < Entity
|
||||
property :guid
|
||||
property :subject
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
entity :messages, [Entities::Message]
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
property :participant_ids, xml_name: :participant_handles
|
||||
end
|
||||
end
|
||||
end
|
||||
13
lib/diaspora_federation/entities/like.rb
Normal file
13
lib/diaspora_federation/entities/like.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class Like < Entity
|
||||
property :positive
|
||||
property :guid
|
||||
property :target_type
|
||||
property :parent_guid
|
||||
property :parent_author_signature
|
||||
property :author_signature
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
end
|
||||
end
|
||||
end
|
||||
14
lib/diaspora_federation/entities/message.rb
Normal file
14
lib/diaspora_federation/entities/message.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class Message < Entity
|
||||
property :guid
|
||||
property :parent_guid
|
||||
property :parent_author_signature
|
||||
property :author_signature
|
||||
property :text
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
property :conversation_guid
|
||||
end
|
||||
end
|
||||
end
|
||||
11
lib/diaspora_federation/entities/relayable_retraction.rb
Normal file
11
lib/diaspora_federation/entities/relayable_retraction.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class RelayableRetraction < Entity
|
||||
property :parent_author_signature
|
||||
property :target_guid
|
||||
property :target_type
|
||||
property :sender_id, xml_name: :sender_handle
|
||||
property :target_author_signature
|
||||
end
|
||||
end
|
||||
end
|
||||
13
lib/diaspora_federation/entities/reshare.rb
Normal file
13
lib/diaspora_federation/entities/reshare.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class Reshare < Entity
|
||||
property :root_diaspora_id # inconsistent, everywhere else it's "handle"
|
||||
property :root_guid
|
||||
property :guid
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
property :public, default: true # always true? (we only reshare public posts)
|
||||
property :created_at, default: -> { Time.now.utc }
|
||||
property :provider_display_name, default: nil
|
||||
end
|
||||
end
|
||||
end
|
||||
9
lib/diaspora_federation/entities/retraction.rb
Normal file
9
lib/diaspora_federation/entities/retraction.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class Retraction < Entity
|
||||
property :post_guid
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
property :type
|
||||
end
|
||||
end
|
||||
end
|
||||
10
lib/diaspora_federation/entities/signed_retraction.rb
Normal file
10
lib/diaspora_federation/entities/signed_retraction.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
module DiasporaFederation
|
||||
module Entities
|
||||
class SignedRetraction < Entity
|
||||
property :target_guid
|
||||
property :target_type
|
||||
property :sender_id, xml_name: :sender_handle
|
||||
property :target_author_signature
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -23,6 +23,7 @@ require "diaspora_federation/validators/rules/guid"
|
|||
require "diaspora_federation/validators/rules/not_nil"
|
||||
require "diaspora_federation/validators/rules/public_key"
|
||||
require "diaspora_federation/validators/rules/tag_count"
|
||||
require "diaspora_federation/validators/rules/diaspora_id_count"
|
||||
|
||||
module DiasporaFederation
|
||||
# Validators to perform basic sanity-checks on {DiasporaFederation::Entities federation entities}.
|
||||
|
|
@ -42,3 +43,12 @@ require "diaspora_federation/validators/photo_validator"
|
|||
require "diaspora_federation/validators/location_validator"
|
||||
require "diaspora_federation/validators/status_message_validator"
|
||||
require "diaspora_federation/validators/participation_validator"
|
||||
require "diaspora_federation/validators/like_validator"
|
||||
require "diaspora_federation/validators/comment_validator"
|
||||
require "diaspora_federation/validators/account_deletion_validator"
|
||||
require "diaspora_federation/validators/message_validator"
|
||||
require "diaspora_federation/validators/conversation_validator"
|
||||
require "diaspora_federation/validators/relayable_retraction_validator"
|
||||
require "diaspora_federation/validators/reshare_validator"
|
||||
require "diaspora_federation/validators/retraction_validator"
|
||||
require "diaspora_federation/validators/signed_retraction_validator"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class AccountDeletionValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/diaspora_federation/validators/comment_validator.rb
Normal file
20
lib/diaspora_federation/validators/comment_validator.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class CommentValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :author_signature, :not_empty
|
||||
|
||||
rule :text, [:not_empty,
|
||||
length: {maximum: 65_535}]
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
13
lib/diaspora_federation/validators/conversation_validator.rb
Normal file
13
lib/diaspora_federation/validators/conversation_validator.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class ConversationValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :participant_ids, diaspora_id_count: {maximum: 20}
|
||||
end
|
||||
end
|
||||
end
|
||||
17
lib/diaspora_federation/validators/like_validator.rb
Normal file
17
lib/diaspora_federation/validators/like_validator.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class LikeValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :author_signature, :not_empty
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
19
lib/diaspora_federation/validators/message_validator.rb
Normal file
19
lib/diaspora_federation/validators/message_validator.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class MessageValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_guid, :guid
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :author_signature, :not_empty
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :conversation_guid, :guid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class RelayableRetractionValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :parent_author_signature, :not_empty
|
||||
|
||||
rule :target_guid, :guid
|
||||
|
||||
rule :target_type, :not_empty
|
||||
|
||||
rule :sender_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :target_author_signature, :not_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
17
lib/diaspora_federation/validators/reshare_validator.rb
Normal file
17
lib/diaspora_federation/validators/reshare_validator.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class ReshareValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :root_diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :root_guid, :guid
|
||||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :public, :boolean
|
||||
end
|
||||
end
|
||||
end
|
||||
13
lib/diaspora_federation/validators/retraction_validator.rb
Normal file
13
lib/diaspora_federation/validators/retraction_validator.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class RetractionValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :post_guid, :guid
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :type, :not_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
module Validation
|
||||
module Rule
|
||||
# Rule for validating the number of Diaspora* ids in a string.
|
||||
# The evaluated string is split at ";" and the result will be counted.
|
||||
class DiasporaIdCount
|
||||
attr_reader :params
|
||||
|
||||
# @param [Hash] params
|
||||
# @option params [Fixnum] :maximum maximum allowed id count
|
||||
def initialize(params)
|
||||
unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
|
||||
raise "A number has to be specified for :maximum"
|
||||
end
|
||||
|
||||
@params = params
|
||||
end
|
||||
|
||||
def error_key
|
||||
:diaspora_id_count
|
||||
end
|
||||
|
||||
def valid_value?(value)
|
||||
ids = value.split(";")
|
||||
return false unless ids.count <= params[:maximum]
|
||||
ids.each do |id|
|
||||
return false unless DiasporaId.new.valid_value?(id)
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
module DiasporaFederation
|
||||
module Validators
|
||||
class SignedRetractionValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
rule :target_guid, :guid
|
||||
|
||||
rule :target_type, :not_empty
|
||||
|
||||
rule :sender_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :target_author_signature, :not_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -114,4 +114,77 @@ FactoryGirl.define do
|
|||
sender_id { generate(:diaspora_id) }
|
||||
recipient_id { generate(:diaspora_id) }
|
||||
end
|
||||
|
||||
factory :comment_entity, class: DiasporaFederation::Entities::Comment do
|
||||
guid
|
||||
parent_guid { generate(:guid) }
|
||||
parent_author_signature { generate(:signature) }
|
||||
author_signature { generate(:signature) }
|
||||
text "this is a very informative comment"
|
||||
diaspora_id
|
||||
end
|
||||
|
||||
factory :like_entity, class: DiasporaFederation::Entities::Like do
|
||||
positive 1
|
||||
guid
|
||||
target_type "StatusMessage"
|
||||
parent_guid { generate(:guid) }
|
||||
parent_author_signature { generate(:signature) }
|
||||
author_signature { generate(:signature) }
|
||||
diaspora_id
|
||||
end
|
||||
|
||||
factory :account_deletion_entity, class: DiasporaFederation::Entities::AccountDeletion do
|
||||
diaspora_id
|
||||
end
|
||||
|
||||
factory :conversation_entity, class: DiasporaFederation::Entities::Conversation do
|
||||
guid
|
||||
subject "this is a very informative subject"
|
||||
created_at { DateTime.now.utc }
|
||||
messages []
|
||||
diaspora_id
|
||||
participant_ids { 3.times.map { generate(:diaspora_id) }.join(";") }
|
||||
end
|
||||
|
||||
factory :message_entity, class: DiasporaFederation::Entities::Message do
|
||||
guid
|
||||
parent_guid { generate(:guid) }
|
||||
parent_author_signature { generate(:signature) }
|
||||
author_signature { generate(:signature) }
|
||||
text "this is a very informative text"
|
||||
created_at { DateTime.now.utc }
|
||||
diaspora_id
|
||||
conversation_guid { generate(:guid) }
|
||||
end
|
||||
|
||||
factory :relayable_retraction_entity, class: DiasporaFederation::Entities::RelayableRetraction do
|
||||
parent_author_signature { generate(:signature) }
|
||||
target_guid { generate(:guid) }
|
||||
target_type "StatusMessage"
|
||||
sender_id { generate(:diaspora_id) }
|
||||
target_author_signature { generate(:signature) }
|
||||
end
|
||||
|
||||
factory :reshare_entity, class: DiasporaFederation::Entities::Reshare do
|
||||
root_diaspora_id { generate(:diaspora_id) }
|
||||
root_guid { generate(:guid) }
|
||||
guid
|
||||
diaspora_id
|
||||
public(true)
|
||||
created_at { DateTime.now.utc }
|
||||
end
|
||||
|
||||
factory :retraction_entity, class: DiasporaFederation::Entities::Retraction do
|
||||
post_guid { generate(:guid) }
|
||||
diaspora_id
|
||||
type "StatusMessage"
|
||||
end
|
||||
|
||||
factory :signed_retraction_entity, class: DiasporaFederation::Entities::SignedRetraction do
|
||||
target_guid { generate(:guid) }
|
||||
target_type "StatusMessage"
|
||||
sender_id { generate(:diaspora_id) }
|
||||
target_author_signature { generate(:signature) }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::AccountDeletion do
|
||||
let(:data) { {diaspora_id: "me@goes.byebye.tld"} }
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<account_deletion>
|
||||
<diaspora_handle>me@goes.byebye.tld</diaspora_handle>
|
||||
</account_deletion>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
29
spec/lib/diaspora_federation/entities/comment_spec.rb
Normal file
29
spec/lib/diaspora_federation/entities/comment_spec.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::Comment do
|
||||
let(:data) {
|
||||
{guid: "0123456789abcdef",
|
||||
parent_guid: "fedcba9876543210",
|
||||
parent_author_signature: "BBBBBB==",
|
||||
author_signature: "AAAAAA==",
|
||||
text: "my comment text",
|
||||
diaspora_id: "bob@pod.somedomain.tld"}
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<comment>
|
||||
<guid>0123456789abcdef</guid>
|
||||
<parent_guid>fedcba9876543210</parent_guid>
|
||||
<parent_author_signature>BBBBBB==</parent_author_signature>
|
||||
<author_signature>AAAAAA==</author_signature>
|
||||
<text>my comment text</text>
|
||||
<diaspora_handle>bob@pod.somedomain.tld</diaspora_handle>
|
||||
</comment>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
54
spec/lib/diaspora_federation/entities/conversation_spec.rb
Normal file
54
spec/lib/diaspora_federation/entities/conversation_spec.rb
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::Conversation do
|
||||
before do
|
||||
@datetime = DateTime.now.utc
|
||||
end
|
||||
|
||||
let(:msg1) { Entities::Message.new(FactoryGirl.attributes_for(:message_entity)) }
|
||||
let(:msg2) { Entities::Message.new(FactoryGirl.attributes_for(:message_entity)) }
|
||||
let(:data) {
|
||||
{guid: FactoryGirl.generate(:guid),
|
||||
subject: "very interesting conversation subject",
|
||||
created_at: @datetime,
|
||||
messages: [msg1, msg2],
|
||||
diaspora_id: FactoryGirl.generate(:diaspora_id),
|
||||
participant_ids: "#{FactoryGirl.generate(:diaspora_id)};#{FactoryGirl.generate(:diaspora_id)}"}
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<conversation>
|
||||
<guid>#{data[:guid]}</guid>
|
||||
<subject>#{data[:subject]}</subject>
|
||||
<created_at>#{data[:created_at]}</created_at>
|
||||
<message>
|
||||
<guid>#{msg1.guid}</guid>
|
||||
<parent_guid>#{msg1.parent_guid}</parent_guid>
|
||||
<parent_author_signature>#{msg1.parent_author_signature}</parent_author_signature>
|
||||
<author_signature>#{msg1.author_signature}</author_signature>
|
||||
<text>#{msg1.text}</text>
|
||||
<created_at>#{msg1.created_at}</created_at>
|
||||
<diaspora_handle>#{msg1.diaspora_id}</diaspora_handle>
|
||||
<conversation_guid>#{msg1.conversation_guid}</conversation_guid>
|
||||
</message>
|
||||
<message>
|
||||
<guid>#{msg2.guid}</guid>
|
||||
<parent_guid>#{msg2.parent_guid}</parent_guid>
|
||||
<parent_author_signature>#{msg2.parent_author_signature}</parent_author_signature>
|
||||
<author_signature>#{msg2.author_signature}</author_signature>
|
||||
<text>#{msg2.text}</text>
|
||||
<created_at>#{msg2.created_at}</created_at>
|
||||
<diaspora_handle>#{msg2.diaspora_id}</diaspora_handle>
|
||||
<conversation_guid>#{msg2.conversation_guid}</conversation_guid>
|
||||
</message>
|
||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||
<participant_handles>#{data[:participant_ids]}</participant_handles>
|
||||
</conversation>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
31
spec/lib/diaspora_federation/entities/like_spec.rb
Normal file
31
spec/lib/diaspora_federation/entities/like_spec.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::Like do
|
||||
let(:data) {
|
||||
{positive: true,
|
||||
guid: "0123456789abcdef",
|
||||
target_type: "Post",
|
||||
parent_guid: "fedcba9876543210",
|
||||
parent_author_signature: "BBBBBB==",
|
||||
author_signature: "AAAAAA==",
|
||||
diaspora_id: "luke@diaspora.example.tld"}
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<like>
|
||||
<positive>true</positive>
|
||||
<guid>0123456789abcdef</guid>
|
||||
<target_type>Post</target_type>
|
||||
<parent_guid>fedcba9876543210</parent_guid>
|
||||
<parent_author_signature>BBBBBB==</parent_author_signature>
|
||||
<author_signature>AAAAAA==</author_signature>
|
||||
<diaspora_handle>luke@diaspora.example.tld</diaspora_handle>
|
||||
</like>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
24
spec/lib/diaspora_federation/entities/message_spec.rb
Normal file
24
spec/lib/diaspora_federation/entities/message_spec.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::Message do
|
||||
let(:data) { FactoryGirl.attributes_for(:message_entity) }
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<message>
|
||||
<guid>#{data[:guid]}</guid>
|
||||
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||
<author_signature>#{data[:author_signature]}</author_signature>
|
||||
<text>#{data[:text]}</text>
|
||||
<created_at>#{data[:created_at]}</created_at>
|
||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||
<conversation_guid>#{data[:conversation_guid]}</conversation_guid>
|
||||
</message>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::RelayableRetraction do
|
||||
let(:data) {
|
||||
{parent_author_signature: "AAAAAA=",
|
||||
target_guid: "0123456789abcdef",
|
||||
target_type: "Comment",
|
||||
sender_id: "luke@diaspora.example.tld",
|
||||
target_author_signature: "BBBBBB="}
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<relayable_retraction>
|
||||
<parent_author_signature>AAAAAA=</parent_author_signature>
|
||||
<target_guid>0123456789abcdef</target_guid>
|
||||
<target_type>Comment</target_type>
|
||||
<sender_handle>luke@diaspora.example.tld</sender_handle>
|
||||
<target_author_signature>BBBBBB=</target_author_signature>
|
||||
</relayable_retraction>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
35
spec/lib/diaspora_federation/entities/reshare_spec.rb
Normal file
35
spec/lib/diaspora_federation/entities/reshare_spec.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::Reshare do
|
||||
before do
|
||||
@datetime = DateTime.now.utc
|
||||
end
|
||||
|
||||
let(:data) {
|
||||
{root_diaspora_id: "robert_root@pod.example.tld",
|
||||
root_guid: "fedcba9876543210",
|
||||
guid: "0123456789abcdef",
|
||||
diaspora_id: "alice@diaspora.domain.tld",
|
||||
public: true,
|
||||
created_at: @datetime,
|
||||
provider_display_name: "mobile"}
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<reshare>
|
||||
<root_diaspora_id>robert_root@pod.example.tld</root_diaspora_id>
|
||||
<root_guid>fedcba9876543210</root_guid>
|
||||
<guid>0123456789abcdef</guid>
|
||||
<diaspora_handle>alice@diaspora.domain.tld</diaspora_handle>
|
||||
<public>true</public>
|
||||
<created_at>#{@datetime}</created_at>
|
||||
<provider_display_name>mobile</provider_display_name>
|
||||
</reshare>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
23
spec/lib/diaspora_federation/entities/retraction_spec.rb
Normal file
23
spec/lib/diaspora_federation/entities/retraction_spec.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::Retraction do
|
||||
let(:data) {
|
||||
{post_guid: "0123456789abcdef",
|
||||
diaspora_id: "luke@diaspora.example.tld",
|
||||
type: "StatusMessage"}
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<retraction>
|
||||
<post_guid>0123456789abcdef</post_guid>
|
||||
<diaspora_handle>luke@diaspora.example.tld</diaspora_handle>
|
||||
<type>StatusMessage</type>
|
||||
</retraction>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
module DiasporaFederation
|
||||
describe Entities::SignedRetraction do
|
||||
let(:data) {
|
||||
{target_guid: "0123456789abcdef",
|
||||
target_type: "StatusMessage",
|
||||
sender_id: "luke@diaspora.example.tld",
|
||||
target_author_signature: "AAAAAA=="}
|
||||
}
|
||||
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<signed_retraction>
|
||||
<target_guid>0123456789abcdef</target_guid>
|
||||
<target_type>StatusMessage</target_type>
|
||||
<sender_handle>luke@diaspora.example.tld</sender_handle>
|
||||
<target_author_signature>AAAAAA==</target_author_signature>
|
||||
</signed_retraction>
|
||||
XML
|
||||
}
|
||||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::AccountDeletionValidator do
|
||||
let(:entity) { :account_deletion_entity }
|
||||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::CommentValidator do
|
||||
let(:entity) { :comment_entity }
|
||||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
%i(guid parent_guid).each do |prop|
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
|
||||
context "#author_signature and #parent_author_signature" do
|
||||
%i(author_signature parent_author_signature).each do |prop|
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#text" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :text }
|
||||
let(:wrong_values) { ["", "a" * 65_536] }
|
||||
let(:correct_values) { ["a" * 65_535] }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::ConversationValidator do
|
||||
let(:entity) { :conversation_entity }
|
||||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :guid }
|
||||
end
|
||||
|
||||
context "participant_ids" do
|
||||
# must not contain more than 20 participant handles
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :participant_ids }
|
||||
let(:wrong_values) { [21.times.map { FactoryGirl.generate(:diaspora_id) }.join(";")] }
|
||||
let(:correct_values) { [20.times.map { FactoryGirl.generate(:diaspora_id) }.join(";")] }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::LikeValidator do
|
||||
let(:entity) { :like_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
%i(guid parent_guid).each do |prop|
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
|
||||
context "#author_signature and #parent_author_signature" do
|
||||
%i(author_signature parent_author_signature).each do |prop|
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -5,10 +5,8 @@ module DiasporaFederation
|
|||
|
||||
context "#lat and #lng" do
|
||||
%i(lat lng).each do |prop|
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
let(:wrong_values) { [""] }
|
||||
let(:correct_values) { [] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::MessageValidator do
|
||||
let(:entity) { :message_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
context "#guid, #parent_guid, #conversation_guid" do
|
||||
%i(guid parent_guid conversation_guid).each do |prop|
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#author_signature and #parent_author_signature" do
|
||||
%i(author_signature parent_author_signature).each do |prop|
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -19,10 +19,8 @@ module DiasporaFederation
|
|||
|
||||
context "#target_type and #author_signature and #parent_author_signature" do
|
||||
%i(target_type author_signature parent_author_signature).each do |prop|
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
let(:wrong_values) { [""] }
|
||||
let(:correct_values) { [] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
describe "#profile" do
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :profile }
|
||||
let(:wrong_values) { [nil] }
|
||||
let(:correct_values) { [] }
|
||||
|
|
|
|||
|
|
@ -23,17 +23,15 @@ module DiasporaFederation
|
|||
|
||||
context "#remote_photo_path, #remote_photo_name" do
|
||||
%i(remote_photo_name remote_photo_path).each do |prop|
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
let(:wrong_values) { [""] }
|
||||
let(:correct_values) { [] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#height, #width" do
|
||||
%i(height width).each do |prop|
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { prop }
|
||||
let(:wrong_values) { [true, :num, "asdf"] }
|
||||
let(:correct_values) { [123, "123"] }
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ module DiasporaFederation
|
|||
|
||||
%i(image_url image_url_medium image_url_small).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { prop }
|
||||
let(:wrong_values) { [] }
|
||||
let(:correct_values) { [nil] }
|
||||
|
|
@ -54,7 +54,7 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
describe "#birthday" do
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :birthday }
|
||||
let(:wrong_values) { ["asdf asdf", true, 1234] }
|
||||
let(:correct_values) { [nil, "", Date.parse("2013-06-29"), "2013-06-29"] }
|
||||
|
|
@ -71,7 +71,7 @@ module DiasporaFederation
|
|||
|
||||
describe "#tag_string" do
|
||||
# more than 5 tags are not allowed
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :tag_string }
|
||||
let(:wrong_values) { ["#i #have #too #many #tags #in #my #profile"] }
|
||||
let(:correct_values) { [] }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::RelayableRetractionValidator do
|
||||
let(:entity) { :relayable_retraction_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :sender_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :target_guid }
|
||||
end
|
||||
|
||||
context "#parent_author_signature, #target_author_signature" do
|
||||
%i(parent_author_signature target_author_signature).each do |prop|
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::ReshareValidator do
|
||||
let(:entity) { :reshare_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
context "#root_diaspora_id, #diaspora_id" do
|
||||
%i(root_diaspora_id diaspora_id).each do |prop|
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { prop }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#root_guid, #guid" do
|
||||
%i(root_guid guid).each do |prop|
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "a boolean validator" do
|
||||
let(:property) { :public }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::RetractionValidator do
|
||||
let(:entity) { :retraction_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :post_guid }
|
||||
end
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
context "#type" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { :type }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
describe Validation::Rule::DiasporaIdCount do
|
||||
let(:id_str) { 3.times.map { FactoryGirl.generate(:diaspora_id) }.join(";") }
|
||||
|
||||
it "requires a parameter" do
|
||||
validator = Validation::Validator.new({})
|
||||
expect {
|
||||
validator.rule(:ids, :diaspora_id_count)
|
||||
}.to raise_error ArgumentError
|
||||
end
|
||||
|
||||
it "validates less ids" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(ids: id_str))
|
||||
validator.rule(:ids, diaspora_id_count: {maximum: 5})
|
||||
|
||||
expect(validator).to be_valid
|
||||
expect(validator.errors).to be_empty
|
||||
end
|
||||
|
||||
it "fails for less but non ids" do
|
||||
bad_str = "user@example.com;i am a weird diaspora id @@@ ### 12345;shouldnt be reached by a rule"
|
||||
validator = Validation::Validator.new(OpenStruct.new(ids: bad_str))
|
||||
validator.rule(:ids, diaspora_id_count: {maximum: 5})
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(:ids)
|
||||
end
|
||||
|
||||
it "validates exactly as many ids" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(ids: id_str))
|
||||
validator.rule(:ids, diaspora_id_count: {maximum: 3})
|
||||
|
||||
expect(validator).to be_valid
|
||||
expect(validator.errors).to be_empty
|
||||
end
|
||||
|
||||
it "fails for too many ids" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(ids: id_str))
|
||||
validator.rule(:ids, diaspora_id_count: {maximum: 1})
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(:ids)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
module DiasporaFederation
|
||||
describe Validators::SignedRetractionValidator do
|
||||
let(:entity) { :signed_retraction_entity }
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :sender_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :target_guid }
|
||||
end
|
||||
|
||||
context "#target_type, #target_author_signature" do
|
||||
%i(target_type target_author_signature).each do |prop|
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { prop }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -27,7 +27,7 @@ module DiasporaFederation
|
|||
# optional urls
|
||||
%i(alias_url salmon_url).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a property with data-types restriction" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { prop }
|
||||
let(:wrong_values) { ["", "https://asdf$%.com", "example.com"] }
|
||||
let(:correct_values) { [nil] }
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ shared_examples "a common validator" do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples "a property with data-types restriction" do
|
||||
shared_examples "a property with a value validation/restriction" do
|
||||
it "fails if a wrong value is supplied" do
|
||||
wrong_values.each do |val|
|
||||
validator = described_class.new(entity_stub(entity, property => val))
|
||||
|
|
@ -34,6 +34,13 @@ shared_examples "a property with data-types restriction" do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples "a property that mustn't be empty" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:wrong_values) { ["", nil] }
|
||||
let(:correct_values) { [] }
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "a diaspora id validator" do
|
||||
it "must not be nil or empty if mandatory" do
|
||||
[nil, ""].each do |val|
|
||||
|
|
|
|||
Loading…
Reference in a new issue