Permalink
Browse files

Added Net::HTTP-level verify_mode setting and appropriate tests.

  • Loading branch information...
1 parent 9c25b7a commit 462a78326bc34922165e381b261215920ec20a6f @arsduo arsduo committed Jun 22, 2011
Showing with 49 additions and 0 deletions.
  1. +49 −0 spec/cases/http_services/net_http_service_spec.rb
@@ -18,6 +18,11 @@
Horse.methods.collect {|m| m.to_sym}.should include(:ca_path)
Horse.methods.collect {|m| m.to_sym}.should include(:ca_path=)
end
+
+ it "has a verify_mode accessor" do
+ Horse.methods.collect {|m| m.to_sym}.should include(:verify_mode)
+ Horse.methods.collect {|m| m.to_sym}.should include(:verify_mode=)
+ end
it "should define a make_request static module method" do
Horse.respond_to?(:make_request).should be_true
@@ -47,6 +52,7 @@
@http_mock.stub(:start).and_yield(@http_yield_mock)
@http_mock.stub(:ca_path=)
@http_mock.stub(:ca_file=)
+ @http_mock.stub(:verify_mode=)
Net::HTTP.stub(:new).and_return(@http_mock)
end
@@ -318,6 +324,49 @@
end
end
+ describe "verify_mode options" do
+ after :each do
+ Horse.always_use_ssl = nil
+ Horse.verify_mode = nil
+ end
+
+ it "does not set verify mode if it's not SSL" do
+ Horse.always_use_ssl = nil
+ @http_mock.should_not_receive(:verify_mode=)
+ Horse.make_request('anything', {} , 'anything', {:verify_mode => "abc"})
+ end
+
+ context "when making an SSL request" do
+ before :each do
+ Horse.always_use_ssl = true
+ end
+
+ it "sets verify mode if provided in the options" do
+ mode = "foo"
+ @http_mock.should_receive(:verify_mode=).with(mode)
+ Horse.make_request('anything', {} , 'anything', {:verify_mode => mode})
+ end
+
+ it "sets verify mode to the default if provided (and none set in options)" do
+ Horse.verify_mode = "foo"
+ @http_mock.should_receive(:verify_mode=).with(Horse.verify_mode)
+ Horse.make_request('anything', {} , 'anything', {})
+ end
+
+ it "sets verify mode to the default if provided (and none set in options)" do
+ mode = "bar"
+ Horse.verify_mode = "foo"
+ @http_mock.should_receive(:verify_mode=).with(mode)
+ Horse.make_request('anything', {} , 'anything', {:verify_mode => mode})
+ end
+
+ it "sets verify mode to OpenSSL::SSL::VERIFY_PEER if no default or option is provided" do
+ @http_mock.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
+ Horse.make_request('anything', {} , 'anything', {})
+ end
+ end
+ end
+
it "should use the graph server by default" do
Net::HTTP.should_receive(:new).with(Koala::Facebook::GRAPH_SERVER, anything).and_return(@http_mock)
Horse.make_request('anything', {}, 'anything')

0 comments on commit 462a783

Please sign in to comment.