send xml to callbacks to queue it for receive
This commit is contained in:
parent
0d3fe7e7be
commit
b56c1e2d04
4 changed files with 39 additions and 19 deletions
|
|
@ -11,8 +11,11 @@ module DiasporaFederation
|
|||
# POST /receive/public
|
||||
def public
|
||||
logger.info "received a public message"
|
||||
logger.debug CGI.unescape(params[:xml])
|
||||
Receiver::Public.new(CGI.unescape(params[:xml])).receive!
|
||||
xml = CGI.unescape(params[:xml])
|
||||
logger.debug xml
|
||||
|
||||
DiasporaFederation.callbacks.trigger(:queue_public_receive, xml)
|
||||
|
||||
render nothing: true, status: :ok
|
||||
end
|
||||
|
||||
|
|
@ -21,13 +24,12 @@ module DiasporaFederation
|
|||
# POST /receive/users/:guid
|
||||
def private
|
||||
logger.info "received a private message for #{params[:guid]}"
|
||||
logger.debug CGI.unescape(params[:xml])
|
||||
begin
|
||||
Receiver::Private.new(params[:guid], CGI.unescape(params[:xml])).receive!
|
||||
render nothing: true, status: :ok
|
||||
rescue RecipientNotFound
|
||||
render nothing: true, status: 404
|
||||
end
|
||||
xml = CGI.unescape(params[:xml])
|
||||
logger.debug xml
|
||||
|
||||
success = DiasporaFederation.callbacks.trigger(:queue_private_receive, params[:guid], xml)
|
||||
|
||||
render nothing: true, status: success ? :ok : 404
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ module DiasporaFederation
|
|||
fetch_author_public_key_by_entity_guid
|
||||
entity_author_is_local?
|
||||
fetch_entity_author_id_by_guid
|
||||
queue_public_receive
|
||||
queue_private_receive
|
||||
entity_persist
|
||||
)
|
||||
|
||||
|
|
@ -124,6 +126,16 @@ module DiasporaFederation
|
|||
# @param [String] guid of the entity
|
||||
# @return [String] Diaspora ID of the person
|
||||
#
|
||||
# queue_public_receive
|
||||
# Queue a public salmon xml to process in background
|
||||
# @param [String] xml salmon xml
|
||||
#
|
||||
# queue_private_receive
|
||||
# Queue a private salmon xml to process in background
|
||||
# @param [String] guid guid of the receiver person
|
||||
# @param [String] xml salmon xml
|
||||
# @return [Boolean] true if successful, false if the user was not found
|
||||
#
|
||||
# @see Callbacks#on
|
||||
#
|
||||
# @example
|
||||
|
|
|
|||
|
|
@ -3,17 +3,14 @@ module DiasporaFederation
|
|||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
describe "POST #public" do
|
||||
it "raises on an empty object" do
|
||||
expect { post :public, xml: "<diaspora/>" }.to raise_error(Salmon::MissingAuthor)
|
||||
end
|
||||
|
||||
it "returns a 422 if no xml is passed" do
|
||||
post :public
|
||||
expect(response.code).to eq("422")
|
||||
end
|
||||
|
||||
it "returns a 200 if receive! reports no errors" do
|
||||
expect_any_instance_of(Receiver::Public).to receive(:receive!)
|
||||
it "returns a 200 if queued correctly" do
|
||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(:queue_public_receive, "<diaspora/>")
|
||||
|
||||
post :public, xml: "<diaspora/>"
|
||||
expect(response.code).to eq("200")
|
||||
|
|
@ -21,7 +18,11 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
describe "POST #private" do
|
||||
it "return 404 for because of an unknown guid" do
|
||||
it "return a 404 if not queued successfully (unknown user guid)" do
|
||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(:queue_private_receive, "any-guid", "<diaspora/>")
|
||||
.and_return(false)
|
||||
|
||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||
expect(response.code).to eq("404")
|
||||
end
|
||||
|
|
@ -33,10 +34,8 @@ module DiasporaFederation
|
|||
|
||||
it "returns a 200 if receive! reports no errors" do
|
||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(:fetch_private_key_by_user_guid, "any-guid")
|
||||
.once
|
||||
.with(:queue_private_receive, "any-guid", "<diaspora/>")
|
||||
.and_return(true)
|
||||
expect_any_instance_of(Receiver::Private).to receive(:receive!)
|
||||
|
||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||
expect(response.code).to eq("200")
|
||||
|
|
|
|||
|
|
@ -91,6 +91,13 @@ DiasporaFederation.configure do |config|
|
|||
nil
|
||||
end
|
||||
|
||||
on :queue_public_receive do
|
||||
end
|
||||
|
||||
on :queue_private_receive do
|
||||
true
|
||||
end
|
||||
|
||||
on :entity_persist do
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue