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
@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
end

View file

@ -23,6 +23,20 @@ describe PublicsController do
post :receive, "id" => user.person.id.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, :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
post :receive, "id" => person.id.to_s
response.code.should == '422'

View file

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

View file

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

View file

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

View file

@ -57,6 +57,8 @@ describe User do
user2.post :status_message, :message => "store this!", :to => aspect2.id
}.should_not raise_error
end
end
context 'update posts' do
@ -182,7 +184,7 @@ describe User do
let(:salmon){user.salmon( post )}
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
end
end