create queue callbacks and remove receive routes
This commit is contained in:
parent
c036a6a4c3
commit
5c8f0c1671
5 changed files with 55 additions and 101 deletions
|
|
@ -7,7 +7,6 @@ class PublicsController < ApplicationController
|
|||
|
||||
skip_before_action :set_header_data
|
||||
skip_before_action :set_grammatical_gender
|
||||
before_action :check_for_xml, :only => [:receive, :receive_public]
|
||||
before_action :authenticate_user!, :only => [:index]
|
||||
|
||||
respond_to :html
|
||||
|
|
@ -18,36 +17,4 @@ class PublicsController < ApplicationController
|
|||
def hub
|
||||
render :text => params['hub.challenge'], :status => 202, :layout => false
|
||||
end
|
||||
|
||||
def receive_public
|
||||
logger.info "received a public message"
|
||||
Workers::ReceiveUnencryptedSalmon.perform_async(CGI::unescape(params[:xml]))
|
||||
render :nothing => true, :status => :ok
|
||||
end
|
||||
|
||||
def receive
|
||||
person = Person.find_by_guid(params[:guid])
|
||||
|
||||
if person.nil? || person.owner_id.nil?
|
||||
logger.error "Received post for nonexistent person #{params[:guid]}"
|
||||
render :nothing => true, :status => 404
|
||||
return
|
||||
end
|
||||
|
||||
@user = person.owner
|
||||
|
||||
logger.info "received a private message for user: #{@user.id}"
|
||||
Workers::ReceiveEncryptedSalmon.perform_async(@user.id, CGI::unescape(params[:xml]))
|
||||
|
||||
render :nothing => true, :status => 202
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_for_xml
|
||||
if params[:xml].nil?
|
||||
render :nothing => true, :status => 422
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -89,5 +89,24 @@ DiasporaFederation.configure do |config|
|
|||
on :fetch_entity_author_id_by_guid do |entity_type, guid|
|
||||
entity_type.constantize.where(guid: guid).joins(:author).pluck(:diaspora_handle).first
|
||||
end
|
||||
|
||||
on :queue_public_receive do |xml|
|
||||
Workers::ReceiveUnencryptedSalmon.perform_async(xml)
|
||||
end
|
||||
|
||||
on :queue_private_receive do |guid, xml|
|
||||
person = Person.find_by_guid(guid)
|
||||
|
||||
if person.nil? || person.owner_id.nil?
|
||||
false
|
||||
else
|
||||
Workers::ReceiveEncryptedSalmon.perform_async(person.owner.id, xml)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
on :save_entity_after_receive do
|
||||
# TODO
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -186,9 +186,7 @@ Diaspora::Application.routes.draw do
|
|||
# Federation
|
||||
|
||||
controller :publics do
|
||||
post 'receive/users/:guid' => :receive
|
||||
post 'receive/public' => :receive_public
|
||||
get 'hub' => :hub
|
||||
get "hub" => :hub
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,71 +5,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PublicsController, :type => :controller do
|
||||
let(:fixture_path) { Rails.root.join('spec', 'fixtures') }
|
||||
before do
|
||||
@user = alice
|
||||
@person = FactoryGirl.create(:person)
|
||||
end
|
||||
|
||||
describe '#receive_public' do
|
||||
it 'succeeds' do
|
||||
post :receive_public, :xml => "<stuff/>"
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'returns a 422 if no xml is passed' do
|
||||
post :receive_public
|
||||
expect(response.code).to eq('422')
|
||||
end
|
||||
|
||||
it 'enqueues a ReceiveUnencryptedSalmon job' do
|
||||
xml = "stuff"
|
||||
expect(Workers::ReceiveUnencryptedSalmon).to receive(:perform_async).with(xml)
|
||||
post :receive_public, :xml => xml
|
||||
end
|
||||
end
|
||||
|
||||
describe '#receive' do
|
||||
let(:xml) { "<walruses></walruses>" }
|
||||
|
||||
it 'succeeds' do
|
||||
post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'enqueues a receive job' do
|
||||
expect(Workers::ReceiveEncryptedSalmon).to receive(:perform_async).with(@user.id, xml).once
|
||||
post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
|
||||
end
|
||||
|
||||
it 'unescapes the xml before sending it to receive_salmon' do
|
||||
aspect = @user.aspects.create(:name => 'foo')
|
||||
post1 = @user.post(:status_message, :text => 'moms', :to => [aspect.id])
|
||||
xml2 = post1.to_diaspora_xml
|
||||
user2 = FactoryGirl.create(:user)
|
||||
|
||||
salmon_factory = Salmon::EncryptedSlap.create_by_user_and_activity(@user, xml2)
|
||||
enc_xml = salmon_factory.xml_for(user2.person)
|
||||
|
||||
expect(Workers::ReceiveEncryptedSalmon).to receive(:perform_async).with(@user.id, enc_xml).once
|
||||
post :receive, "guid" => @user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
|
||||
end
|
||||
|
||||
it 'returns a 422 if no xml is passed' do
|
||||
post :receive, "guid" => @person.guid.to_s
|
||||
expect(response.code).to eq('422')
|
||||
end
|
||||
|
||||
it 'returns a 404 if no user is found' do
|
||||
post :receive, "guid" => @person.guid.to_s, "xml" => xml
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
it 'returns a 404 if no person is found' do
|
||||
post :receive, :guid => '2398rq3948yftn', :xml => xml
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
|
||||
describe '#hub' do
|
||||
it 'succeeds' do
|
||||
get :hub
|
||||
|
|
|
|||
|
|
@ -266,4 +266,39 @@ describe "diaspora federation callbacks" do
|
|||
).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe ":queue_public_receive" do
|
||||
it "enqueues a ReceiveUnencryptedSalmon job" do
|
||||
xml = "<diaspora/>"
|
||||
expect(Workers::ReceiveUnencryptedSalmon).to receive(:perform_async).with(xml)
|
||||
|
||||
DiasporaFederation.callbacks.trigger(:queue_public_receive, xml)
|
||||
end
|
||||
end
|
||||
|
||||
describe ":queue_private_receive" do
|
||||
let(:xml) { "<diaspora/>" }
|
||||
|
||||
it "returns true if the user is found" do
|
||||
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, alice.person.guid, xml)
|
||||
expect(result).to be_truthy
|
||||
end
|
||||
|
||||
it "enqueues a ReceiveEncryptedSalmon job" do
|
||||
expect(Workers::ReceiveEncryptedSalmon).to receive(:perform_async).with(alice.id, xml)
|
||||
|
||||
DiasporaFederation.callbacks.trigger(:queue_private_receive, alice.person.guid, xml)
|
||||
end
|
||||
|
||||
it "returns false if the no user is found" do
|
||||
person = FactoryGirl.create(:person)
|
||||
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, person.guid, xml)
|
||||
expect(result).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false if the no person is found" do
|
||||
result = DiasporaFederation.callbacks.trigger(:queue_private_receive, "2398rq3948yftn", xml)
|
||||
expect(result).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue