make sure receive unescapes the payload before sending it to the job

This commit is contained in:
maxwell 2011-01-06 16:29:58 -08:00
parent 0c8e6b0ba1
commit cff387d651
6 changed files with 31 additions and 12 deletions

View file

@ -56,7 +56,7 @@ class PublicsController < ApplicationController
end end
@user = person.owner @user = person.owner
Resque.enqueue(Jobs::ReceiveSalmon, @user.id, params[:xml]) Resque.enqueue(Jobs::ReceiveSalmon, @user.id, CGI::unescape(params[:xml]))
render :nothing => true, :status => 200 render :nothing => true, :status => 200
end end

View file

@ -23,6 +23,20 @@ describe PublicsController do
post :receive, "id" => user.person.id.to_s, "xml" => xml post :receive, "id" => user.person.id.to_s, "xml" => xml
end end
it 'unescapes the xml before sending it to receive_salmon' do
aspect = user.aspects.create(:name => 'foo')
post1 = user.post(:status_message, :message => 'moms', :to => [aspect.id])
xml2 = post1.to_diaspora_xml
user2 = make_user
salmon_factory = Salmon::SalmonSlap.create(user, xml2)
enc_xml = salmon_factory.xml_for(user2.person)
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, enc_xml).once
post :receive, "id" => user.person.id.to_s, "xml" => CGI::escape(enc_xml)
end
it 'returns a 422 if no xml is passed' do it 'returns a 422 if no xml is passed' do
post :receive, "id" => person.id.to_s post :receive, "id" => person.id.to_s
response.code.should == '422' response.code.should == '422'

View file

@ -5,11 +5,11 @@
require 'spec_helper' require 'spec_helper'
describe PubSubHubbub do describe PubSubHubbub do
before :all do before do
RestClient.unstub!(:post) RestClient.unstub!(:post)
end end
after :all do after do
RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success)) RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success))
end end

View file

@ -13,4 +13,3 @@ describe Jobs::PostToService do
Jobs::PostToService.perform("123", post.id.to_s, url) Jobs::PostToService.perform("123", post.id.to_s, url)
end end
end end

View file

@ -3,6 +3,7 @@ require 'spec_helper'
describe Jobs::ReceiveSalmon do describe Jobs::ReceiveSalmon do
before do before do
@user = make_user @user = make_user
@user2 = make_user
@xml = '<xml></xml>' @xml = '<xml></xml>'
User.stub(:find){ |id| User.stub(:find){ |id|
if id == @user.id if id == @user.id
@ -16,4 +17,7 @@ describe Jobs::ReceiveSalmon do
@user.should_receive(:receive_salmon).with(@xml).once @user.should_receive(:receive_salmon).with(@xml).once
Jobs::ReceiveSalmon.perform(@user.id, @xml) Jobs::ReceiveSalmon.perform(@user.id, @xml)
end end
end end

View file

@ -49,14 +49,16 @@ describe User do
end end
describe '#receive_salmon' do describe '#receive_salmon' do
it 'should handle the case where the webfinger fails' do it 'should handle the case where the webfinger fails' do
pending "Write this to test #receive_salmon" pending "Write this to test #receive_salmon"
Webfinger.stub!(:fetch).and_return(nil) Webfinger.stub!(:fetch).and_return(nil)
proc{
user2.post :status_message, :message => "store this!", :to => aspect2.id
}.should_not raise_error
end
proc{
user2.post :status_message, :message => "store this!", :to => aspect2.id
}.should_not raise_error
end
end end
context 'update posts' do context 'update posts' do
@ -182,7 +184,7 @@ describe User do
let(:salmon){user.salmon( post )} let(:salmon){user.salmon( post )}
it 'should receive a salmon for a post' do it 'should receive a salmon for a post' do
user2.receive_salmon( salmon.xml_for user2.person ) user2.receive_salmon( salmon.xml_for(user2.person) )
user2.visible_post_ids.include?(post.id).should be true user2.visible_post_ids.include?(post.id).should be true
end end
end end