validate sender for retraction and relayable
This commit is contained in:
parent
c7c2957b07
commit
05cd90f073
3 changed files with 195 additions and 9 deletions
|
|
@ -27,7 +27,19 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
def sender_valid?
|
def sender_valid?
|
||||||
sender == entity.author # TODO: handle sender of relayables
|
case entity
|
||||||
|
when Entities::Retraction
|
||||||
|
case entity.target_type
|
||||||
|
when "Comment", "Like", "PollParticipation"
|
||||||
|
sender == entity.target.author || sender == entity.target.parent.author
|
||||||
|
else
|
||||||
|
sender == entity.target.author
|
||||||
|
end
|
||||||
|
when Entities::Relayable
|
||||||
|
sender == entity.author || sender == entity.parent.author
|
||||||
|
else
|
||||||
|
sender == entity.author
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe Federation::Receiver::Private do
|
describe Federation::Receiver::Private do
|
||||||
let(:recipient) { 42 }
|
let(:recipient) { 42 }
|
||||||
let(:entity) { FactoryGirl.build(:status_message_entity, public: false) }
|
let(:post) { FactoryGirl.build(:status_message_entity, public: false) }
|
||||||
let(:magic_env) { Salmon::MagicEnvelope.new(entity, entity.author) }
|
let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) }
|
||||||
|
|
||||||
describe "#receive" do
|
describe "#receive" do
|
||||||
it "receives a private post" do
|
it "receives a private post" do
|
||||||
expect_callback(:receive_entity, entity, recipient)
|
expect_callback(:receive_entity, post, recipient)
|
||||||
|
|
||||||
described_class.new(magic_env, recipient).receive
|
described_class.new(magic_env, recipient).receive
|
||||||
end
|
end
|
||||||
|
|
||||||
it "validates the sender" do
|
it "validates the sender" do
|
||||||
sender = FactoryGirl.generate(:diaspora_id)
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
bad_env = Salmon::MagicEnvelope.new(entity, sender)
|
bad_env = Salmon::MagicEnvelope.new(post, sender)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env, recipient).receive
|
described_class.new(bad_env, recipient).receive
|
||||||
|
|
@ -25,6 +25,93 @@ module DiasporaFederation
|
||||||
described_class.new(magic_env).receive
|
described_class.new(magic_env).receive
|
||||||
}.to raise_error Federation::Receiver::RecipientRequired
|
}.to raise_error Federation::Receiver::RecipientRequired
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with relayable" do
|
||||||
|
let(:comment) { FactoryGirl.build(:comment_entity, parent: FactoryGirl.build(:related_entity, public: false)) }
|
||||||
|
|
||||||
|
it "receives a comment from the author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(comment, comment.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, comment, recipient)
|
||||||
|
|
||||||
|
described_class.new(magic_env, recipient).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "receives a comment from the parent author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(comment, comment.parent.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, comment, recipient)
|
||||||
|
|
||||||
|
described_class.new(magic_env, recipient).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "validates the sender" do
|
||||||
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
|
bad_env = Salmon::MagicEnvelope.new(comment, sender)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new(bad_env, recipient).receive
|
||||||
|
}.to raise_error Federation::Receiver::InvalidSender
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with retraction" do
|
||||||
|
context "for a post" do
|
||||||
|
let(:retraction) { FactoryGirl.build(:retraction_entity, target_type: "Post") }
|
||||||
|
|
||||||
|
it "retracts a post from the author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, retraction, recipient)
|
||||||
|
|
||||||
|
described_class.new(magic_env, recipient).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "validates the sender" do
|
||||||
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
|
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new(bad_env, recipient).receive
|
||||||
|
}.to raise_error Federation::Receiver::InvalidSender
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for a comment" do
|
||||||
|
let(:retraction) {
|
||||||
|
FactoryGirl.build(
|
||||||
|
:retraction_entity,
|
||||||
|
target_type: "Comment",
|
||||||
|
target: FactoryGirl.build(:related_entity, parent: FactoryGirl.build(:related_entity))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
it "retracts a comment from the author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, retraction, recipient)
|
||||||
|
|
||||||
|
described_class.new(magic_env, recipient).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "retracts a comment from the parent author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.parent.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, retraction, recipient)
|
||||||
|
|
||||||
|
described_class.new(magic_env, recipient).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "validates the sender" do
|
||||||
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
|
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new(bad_env, recipient).receive
|
||||||
|
}.to raise_error Federation::Receiver::InvalidSender
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,110 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe Federation::Receiver::Public do
|
describe Federation::Receiver::Public do
|
||||||
let(:entity) { FactoryGirl.build(:status_message_entity) }
|
let(:post) { FactoryGirl.build(:status_message_entity) }
|
||||||
let(:magic_env) { Salmon::MagicEnvelope.new(entity, entity.author) }
|
let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) }
|
||||||
|
|
||||||
describe "#receive" do
|
describe "#receive" do
|
||||||
it "receives a public post" do
|
it "receives a public post" do
|
||||||
expect_callback(:receive_entity, entity, nil)
|
expect_callback(:receive_entity, post, nil)
|
||||||
|
|
||||||
described_class.new(magic_env).receive
|
described_class.new(magic_env).receive
|
||||||
end
|
end
|
||||||
|
|
||||||
it "validates the sender" do
|
it "validates the sender" do
|
||||||
sender = FactoryGirl.generate(:diaspora_id)
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
bad_env = Salmon::MagicEnvelope.new(entity, sender)
|
bad_env = Salmon::MagicEnvelope.new(post, sender)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env).receive
|
described_class.new(bad_env).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with relayable" do
|
||||||
|
let(:comment) { FactoryGirl.build(:comment_entity) }
|
||||||
|
|
||||||
|
it "receives a comment from the author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(comment, comment.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, comment, nil)
|
||||||
|
|
||||||
|
described_class.new(magic_env).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "receives a comment from the author parent" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(comment, comment.parent.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, comment, nil)
|
||||||
|
|
||||||
|
described_class.new(magic_env).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "validates the sender" do
|
||||||
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
|
bad_env = Salmon::MagicEnvelope.new(comment, sender)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new(bad_env).receive
|
||||||
|
}.to raise_error Federation::Receiver::InvalidSender
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with retraction" do
|
||||||
|
context "for a post" do
|
||||||
|
let(:retraction) { FactoryGirl.build(:retraction_entity, target_type: "Post") }
|
||||||
|
|
||||||
|
it "retracts a post from the author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, retraction, nil)
|
||||||
|
|
||||||
|
described_class.new(magic_env).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "validates the sender" do
|
||||||
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
|
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new(bad_env).receive
|
||||||
|
}.to raise_error Federation::Receiver::InvalidSender
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for a comment" do
|
||||||
|
let(:retraction) {
|
||||||
|
FactoryGirl.build(
|
||||||
|
:retraction_entity,
|
||||||
|
target_type: "Comment",
|
||||||
|
target: FactoryGirl.build(:related_entity, parent: FactoryGirl.build(:related_entity))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
it "retracts a comment from the author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, retraction, nil)
|
||||||
|
|
||||||
|
described_class.new(magic_env).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "retracts a comment from the parent author" do
|
||||||
|
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.parent.author)
|
||||||
|
|
||||||
|
expect_callback(:receive_entity, retraction, nil)
|
||||||
|
|
||||||
|
described_class.new(magic_env).receive
|
||||||
|
end
|
||||||
|
|
||||||
|
it "validates the sender" do
|
||||||
|
sender = FactoryGirl.generate(:diaspora_id)
|
||||||
|
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new(bad_env).receive
|
||||||
|
}.to raise_error Federation::Receiver::InvalidSender
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue