Skip to content

Commit 3ff34f3

Browse files
author
Nathan Sutton
committed
Merge branch 'bugfix/force-an-openssl-cert-store-with-default-paths-because-rubby'
2 parents c02b1cd + 24b5f16 commit 3ff34f3

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

lib/zencoder/http/net_http.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,17 @@ def http
6262
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
6363
else
6464
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
65-
end
6665

67-
http.ca_file = ca_file if ca_file
68-
http.ca_path = ca_path if ca_path
66+
http.cert_store = OpenSSL::X509::Store.new
67+
http.cert_store.set_default_paths
68+
69+
if defined?(OpenSSL::X509::V_FLAG_CRL_CHECK_ALL)
70+
http.cert_store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
71+
end
72+
73+
http.cert_store.add_file(ca_file) if ca_file
74+
http.cert_store.add_path(ca_path) if ca_path
75+
end
6976
end
7077

7178
http

test/test_helper.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
require 'bundler'
33
Bundler.setup
44
Bundler.require(:default, :test)
5-
require 'mocha/integration/test_unit' # Bundler load-order hax
5+
6+
begin
7+
require "minitest/unit"
8+
require "mocha/mini_test"
9+
rescue LoadError
10+
require "test/unit"
11+
require "mocha/test_unit"
12+
end
613

714
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
815
$LOAD_PATH.unshift(File.dirname(__FILE__))

test/zencoder/http/net_http_test.rb

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,45 @@ class Zencoder::HTTP::NetHTTPTest < Test::Unit::TestCase
4242

4343
context "SSL verification" do
4444
setup do
45-
@http_stub = stub(:use_ssl= => true, :request => true, :verify_mode= => true)
45+
@cert_store = stub(:add_file => true, :add_path => true, :flags= => true, :set_default_paths => true)
46+
@http_stub = stub(:use_ssl= => true, :request => true, :verify_mode= => true, :cert_store= => true, :cert_store => @cert_store)
4647
::Net::HTTP.expects(:new).returns(@http_stub)
4748
end
4849

49-
should "not verify when set to skip ssl verification" do
50-
@http_stub.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
51-
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :skip_ssl_verify => true)
52-
end
50+
context "when set to skip ssl verification" do
51+
should "not verify" do
52+
@http_stub.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
53+
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :skip_ssl_verify => true)
54+
end
5355

54-
should "set the ca_file" do
55-
@http_stub.expects(:ca_file=).with("/foo/bar/baz.crt")
56-
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :ca_file => "/foo/bar/baz.crt")
56+
should "not setup a custom cert store" do
57+
@http_stub.expects(:cert_store=).never
58+
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :skip_ssl_verify => true)
59+
end
5760
end
5861

59-
should "set the ca_path" do
60-
@http_stub.expects(:ca_path=).with("/foo/bar/")
61-
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :ca_path => "/foo/bar/")
62+
context "when set to do ssl verification" do
63+
should "setup a custom cert store" do
64+
@http_stub.expects(:cert_store=)
65+
Zencoder::HTTP::NetHTTP.post('https://example.com/path')
66+
end
67+
68+
should "set the default paths on the custom cert store" do
69+
@cert_store.expects(:set_default_paths)
70+
Zencoder::HTTP::NetHTTP.post('https://example.com/path')
71+
end
72+
73+
should "set the ca_file when it is passed in" do
74+
@cert_store.expects(:add_file).with("/foo/bar/baz.crt")
75+
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :ca_file => "/foo/bar/baz.crt")
76+
end
77+
78+
should "set the ca_path when it is passed in" do
79+
@cert_store.expects(:add_path).with("/foo/bar/")
80+
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :ca_path => "/foo/bar/")
81+
end
6282
end
83+
6384
end
6485

6586
context ".post" do

0 commit comments

Comments
 (0)