rename SlapReceiver and mark them deprecated

This commit is contained in:
Benjamin Neff 2016-02-14 01:36:18 +01:00
parent 76a4ea929b
commit 566ac9ff2d
10 changed files with 79 additions and 79 deletions

View file

@ -4,6 +4,5 @@ module DiasporaFederation
end
end
require "diaspora_federation/federation/exceptions"
require "diaspora_federation/federation/receiver"
require "diaspora_federation/federation/sender"

View file

@ -1,11 +0,0 @@
module DiasporaFederation
module Federation
# Raised if failed to fetch a public key of the sender of the received message
class SenderKeyNotFound < RuntimeError
end
# Raised if recipient private key is missing for a private receive
class RecipientKeyNotFound < RuntimeError
end
end
end

View file

@ -1,25 +1,10 @@
module DiasporaFederation
module Federation
# Common base for Private and Public receivers
# @see Receiver::Public
# @see Receiver::Private
class Receiver
# initializes a new Receiver for a salmon XML
# @param [String] salmon_xml the message salmon xml
def initialize(salmon_xml)
@salmon_xml = salmon_xml
end
# Parse the salmon xml and send it to the +:save_entity_after_receive+ callback
def receive!
sender_id = slap.author_id
public_key = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, sender_id)
raise SenderKeyNotFound if public_key.nil?
DiasporaFederation.callbacks.trigger(:save_entity_after_receive, slap.entity(public_key))
end
module Receiver
end
end
end
require "diaspora_federation/federation/receiver/private"
require "diaspora_federation/federation/receiver/public"
require "diaspora_federation/federation/receiver/slap_receiver"
require "diaspora_federation/federation/receiver/private_slap_receiver"
require "diaspora_federation/federation/receiver/public_slap_receiver"

View file

@ -1,26 +0,0 @@
module DiasporaFederation
module Federation
class Receiver
# Receiver::Private is used to receive private messages, which are addressed
# to a specific user, encrypted with his public key and packed using Salmon::EncryptedSlap
class Private < Receiver
# initializes a new Private Receiver for a salmon XML
# @param [String] salmon_xml the message salmon xml
# @param [OpenSSL::PKey::RSA] recipient_private_key recipient private key to decrypt the message
def initialize(salmon_xml, recipient_private_key)
super(salmon_xml)
raise RecipientKeyNotFound if recipient_private_key.nil?
@recipient_private_key = recipient_private_key
end
protected
# parses the encrypted slap xml
# @return [Salmon::EncryptedSlap] slap instance
def slap
@salmon ||= Salmon::EncryptedSlap.from_xml(@salmon_xml, @recipient_private_key)
end
end
end
end
end

View file

@ -0,0 +1,27 @@
module DiasporaFederation
module Federation
module Receiver
# This is used to receive private messages, which are addressed to a specific user,
# encrypted with his public key and packed using {Salmon::EncryptedSlap}.
# @deprecated
class PrivateSlapReceiver < SlapReceiver
# initializes a new Private Receiver for a salmon slap XML
# @param [String] slap_xml the message salmon slap xml
# @param [OpenSSL::PKey::RSA] recipient_private_key recipient private key to decrypt the message
def initialize(slap_xml, recipient_private_key)
super(slap_xml)
raise ArgumentError, "no recipient key provided" unless recipient_private_key.instance_of?(OpenSSL::PKey::RSA)
@recipient_private_key = recipient_private_key
end
protected
# parses the encrypted slap xml
# @return [Salmon::EncryptedSlap] slap instance
def slap
@slap ||= Salmon::EncryptedSlap.from_xml(@slap_xml, @recipient_private_key)
end
end
end
end
end

View file

@ -1,17 +0,0 @@
module DiasporaFederation
module Federation
class Receiver
# Receiver::Public is used to receive public messages, which are not addressed to a specific user, unencrypted
# and packed using Salmon::Slap
class Public < Receiver
protected
# parses the public slap xml
# @return [Salmon::Slap] slap instance
def slap
@salmon ||= Salmon::Slap.from_xml(@salmon_xml)
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module DiasporaFederation
module Federation
module Receiver
# This is used to receive public messages, which are not addressed to
# a specific user, unencrypted and packed using {Salmon::Slap}.
# @deprecated
class PublicSlapReceiver < SlapReceiver
protected
# parses the public slap xml
# @return [Salmon::Slap] slap instance
def slap
@slap ||= Salmon::Slap.from_xml(@slap_xml)
end
end
end
end
end

View file

@ -0,0 +1,25 @@
module DiasporaFederation
module Federation
module Receiver
# Common base for Private and Public receivers
# @see PublicSlapReceiver
# @see PrivateSlapReceiver
# @deprecated
class SlapReceiver
# initializes a new SlapReceiver for a salmon slap XML
# @param [String] slap_xml the message salmon xml
def initialize(slap_xml)
@slap_xml = slap_xml
end
# Parse the salmon xml and send it to the +:save_entity_after_receive+ callback
def receive!
sender_id = slap.author_id
public_key = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, sender_id)
raise Salmon::SenderKeyNotFound if public_key.nil?
DiasporaFederation.callbacks.trigger(:save_entity_after_receive, slap.entity(public_key))
end
end
end
end
end

View file

@ -1,5 +1,5 @@
module DiasporaFederation
describe Federation::Receiver::Private do
describe Federation::Receiver::PrivateSlapReceiver do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) }
let(:sender_key) { OpenSSL::PKey::RSA.generate(1024) }
let(:recipient_key) { OpenSSL::PKey::RSA.generate(1024) }
@ -25,13 +25,13 @@ module DiasporaFederation
expect {
described_class.new(xml, recipient_key).receive!
}.to raise_error Federation::SenderKeyNotFound
}.to raise_error Salmon::SenderKeyNotFound
end
it "raises when recipient private key is not available" do
expect {
described_class.new(xml, nil).receive!
}.to raise_error Federation::RecipientKeyNotFound
}.to raise_error ArgumentError, "no recipient key provided"
end
it "raises when bad xml was supplied" do

View file

@ -1,5 +1,5 @@
module DiasporaFederation
describe Federation::Receiver::Public do
describe Federation::Receiver::PublicSlapReceiver do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) }
let(:sender_key) { OpenSSL::PKey::RSA.generate(1024) }
let(:xml) {
@ -27,7 +27,7 @@ module DiasporaFederation
expect {
described_class.new(xml).receive!
}.to raise_error Federation::SenderKeyNotFound
}.to raise_error Salmon::SenderKeyNotFound
end
it "raises when bad xml was supplied" do