changes for new federation-gem version

This commit is contained in:
Benjamin Neff 2016-01-16 00:14:01 +01:00 committed by Dennis Schubert
parent c4ad63d106
commit a3ed9da210
5 changed files with 20 additions and 18 deletions

View file

@ -106,7 +106,11 @@ DiasporaFederation.configure do |config|
end
end
on :save_entity_after_receive do
on :receive_entity do
# TODO
end
on :update_pod do
# TODO
end
end

View file

@ -20,11 +20,10 @@ def create_remote_user(pod)
end
def create_relayable_entity(entity_name, target, diaspora_id, parent_author_key)
target_entity_type = FactoryGirl.factory_by_name(entity_name).build_class.get_target_entity_type(@entity.to_h)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(
:fetch_author_private_key_by_entity_guid,
target_entity_type,
FactoryGirl.build(entity_name).parent_type,
target.guid
)
.and_return(parent_author_key)
@ -33,19 +32,18 @@ def create_relayable_entity(entity_name, target, diaspora_id, parent_author_key)
entity_name,
conversation_guid: target.guid,
parent_guid: target.guid,
diaspora_id: diaspora_id,
author: diaspora_id,
poll_answer_guid: target.respond_to?(:poll_answers) ? target.poll_answers.first.guid : nil
)
end
def generate_xml(entity, remote_user, recipient=nil)
if recipient
DiasporaFederation::Salmon::EncryptedSlap.generate_xml(
DiasporaFederation::Salmon::EncryptedSlap.prepare(
remote_user.diaspora_handle,
OpenSSL::PKey::RSA.new(remote_user.encryption_key),
entity,
OpenSSL::PKey::RSA.new(recipient.encryption_key)
)
entity
).generate_xml(OpenSSL::PKey::RSA.new(recipient.encryption_key))
else
DiasporaFederation::Salmon::Slap.generate_xml(
remote_user.diaspora_handle,

View file

@ -36,7 +36,7 @@ describe "Receive federation messages feature" do
it "reshare of public post passes" do
post = FactoryGirl.create(:status_message, author: alice.person, public: true)
reshare = FactoryGirl.build(
:reshare_entity, root_diaspora_id: alice.diaspora_handle, root_guid: post.guid, diaspora_id: sender_id)
:reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id)
post_message(generate_xml(reshare, sender))
expect(Reshare.exists?(root_guid: post.guid, diaspora_handle: sender_id)).to be_truthy
@ -45,7 +45,7 @@ describe "Receive federation messages feature" do
it "reshare of private post fails" do
post = FactoryGirl.create(:status_message, author: alice.person, public: false)
reshare = FactoryGirl.build(
:reshare_entity, root_diaspora_id: alice.diaspora_handle, root_guid: post.guid, diaspora_id: sender_id)
:reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id)
expect {
post_message(generate_xml(reshare, sender))
}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Only posts which are public may be reshared."
@ -72,7 +72,7 @@ describe "Receive federation messages feature" do
let(:recipient) { alice }
it "treats sharing request recive correctly" do
entity = FactoryGirl.build(:request_entity, recipient_id: alice.diaspora_handle)
entity = FactoryGirl.build(:request_entity, recipient: alice.diaspora_handle)
expect(Diaspora::Fetcher::Public).to receive(:queue_for).exactly(1).times
@ -94,7 +94,7 @@ describe "Receive federation messages feature" do
end
it "doesn't save the private status message if there is no sharing" do
entity = FactoryGirl.build(:status_message_entity, diaspora_id: sender_id, public: false)
entity = FactoryGirl.build(:status_message_entity, author: sender_id, public: false)
post_message(generate_xml(entity, sender, alice), alice)
expect(StatusMessage.exists?(guid: entity.guid)).to be_falsey
@ -111,7 +111,7 @@ describe "Receive federation messages feature" do
it_behaves_like "messages which can't be send without sharing"
it "treats profile receive correctly" do
entity = FactoryGirl.build(:profile_entity, diaspora_id: sender_id)
entity = FactoryGirl.build(:profile_entity, author: sender_id)
post_message(generate_xml(entity, sender, alice), alice)
expect(Profile.exists?(diaspora_handle: entity.diaspora_id)).to be_truthy
@ -120,8 +120,8 @@ describe "Receive federation messages feature" do
it "receives conversation correctly" do
entity = FactoryGirl.build(
:conversation_entity,
diaspora_id: sender_id,
participant_ids: "#{sender_id};#{alice.diaspora_handle}"
author: sender_id,
participants: "#{sender_id};#{alice.diaspora_handle}"
)
post_message(generate_xml(entity, sender, alice), alice)

View file

@ -9,7 +9,7 @@ def retraction_entity(entity_name, target_object, sender)
FactoryGirl.build(
entity_name,
diaspora_id: sender.diaspora_handle,
author: sender.diaspora_handle,
target_guid: target_object.guid,
target_type: target_object.class.to_s
)

View file

@ -4,7 +4,7 @@ shared_examples_for "messages which are indifferent about sharing fact" do
let(:public) { recipient.nil? }
it "treats status message receive correctly" do
entity = FactoryGirl.build(:status_message_entity, diaspora_id: sender_id, public: public)
entity = FactoryGirl.build(:status_message_entity, author: sender_id, public: public)
post_message(generate_xml(entity, sender, recipient), recipient)
@ -13,7 +13,7 @@ shared_examples_for "messages which are indifferent about sharing fact" do
it "doesn't accept status message with wrong signature" do
allow(sender).to receive(:encryption_key).and_return(OpenSSL::PKey::RSA.new(1024))
entity = FactoryGirl.build(:status_message_entity, diaspora_id: sender_id, public: public)
entity = FactoryGirl.build(:status_message_entity, author: sender_id, public: public)
post_message(generate_xml(entity, sender, recipient), recipient)