Skip to content
Extraits de code Groupes Projets
Valider 5c8f0c16 rédigé par Benjamin Neff's avatar Benjamin Neff Validation de Dennis Schubert
Parcourir les fichiers

create queue callbacks and remove receive routes

parent c036a6a4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -7,7 +7,6 @@ class PublicsController < ApplicationController ...@@ -7,7 +7,6 @@ class PublicsController < ApplicationController
skip_before_action :set_header_data skip_before_action :set_header_data
skip_before_action :set_grammatical_gender skip_before_action :set_grammatical_gender
before_action :check_for_xml, :only => [:receive, :receive_public]
before_action :authenticate_user!, :only => [:index] before_action :authenticate_user!, :only => [:index]
respond_to :html respond_to :html
...@@ -18,36 +17,4 @@ class PublicsController < ApplicationController ...@@ -18,36 +17,4 @@ class PublicsController < ApplicationController
def hub def hub
render :text => params['hub.challenge'], :status => 202, :layout => false render :text => params['hub.challenge'], :status => 202, :layout => false
end 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 end
...@@ -89,5 +89,24 @@ DiasporaFederation.configure do |config| ...@@ -89,5 +89,24 @@ DiasporaFederation.configure do |config|
on :fetch_entity_author_id_by_guid do |entity_type, guid| on :fetch_entity_author_id_by_guid do |entity_type, guid|
entity_type.constantize.where(guid: guid).joins(:author).pluck(:diaspora_handle).first entity_type.constantize.where(guid: guid).joins(:author).pluck(:diaspora_handle).first
end 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
end end
...@@ -186,9 +186,7 @@ Diaspora::Application.routes.draw do ...@@ -186,9 +186,7 @@ Diaspora::Application.routes.draw do
# Federation # Federation
controller :publics do controller :publics do
post 'receive/users/:guid' => :receive get "hub" => :hub
post 'receive/public' => :receive_public
get 'hub' => :hub
end end
......
...@@ -5,71 +5,6 @@ ...@@ -5,71 +5,6 @@
require 'spec_helper' require 'spec_helper'
describe PublicsController, :type => :controller do 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 describe '#hub' do
it 'succeeds' do it 'succeeds' do
get :hub get :hub
......
...@@ -266,4 +266,39 @@ describe "diaspora federation callbacks" do ...@@ -266,4 +266,39 @@ describe "diaspora federation callbacks" do
).to be_nil ).to be_nil
end end
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 end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter