diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index ef3729a66f4de2f20b94c5bb1321d6b2e084ae5a..d9ef788b8f9870c9d5360e8297ec1e9321f03e7c 100644 --- a/app/models/jobs/http_multi.rb +++ b/app/models/jobs/http_multi.rb @@ -25,7 +25,14 @@ module Job people.each do |person| url = person.receive_url - xml = salmon.xml_for(person) + begin + xml = salmon.xml_for(person) + rescue OpenSSL::PKey::RSAError => e + Rails.logger.info(:event => :invalid_rsa_key, :identifier => person.diaspora_handle) + next + end + + Rails.logger.info("event=http_multi_send sender_id=#{user_id} recipient_id=#{person.id} url=#{url} xml='#{xml}'") request = Request.new(url, OPTS.merge(:params => {:xml => CGI::escape(xml)})) diff --git a/spec/models/jobs/http_multi_spec.rb b/spec/models/jobs/http_multi_spec.rb index b209aa5241d3496322fbf5b27e15c7bb42757f97..501fcf9229346cbb944d5a06814765419103f7ca 100644 --- a/spec/models/jobs/http_multi_spec.rb +++ b/spec/models/jobs/http_multi_spec.rb @@ -80,4 +80,17 @@ describe Job::HttpMulti do person.reload person.url.should == "https://remote.net/" end + + it 'only sends to users with valid RSA keys' do + person = @people[0] + person.serialized_public_key = "-----BEGIN RSA PUBLIC KEY-----\nPsych!\n-----END RSA PUBLIC KEY-----" + person.save + + @hydra.stub(:post, @people[0].receive_url).and_return(@response) + @hydra.stub(:post, @people[1].receive_url).and_return(@response) + Typhoeus::Hydra.stub!(:new).and_return(@hydra) + + @hydra.should_receive(:queue).once + Job::HttpMulti.perform(bob.id, @post_xml, [@people[0].id, @people[1].id]) + end end