subclassing receivers, renamed perform to perform [bang]
This commit is contained in:
parent
4a8aea9e78
commit
7926ebfb53
6 changed files with 220 additions and 222 deletions
|
|
@ -1,6 +1,9 @@
|
|||
module Postzord
|
||||
module Receiver
|
||||
class LocalBatch
|
||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class Postzord::Receiver::LocalBatch < Postzord::Receiver
|
||||
|
||||
attr_reader :object, :recipient_user_ids, :users
|
||||
|
||||
def initialize(object, recipient_user_ids)
|
||||
|
|
@ -14,6 +17,9 @@ module Postzord
|
|||
receive_relayable
|
||||
else
|
||||
create_post_visibilities
|
||||
|
||||
# if caching enabled, add to cache
|
||||
|
||||
end
|
||||
notify_mentioned_users if @object.respond_to?(:mentions)
|
||||
|
||||
|
|
@ -67,5 +73,3 @@ module Postzord
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
#
|
||||
|
||||
require File.join(Rails.root, 'lib/webfinger')
|
||||
require File.join(Rails.root, 'lib/diaspora/parser')
|
||||
|
||||
module Postzord
|
||||
module Receiver
|
||||
class Private
|
||||
class Postzord::Receiver::Private < Postzord::Receiver
|
||||
|
||||
def initialize(user, opts={})
|
||||
@user = user
|
||||
@user_person = @user.person
|
||||
|
|
@ -19,7 +18,7 @@ module Postzord
|
|||
@object = opts[:object]
|
||||
end
|
||||
|
||||
def perform
|
||||
def perform!
|
||||
if @sender && self.salmon.verified_for_key?(@sender.public_key)
|
||||
parse_and_receive(salmon.parsed_data)
|
||||
else
|
||||
|
|
@ -113,5 +112,3 @@ module Postzord
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@
|
|||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
module Postzord
|
||||
module Receiver
|
||||
class Public
|
||||
class Postzord::Receiver::Public < Postzord::Receiver
|
||||
|
||||
attr_accessor :salmon, :author
|
||||
|
||||
def initialize(xml)
|
||||
|
|
@ -60,5 +59,3 @@ module Postzord
|
|||
@object.respond_to?(:public) && !@object.public?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ describe "attack vectors" do
|
|||
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
expect {
|
||||
zord.perform
|
||||
zord.perform!
|
||||
}.should raise_error /not a valid object/
|
||||
|
||||
bob.visible_posts.include?(post_from_non_contact).should be_false
|
||||
|
|
@ -39,7 +39,7 @@ describe "attack vectors" do
|
|||
salmon_xml = bob.salmon(original_message).xml_for(alice.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
expect {
|
||||
zord.perform
|
||||
zord.perform!
|
||||
}.should raise_error /not a valid object/
|
||||
|
||||
alice.reload.visible_posts.should_not include(StatusMessage.find(original_message.id))
|
||||
|
|
@ -53,12 +53,12 @@ describe "attack vectors" do
|
|||
salmon_xml = eve.salmon(original_message).xml_for(bob.person)
|
||||
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
malicious_message = Factory.build(:status_message, :id => original_message.id, :text => 'BAD!!!', :author => alice.person)
|
||||
salmon_xml = alice.salmon(malicious_message).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
original_message.reload.text.should == "store this!"
|
||||
end
|
||||
|
|
@ -68,14 +68,14 @@ describe "attack vectors" do
|
|||
|
||||
salmon_xml = eve.salmon(original_message).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
lambda {
|
||||
malicious_message = Factory.build( :status_message, :id => original_message.id, :text => 'BAD!!!', :author => eve.person)
|
||||
|
||||
salmon_xml2 = alice.salmon(malicious_message).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
}.should_not change{
|
||||
bob.reload.visible_posts.count
|
||||
|
|
@ -97,7 +97,7 @@ describe "attack vectors" do
|
|||
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
expect {
|
||||
zord.perform
|
||||
zord.perform!
|
||||
}.should raise_error /not a valid object/
|
||||
|
||||
eve.reload.profile.first_name.should == first_name
|
||||
|
|
@ -109,7 +109,7 @@ describe "attack vectors" do
|
|||
|
||||
salmon_xml = eve.salmon(original_message).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
bob.visible_posts.count.should == 1
|
||||
StatusMessage.count.should == 1
|
||||
|
|
@ -121,7 +121,7 @@ describe "attack vectors" do
|
|||
|
||||
salmon_xml = alice.salmon(ret).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
StatusMessage.count.should == 1
|
||||
bob.visible_posts.count.should == 1
|
||||
|
|
@ -143,7 +143,7 @@ describe "attack vectors" do
|
|||
proc {
|
||||
salmon_xml = alice.salmon(ret).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
}.should_not raise_error
|
||||
end
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ describe "attack vectors" do
|
|||
|
||||
salmon_xml = eve.salmon(original_message).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
bob.visible_posts.count.should == 1
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ describe "attack vectors" do
|
|||
salmon_xml = alice.salmon(ret).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
expect {
|
||||
zord.perform
|
||||
zord.perform!
|
||||
}.should raise_error /not a valid object/
|
||||
|
||||
bob.reload.visible_posts.count.should == 1
|
||||
|
|
@ -180,7 +180,7 @@ describe "attack vectors" do
|
|||
salmon_xml = alice.salmon(ret).xml_for(bob.person)
|
||||
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
}.should_not change{bob.reload.contacts.count}
|
||||
end
|
||||
|
|
@ -196,7 +196,7 @@ describe "attack vectors" do
|
|||
salmon_xml = alice.salmon(ret).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
expect {
|
||||
zord.perform
|
||||
zord.perform!
|
||||
}.should raise_error /not a valid object/
|
||||
|
||||
bob.reload.contacts.count.should == 2
|
||||
|
|
@ -207,7 +207,7 @@ describe "attack vectors" do
|
|||
|
||||
salmon_xml = eve.salmon(original_message).xml_for(bob.person)
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
original_message.diaspora_handle = alice.diaspora_handle
|
||||
original_message.text= "bad bad bad"
|
||||
|
|
@ -215,7 +215,7 @@ describe "attack vectors" do
|
|||
salmon_xml = alice.salmon(original_message).xml_for(bob.person)
|
||||
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
original_message.reload.text.should == "store this!"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ describe 'a user receives a post' do
|
|||
salmon_xml = salmon.xml_for(bob.person)
|
||||
|
||||
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
zord.perform!
|
||||
|
||||
bob.visible_posts.include?(post).should be_true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ describe Postzord::Receiver::Private do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
describe '#perform!' do
|
||||
before do
|
||||
@zord = Postzord::Receiver::Private.new(@user, :salmon_xml => @salmon_xml)
|
||||
@salmon = @zord.instance_variable_get(:@salmon)
|
||||
|
|
@ -56,25 +56,25 @@ describe Postzord::Receiver::Private do
|
|||
context 'returns nil' do
|
||||
it 'if the salmon author does not exist' do
|
||||
@zord.instance_variable_set(:@sender, nil)
|
||||
@zord.perform.should be_nil
|
||||
@zord.perform!.should be_nil
|
||||
end
|
||||
|
||||
it 'if the author does not match the signature' do
|
||||
@zord.instance_variable_set(:@sender, Factory(:person))
|
||||
@zord.perform.should be_nil
|
||||
@zord.perform!.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns the sent object' do
|
||||
it 'returns the received object on success' do
|
||||
object = @zord.perform
|
||||
object = @zord.perform!
|
||||
object.should respond_to(:to_diaspora_xml)
|
||||
end
|
||||
end
|
||||
|
||||
it 'parses the salmon object' do
|
||||
Diaspora::Parser.should_receive(:from_xml).with(@salmon.parsed_data).and_return(@original_post)
|
||||
@zord.perform
|
||||
@zord.perform!
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue