validates entity on receive if it can be public but is not
This commit is contained in:
parent
c8be9083f0
commit
a8af94f192
3 changed files with 43 additions and 0 deletions
|
|
@ -8,6 +8,10 @@ module DiasporaFederation
|
|||
# Raised, if receiving a private message without recipient.
|
||||
class RecipientRequired < RuntimeError
|
||||
end
|
||||
|
||||
# Raised, if receiving a message with public receiver which is not public but should be.
|
||||
class NotPublic < RuntimeError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,16 @@ module DiasporaFederation
|
|||
module Receiver
|
||||
# receiver for public entities
|
||||
class Public < AbstractReceiver
|
||||
private
|
||||
|
||||
def validate
|
||||
super
|
||||
raise NotPublic if entity_can_be_public_but_it_is_not?
|
||||
end
|
||||
|
||||
def entity_can_be_public_but_it_is_not?
|
||||
entity.respond_to?(:public) && !entity.public
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -105,6 +105,35 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "validates if it is public" do
|
||||
it "allows public entities" do
|
||||
public_post = FactoryGirl.build(:status_message_entity, public: true)
|
||||
magic_env = Salmon::MagicEnvelope.new(public_post, public_post.author)
|
||||
|
||||
expect_callback(:receive_entity, public_post, nil)
|
||||
|
||||
described_class.new(magic_env).receive
|
||||
end
|
||||
|
||||
it "does not allow non-public entities" do
|
||||
private_post = FactoryGirl.build(:status_message_entity, public: false)
|
||||
magic_env = Salmon::MagicEnvelope.new(private_post, private_post.author)
|
||||
|
||||
expect {
|
||||
described_class.new(magic_env).receive
|
||||
}.to raise_error Federation::Receiver::NotPublic
|
||||
end
|
||||
|
||||
it "allows entities without public flag" do
|
||||
profile = FactoryGirl.build(:profile_entity)
|
||||
magic_env = Salmon::MagicEnvelope.new(profile, profile.author)
|
||||
|
||||
expect_callback(:receive_entity, profile, nil)
|
||||
|
||||
described_class.new(magic_env).receive
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue