Skip to content

Commit 0a0fe23

Browse files
author
Nathan Sutton
committed
Removing the bundling of the zencoder ca chain and allow users to specify cert paths
1 parent 9853448 commit 0a0fe23

File tree

6 files changed

+40
-70
lines changed

6 files changed

+40
-70
lines changed

lib/zencoder/http.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module Zencoder
22
class HTTP
33

4-
CA_CHAIN_PATH = File.expand_path(File.join(File.dirname(__FILE__), "http", "resources", "zencoder_ca_chain.crt"))
5-
64
include Zencoder::Serializer
75

86
attr_accessor :url, :options, :method

lib/zencoder/http/net_http.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Zencoder
22
class HTTP
33
class NetHTTP
44

5-
attr_accessor :method, :url, :uri, :body, :params, :headers, :timeout, :skip_ssl_verify, :options
5+
attr_accessor :method, :url, :uri, :body, :params, :headers, :timeout, :skip_ssl_verify, :options, :ca_file, :ca_path
66

77
def initialize(method, url, options)
88
@method = method
@@ -13,6 +13,8 @@ def initialize(method, url, options)
1313
@headers = @options.delete(:headers)
1414
@timeout = @options.delete(:timeout)
1515
@skip_ssl_verify = @options.delete(:skip_ssl_verify)
16+
@ca_file = @options.delete(:ca_file)
17+
@ca_path = @options.delete(:ca_path)
1618
end
1719

1820
def self.post(url, options={})
@@ -59,10 +61,11 @@ def http
5961
if skip_ssl_verify
6062
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
6163
else
62-
http.ca_file = Zencoder::HTTP::CA_CHAIN_PATH
6364
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
64-
http.verify_depth = 5
6565
end
66+
67+
http.ca_file = ca_file if ca_file
68+
http.ca_path = ca_path if ca_path
6669
end
6770

6871
http

lib/zencoder/http/resources/zencoder_ca_chain.crt

Lines changed: 0 additions & 62 deletions
This file was deleted.

lib/zencoder/http/typhoeus.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def self.perform(method, url, options={})
2424
options[:disable_ssl_peer_verification] = true
2525
end
2626

27+
if ca_file = options.delete(:ca_file)
28+
options[:sslcert] = ca_file
29+
end
30+
31+
if ca_path = options.delete(:ca_path)
32+
options[:capath] = ca_path
33+
end
34+
2735
::Typhoeus::Request.send(method, url, options)
2836
end
2937

test/zencoder/http/net_http_test.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,25 @@ class Zencoder::HTTP::NetHTTPTest < Test::Unit::TestCase
4141
end
4242

4343
context "SSL verification" do
44+
setup do
45+
@http_stub = stub(:use_ssl= => true, :request => true, :verify_mode= => true)
46+
::Net::HTTP.expects(:new).returns(@http_stub)
47+
end
48+
4449
should "not verify when set to skip ssl verification" do
45-
http_stub = stub(:use_ssl= => true, :request => true)
46-
http_stub.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
47-
::Net::HTTP.expects(:new).returns(http_stub)
50+
@http_stub.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
4851
Zencoder::HTTP::NetHTTP.post('https://example.com/path', :skip_ssl_verify => true)
4952
end
53+
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")
57+
end
58+
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+
end
5063
end
5164

5265
context ".post" do

test/zencoder/http/typhoeus_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ module Request
4444
Typhoeus::Request.expects(:get).with('https://example.com', {:disable_ssl_peer_verification => true})
4545
Zencoder::HTTP::Typhoeus.get('https://example.com', {:skip_ssl_verify => true})
4646
end
47+
48+
should "use the path to the cert file" do
49+
Typhoeus::Request.expects(:get).with('https://example.com', {:disable_ssl_peer_verification => true, :sslcert => "/foo/bar/baz.crt"})
50+
Zencoder::HTTP::Typhoeus.get('https://example.com', {:skip_ssl_verify => true, :ca_file => "/foo/bar/baz.crt"})
51+
end
52+
53+
should "use the path to the certs directory" do
54+
Typhoeus::Request.expects(:get).with('https://example.com', {:disable_ssl_peer_verification => true, :capath => "/foo/bar/baz.crt"})
55+
Zencoder::HTTP::Typhoeus.get('https://example.com', {:skip_ssl_verify => true, :ca_path => "/foo/bar/baz.crt"})
56+
end
4757
end
4858

4959
end

0 commit comments

Comments
 (0)