httpi 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,9 +83,11 @@ module HTTPI
83
83
  end
84
84
 
85
85
  def setup_ssl_auth(ssl)
86
- client.ssl_config.client_cert = ssl.cert
87
- client.ssl_config.client_key = ssl.cert_key
88
- client.ssl_config.client_ca = ssl.ca_cert if ssl.ca_cert_file
86
+ unless ssl.verify_mode == :none
87
+ client.ssl_config.client_cert = ssl.cert
88
+ client.ssl_config.client_key = ssl.cert_key
89
+ client.ssl_config.client_ca = ssl.ca_cert if ssl.ca_cert_file
90
+ end
89
91
  client.ssl_config.verify_mode = ssl.openssl_verify_mode
90
92
  end
91
93
 
@@ -12,7 +12,7 @@ module HTTPI
12
12
 
13
13
  # Returns whether SSL configuration is present.
14
14
  def present?
15
- cert && cert_key
15
+ (verify_mode == :none) || (cert && cert_key)
16
16
  rescue TypeError, Errno::ENOENT
17
17
  false
18
18
  end
@@ -1,5 +1,5 @@
1
1
  module HTTPI
2
2
 
3
- VERSION = "0.7.1"
3
+ VERSION = "0.7.2"
4
4
 
5
5
  end
@@ -27,7 +27,7 @@ describe HTTPI::Adapter::HTTPClient do
27
27
  it "should return a valid HTTPI::Response" do
28
28
  request = HTTPI::Request.new :url => "http://example.com", :body => Fixture.xml
29
29
  httpclient.expects(:post).with(request.url, request.body, request.headers).returns(http_message)
30
-
30
+
31
31
  adapter.post(request).should match_response(:body => Fixture.xml)
32
32
  end
33
33
  end
@@ -43,7 +43,7 @@ describe HTTPI::Adapter::HTTPClient do
43
43
  it "should return a valid HTTPI::Response" do
44
44
  request = HTTPI::Request.new :url => "http://example.com", :body => Fixture.xml
45
45
  httpclient.expects(:put).with(request.url, request.body, request.headers).returns(http_message)
46
-
46
+
47
47
  adapter.put(request).should match_response(:body => Fixture.xml)
48
48
  end
49
49
  end
@@ -118,17 +118,42 @@ describe HTTPI::Adapter::HTTPClient do
118
118
  ssl_config.expects(:client_cert=).with(ssl_auth_request.auth.ssl.cert)
119
119
  ssl_config.expects(:client_key=).with(ssl_auth_request.auth.ssl.cert_key)
120
120
  ssl_config.expects(:verify_mode=).with(ssl_auth_request.auth.ssl.openssl_verify_mode)
121
-
121
+
122
122
  adapter.get(ssl_auth_request)
123
123
  end
124
124
 
125
125
  it "should set the client_ca if specified" do
126
126
  ssl_auth_request.auth.ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
127
127
  ssl_config.expects(:client_ca=).with(ssl_auth_request.auth.ssl.ca_cert)
128
-
128
+
129
129
  adapter.get(ssl_auth_request)
130
130
  end
131
131
  end
132
+
133
+ context "(for SSL client auth with a verify mode of :none with no certs provided)" do
134
+ let(:ssl_auth_request) do
135
+ basic_request do |request|
136
+ request.auth.ssl.verify_mode = :none
137
+ end
138
+ end
139
+
140
+ it "verify_mode should be set" do
141
+ ssl_config.expects(:verify_mode=).with(ssl_auth_request.auth.ssl.openssl_verify_mode)
142
+
143
+ adapter.get(ssl_auth_request)
144
+ end
145
+
146
+ it "should not set client_cert and client_key "do
147
+ ssl_config.expects(:client_cert=).never
148
+ ssl_config.expects(:client_key=).never
149
+
150
+ adapter.get(ssl_auth_request)
151
+ end
152
+
153
+ it "should raise an exception" do
154
+ lambda { adapter.get(ssl_auth_request) }.should_not raise_error
155
+ end
156
+ end
132
157
  end
133
158
 
134
159
  def http_message(body = Fixture.xml)
@@ -18,20 +18,26 @@ describe HTTPI::Auth::SSL do
18
18
  it "should return false if only a client key was specified" do
19
19
  ssl = HTTPI::Auth::SSL.new
20
20
  ssl.cert_key_file = "spec/fixtures/client_key.pem"
21
-
21
+
22
22
  ssl.should_not be_present
23
23
  end
24
24
 
25
25
  it "should return false if only a client key was specified" do
26
26
  ssl = HTTPI::Auth::SSL.new
27
27
  ssl.cert_file = "spec/fixtures/client_cert.pem"
28
-
28
+
29
29
  ssl.should_not be_present
30
30
  end
31
31
 
32
32
  it "should return true if both client key and cert are present" do
33
33
  ssl.should be_present
34
34
  end
35
+
36
+ it "should return true of the verify_mode is :none" do
37
+ ssl = HTTPI::Auth::SSL.new
38
+ ssl.verify_mode = :none
39
+ ssl.should be_present
40
+ end
35
41
  end
36
42
 
37
43
  describe "#verify_mode" do
@@ -41,7 +47,7 @@ describe HTTPI::Auth::SSL do
41
47
 
42
48
  it "should set the verify mode to use" do
43
49
  ssl = HTTPI::Auth::SSL.new
44
-
50
+
45
51
  ssl.verify_mode = :none
46
52
  ssl.verify_mode.should == :none
47
53
  end
@@ -66,7 +72,7 @@ describe HTTPI::Auth::SSL do
66
72
  describe "#ca_cert" do
67
73
  it "should return an OpenSSL::X509::Certificate for the given ca_cert_file" do
68
74
  ssl = HTTPI::Auth::SSL.new
69
-
75
+
70
76
  ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
71
77
  ssl.ca_cert.should be_a(OpenSSL::X509::Certificate)
72
78
  end
@@ -75,28 +81,28 @@ describe HTTPI::Auth::SSL do
75
81
  describe "#openssl_verify_mode" do
76
82
  it "should return the OpenSSL verify mode for :none" do
77
83
  ssl = HTTPI::Auth::SSL.new
78
-
84
+
79
85
  ssl.verify_mode = :none
80
86
  ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_NONE
81
87
  end
82
88
 
83
89
  it "should return the OpenSSL verify mode for :peer" do
84
90
  ssl = HTTPI::Auth::SSL.new
85
-
91
+
86
92
  ssl.verify_mode = :peer
87
93
  ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_PEER
88
94
  end
89
95
 
90
96
  it "should return the OpenSSL verify mode for :fail_if_no_peer_cert" do
91
97
  ssl = HTTPI::Auth::SSL.new
92
-
98
+
93
99
  ssl.verify_mode = :fail_if_no_peer_cert
94
100
  ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
95
101
  end
96
102
 
97
103
  it "should return the OpenSSL verify mode for :client_once" do
98
104
  ssl = HTTPI::Auth::SSL.new
99
-
105
+
100
106
  ssl.verify_mode = :client_once
101
107
  ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_CLIENT_ONCE
102
108
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 1
10
- version: 0.7.1
9
+ - 2
10
+ version: 0.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-23 00:00:00 +01:00
19
+ date: 2010-12-02 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency