From 00589c10c60fa4db8cec41d2101f79c22d136463 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Tue, 21 Jun 2011 21:13:51 -0700 Subject: [PATCH 1/2] If one user has a bad rsa key, don't abort all sends. --- app/models/jobs/http_multi.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index ef3729a66..d9ef788b8 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)})) From 2f89f19f34d879b27f5b1537d42edc5d4a9a19bb Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 4 Jul 2011 15:43:35 -0700 Subject: [PATCH 2/2] Test sending to people with bad rsa keys. --- spec/models/jobs/http_multi_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/models/jobs/http_multi_spec.rb b/spec/models/jobs/http_multi_spec.rb index b209aa524..501fcf922 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