From b575983c22f025bf7b599975e16d715a8ae040f7 Mon Sep 17 00:00:00 2001 From: Ilya Zhitomirskiy Date: Wed, 8 Jun 2011 18:46:38 -0700 Subject: [PATCH] WIP certs --- app/models/app_config.rb | 9 +++++---- lib/webfinger.rb | 6 +++--- spec/lib/webfinger_spec.rb | 4 ++-- spec/models/services/facebook_spec.rb | 10 +++++----- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/models/app_config.rb b/app/models/app_config.rb index b98a4e73c..9bfa243ec 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -7,6 +7,10 @@ class AppConfig < Settingslogic source File.join(Rails.root, "config", "application.yml") namespace Rails.env + + if self[:ca_file].blank? && Rails.env.development? + OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE + end def self.load! if no_config_file? && !have_old_config_file? @@ -36,10 +40,7 @@ HELP end super - - if self[:ca_file].blank? && Rails.env.development? - OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE - end + if no_cert_file_in_prod? $stderr.puts <<-HELP diff --git a/lib/webfinger.rb b/lib/webfinger.rb index bf752bc93..2e8659fd8 100644 --- a/lib/webfinger.rb +++ b/lib/webfinger.rb @@ -47,7 +47,7 @@ class Webfinger private def get_xrd begin - http = RestClient.get xrd_url, OPTS + http = Faraday.get xrd_url, OPTS profile_url = webfinger_profile_url(http.body) if profile_url @@ -69,7 +69,7 @@ class Webfinger def get_webfinger_profile(profile_url) begin - http = RestClient.get(profile_url, OPTS) + http = Faraday.get(profile_url, OPTS) rescue raise I18n.t('webfinger.fetch_failed', :profile_url => profile_url) @@ -83,7 +83,7 @@ class Webfinger @wf_profile = WebfingerProfile.new(@account, webfinger_profile) begin - hcard = RestClient.get(@wf_profile.hcard, OPTS) + hcard = Faraday.get(@wf_profile.hcard, OPTS) rescue return I18n.t('webfinger.hcard_fetch_failed', :account => @account) end diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb index 08a118b23..80e71aa7a 100644 --- a/spec/lib/webfinger_spec.rb +++ b/spec/lib/webfinger_spec.rb @@ -78,7 +78,7 @@ describe Webfinger do diaspora_xrd.stub!(:body).and_return(diaspora_xrd) hcard_xml.stub!(:body).and_return(hcard_xml) diaspora_finger.stub!(:body).and_return(diaspora_finger) - RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml) + Faraday.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml) #new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com") # http://tom.joindiaspora.com/.well-known/host-meta f = Webfinger.new("alice@example.org").fetch @@ -90,7 +90,7 @@ describe Webfinger do f = Webfinger.new("tom@tom.joindiaspora.com") diaspora_xrd.stub!(:body).and_return(diaspora_xrd) - RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd) + Faraday.should_receive(:get).twice.and_return(nil, diaspora_xrd) f.should_receive(:xrd_url).twice f.send(:get_xrd) f.instance_variable_get(:@ssl).should == false diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index 423ed582f..43956cb69 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -11,16 +11,16 @@ describe Services::Facebook do describe '#post' do it 'posts a status message to facebook' do - RestClient.should_receive(:post).with("https://graph.facebook.com/me/feed", :message => @post.text, :access_token => @service.access_token) + Faraday.should_receive(:post).with("https://graph.facebook.com/me/feed", :message => @post.text, :access_token => @service.access_token) @service.post(@post) end it 'swallows exception raised by facebook always being down' do - RestClient.should_receive(:post).and_raise + Faraday.should_receive(:post).and_raise @service.post(@post) end it 'should call public message' do - RestClient.stub!(:post) + Faraday.stub!(:post) url = "foo" @service.should_receive(:public_message).with(@post, url) @service.post(@post, url) @@ -53,12 +53,12 @@ describe Services::Facebook do JSON @web_mock = mock() @web_mock.stub!(:body).and_return(@fb_list_hash) - RestClient.stub!(:get).and_return(@web_mock) + Faraday.stub!(:get).and_return(@web_mock) end describe '#save_friends' do it 'requests a friend list' do - RestClient.should_receive(:get).with("https://graph.facebook.com/me/friends?fields[]=name&fields[]=picture&access_token=yeah").and_return(@web_mock) + Faraday.should_receive(:get).with("https://graph.facebook.com/me/friends?fields[]=name&fields[]=picture&access_token=yeah").and_return(@web_mock) @service.save_friends end