httpi-ntlm 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.autotest +5 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +69 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE +20 -0
  8. data/README.md +223 -0
  9. data/Rakefile +18 -0
  10. data/autotest/discover.rb +1 -0
  11. data/httpi-ntlm.gemspec +27 -0
  12. data/lib/httpi-ntlm.rb +1 -0
  13. data/lib/httpi.rb +198 -0
  14. data/lib/httpi/adapter.rb +67 -0
  15. data/lib/httpi/adapter/curb.rb +125 -0
  16. data/lib/httpi/adapter/httpclient.rb +98 -0
  17. data/lib/httpi/adapter/net_http.rb +117 -0
  18. data/lib/httpi/auth/config.rb +81 -0
  19. data/lib/httpi/auth/ssl.rb +91 -0
  20. data/lib/httpi/dime.rb +56 -0
  21. data/lib/httpi/request.rb +90 -0
  22. data/lib/httpi/response.rb +85 -0
  23. data/lib/httpi/version.rb +5 -0
  24. data/spec/fixtures/attachment.gif +0 -0
  25. data/spec/fixtures/client_cert.pem +16 -0
  26. data/spec/fixtures/client_key.pem +15 -0
  27. data/spec/fixtures/xml.gz +0 -0
  28. data/spec/fixtures/xml.xml +10 -0
  29. data/spec/fixtures/xml_dime.dime +0 -0
  30. data/spec/fixtures/xml_dime.xml +1 -0
  31. data/spec/httpi/adapter/curb_spec.rb +232 -0
  32. data/spec/httpi/adapter/httpclient_spec.rb +164 -0
  33. data/spec/httpi/adapter/net_http_spec.rb +142 -0
  34. data/spec/httpi/adapter_spec.rb +55 -0
  35. data/spec/httpi/auth/config_spec.rb +117 -0
  36. data/spec/httpi/auth/ssl_spec.rb +128 -0
  37. data/spec/httpi/httpi_spec.rb +284 -0
  38. data/spec/httpi/request_spec.rb +135 -0
  39. data/spec/httpi/response_spec.rb +125 -0
  40. data/spec/integration/request_spec.rb +95 -0
  41. data/spec/integration/server.rb +39 -0
  42. data/spec/spec_helper.rb +12 -0
  43. data/spec/support/fixture.rb +27 -0
  44. data/spec/support/matchers.rb +19 -0
  45. metadata +200 -0
@@ -0,0 +1,125 @@
1
+ require "spec_helper"
2
+ require "httpi/response"
3
+
4
+ describe HTTPI::Response do
5
+
6
+ context "normal" do
7
+ let(:response) { HTTPI::Response.new 200, {}, Fixture.xml }
8
+
9
+ describe "#error?" do
10
+ it "returns false" do
11
+ response.should_not be_an_error
12
+ end
13
+ end
14
+
15
+ describe "#headers" do
16
+ it "returns the HTTP response headers" do
17
+ response.headers.should == {}
18
+ end
19
+ end
20
+
21
+ describe "#code" do
22
+ it "returns the HTTP response code" do
23
+ response.code.should == 200
24
+ end
25
+
26
+ it "always returns an Integer" do
27
+ response = HTTPI::Response.new "200", {}, ""
28
+ response.code.should == 200
29
+ end
30
+ end
31
+
32
+ describe "#multipart" do
33
+ it "returns false" do
34
+ response.should_not be_multipart
35
+ end
36
+ end
37
+ end
38
+
39
+ context "empty" do
40
+ let(:response) { HTTPI::Response.new 204, {}, nil }
41
+
42
+ describe "#body" do
43
+ it "returns an empty String" do
44
+ response.body.should == ""
45
+ end
46
+ end
47
+ end
48
+
49
+ context "multipart" do
50
+ let(:response) { HTTPI::Response.new 200, { "Content-Type" => "multipart/related" }, "multipart" }
51
+
52
+ describe "#multipart" do
53
+ it "returns true" do
54
+ response.should be_multipart
55
+ end
56
+ end
57
+ end
58
+
59
+ context "error" do
60
+ let(:response) { HTTPI::Response.new 404, {}, "" }
61
+
62
+ describe "#error?" do
63
+ it "returns true" do
64
+ response.should be_an_error
65
+ end
66
+ end
67
+ end
68
+
69
+ context "gzipped" do
70
+ let(:response) { HTTPI::Response.new 200, { "Content-Encoding" => "gzip" }, Fixture.gzip }
71
+
72
+ describe "#headers" do
73
+ it "returns the HTTP response headers" do
74
+ response.headers.should == { "Content-Encoding" => "gzip" }
75
+ end
76
+ end
77
+
78
+ describe "#body" do
79
+ it "returns the (gzip decoded) HTTP response body" do
80
+ response.body.should == Fixture.xml
81
+ end
82
+
83
+ it "bubbles Zlib errors" do
84
+ arbitrary_error = Class.new(ArgumentError)
85
+ Zlib::GzipReader.expects(:new).raises(arbitrary_error)
86
+ expect { response.body }.to raise_error(arbitrary_error)
87
+ end
88
+ end
89
+
90
+ describe "#raw_body" do
91
+ it "returns the raw HTML response body" do
92
+ response.raw_body.should == Fixture.gzip
93
+ end
94
+ end
95
+ end
96
+
97
+ context "DIME" do
98
+ let(:response) { HTTPI::Response.new 200, { "Content-Type" => "application/dime" }, Fixture.dime }
99
+
100
+ describe "#headers" do
101
+ it "returns the HTTP response headers" do
102
+ response.headers.should == { "Content-Type" => "application/dime" }
103
+ end
104
+ end
105
+
106
+ describe "#body" do
107
+ it "returns the (dime decoded) HTTP response body" do
108
+ response.body.should == Fixture.xml_dime
109
+ end
110
+ end
111
+
112
+ describe "#raw_body" do
113
+ it "returns the raw HTML response body" do
114
+ response.raw_body.should == Fixture.dime
115
+ end
116
+ end
117
+
118
+ describe "#attachments" do
119
+ it "returns proper attachment when given a dime response" do
120
+ response.attachments.first.data == File.read(File.expand_path("../../fixtures/attachment.gif", __FILE__))
121
+ end
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,95 @@
1
+ require "spec_helper"
2
+ require "httpi"
3
+ require "integration/server"
4
+
5
+ MockServer.new(IntegrationServer, 4000).start
6
+
7
+ describe HTTPI do
8
+ let(:client) { HTTPI }
9
+
10
+ before :all do
11
+ WebMock.allow_net_connect!
12
+
13
+ @username = "admin"
14
+ @password = "pwd"
15
+ @error_message = "Authorization Required"
16
+ @example_web_page = "Hello"
17
+ @content_type = "text/plain"
18
+ end
19
+
20
+ shared_examples_for "an HTTP client" do
21
+ it "and send HTTP headers" do
22
+ request = HTTPI::Request.new :url => "http://localhost:4000/x-header"
23
+ request.headers["X-Header"] = "HTTPI"
24
+
25
+ response = HTTPI.get request, adapter
26
+ response.body.should include("X-Header is HTTPI")
27
+ end
28
+
29
+ it "and execute an HTTP GET request" do
30
+ response = HTTPI.get "http://localhost:4000", adapter
31
+ response.body.should include(@example_web_page)
32
+ response.headers["Content-Type"].should include(@content_type)
33
+ end
34
+
35
+ it "and execute an HTTP POST request" do
36
+ response = HTTPI.post "http://localhost:4000", "<some>xml</some>", adapter
37
+ response.body.should include(@example_web_page)
38
+ response.headers["Content-Type"].should include(@content_type)
39
+ end
40
+
41
+ it "and execute an HTTP HEAD request" do
42
+ response = HTTPI.head "http://localhost:4000", adapter
43
+ response.code.should == 200
44
+ response.headers["Content-Type"].should include(@content_type)
45
+ end
46
+
47
+ it "and execute an HTTP PUT request" do
48
+ response = HTTPI.put "http://localhost:4000", "<some>xml</some>", adapter
49
+ response.body.should include("PUT is not allowed")
50
+ response.headers["Content-Type"].should include(@content_type)
51
+ end
52
+
53
+ it "and execute an HTTP DELETE request" do
54
+ response = HTTPI.delete "http://localhost:4000", adapter
55
+ response.body.should include("DELETE is not allowed")
56
+ response.headers["Content-Type"].should include(@content_type)
57
+ end
58
+ end
59
+
60
+ shared_examples_for "it works with HTTP basic auth" do
61
+ it "and access a secured page" do
62
+ request = HTTPI::Request.new :url => "http://localhost:4000/auth/basic"
63
+ request.auth.basic @username, @password
64
+
65
+ response = HTTPI.get request, adapter
66
+ response.body.should_not include(@error_message)
67
+ end
68
+ end
69
+
70
+ shared_examples_for "it works with HTTP digest auth" do
71
+ it "and access a secured page" do
72
+ request = HTTPI::Request.new :url => "http://localhost:4000/auth/digest"
73
+ request.auth.digest @username, @password
74
+
75
+ response = HTTPI.get request, adapter
76
+ response.body.should_not include(@error_message)
77
+ end
78
+ end
79
+
80
+ HTTPI::Adapter::ADAPTERS.keys.each do |adapter|
81
+ context "using :#{adapter}" do
82
+ let(:adapter) { adapter }
83
+ it_should_behave_like "an HTTP client"
84
+ it_should_behave_like "it works with HTTP basic auth"
85
+ end
86
+ end
87
+
88
+ (HTTPI::Adapter::ADAPTERS.keys - [:net_http]).each do |adapter|
89
+ context "using :#{adapter}" do
90
+ let(:adapter) { adapter }
91
+ it_should_behave_like "it works with HTTP digest auth"
92
+ end
93
+ end
94
+
95
+ end
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+ require "mock_server"
3
+
4
+ IntegrationServer = Rack::Builder.new do
5
+ map "/" do
6
+ run lambda {|env|
7
+ case env["REQUEST_METHOD"]
8
+ when "HEAD" then
9
+ [200, {"Content-Type" => "text/plain", "Content-Length" => "5"}, []]
10
+ when "GET", "POST" then
11
+ [200, {"Content-Type" => "text/plain", "Content-Length" => "5"}, ["Hello"]]
12
+ when "PUT", "DELETE"
13
+ body = "#{env["REQUEST_METHOD"]} is not allowed"
14
+ [200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
15
+ end
16
+ }
17
+ end
18
+
19
+ map "/x-header" do
20
+ run lambda {|env|
21
+ body = "X-Header is #{env["HTTP_X_HEADER"]}"
22
+ [200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
23
+ }
24
+ end
25
+
26
+ map "/auth" do
27
+ map "/basic" do
28
+ run Rack::Auth::Basic do |user, password|
29
+ user == "admin" && password == "secret"
30
+ end
31
+ end
32
+
33
+ map "/digest" do
34
+ run Rack::Auth::Digest::MD5 do |username|
35
+ {"admin" => "pwd"}[username]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ require "bundler"
2
+ Bundler.require :default, :development
3
+
4
+ RSpec.configure do |config|
5
+ config.include WebMock::API
6
+ config.mock_with :mocha
7
+ end
8
+
9
+ HTTPI.log = false # disable for specs
10
+
11
+ require "support/fixture"
12
+ require "support/matchers"
@@ -0,0 +1,27 @@
1
+ class Fixture
2
+ class << self
3
+
4
+ def xml
5
+ @xml ||= load :xml
6
+ end
7
+
8
+ def xml_dime
9
+ @xml_dime ||= load :xml_dime
10
+ end
11
+
12
+ def gzip
13
+ @gzip ||= load :xml, :gz
14
+ end
15
+
16
+ def dime
17
+ @dime ||= load :xml_dime, :dime
18
+ end
19
+
20
+ private
21
+
22
+ def load(fixture, type = :xml)
23
+ File.read File.expand_path("../../fixtures/#{fixture}.#{type}", __FILE__)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ RSpec::Matchers.define :match_response do |options|
2
+ defaults = { :code => 200, :headers => { "Accept-encoding" => "utf-8" }, :body => "" }
3
+ response = defaults.merge options
4
+
5
+ match do |actual|
6
+ actual.should be_an(HTTPI::Response)
7
+ actual.code.should == response[:code]
8
+ downcase(actual.headers).should == downcase(response[:headers])
9
+ actual.body.should == response[:body]
10
+ end
11
+
12
+ def downcase(hash)
13
+ hash.inject({}) do |memo, (key, value)|
14
+ memo[key.downcase] = value.downcase
15
+ memo
16
+ end
17
+ end
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httpi-ntlm
3
+ version: !ruby/object:Gem::Version
4
+ hash: 55
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 6
10
+ version: 0.9.6
11
+ platform: ruby
12
+ authors:
13
+ - Daniel Harrington
14
+ - Martin Tepper
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-06-29 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: pyu-ntlm-http
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 73
44
+ segments:
45
+ - 0
46
+ - 1
47
+ - 3
48
+ - 1
49
+ version: 0.1.3.1
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 2
63
+ - 2
64
+ version: "2.2"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: autotest
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: mocha
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 41
90
+ segments:
91
+ - 0
92
+ - 9
93
+ - 9
94
+ version: 0.9.9
95
+ type: :development
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ hash: 7
106
+ segments:
107
+ - 1
108
+ - 4
109
+ - 0
110
+ version: 1.4.0
111
+ type: :development
112
+ version_requirements: *id006
113
+ description: HTTPI provides a common interface for Ruby HTTP libraries.
114
+ email: me@rubiii.com
115
+ executables: []
116
+
117
+ extensions: []
118
+
119
+ extra_rdoc_files: []
120
+
121
+ files:
122
+ - .autotest
123
+ - .gitignore
124
+ - .rspec
125
+ - .travis.yml
126
+ - CHANGELOG.md
127
+ - Gemfile
128
+ - LICENSE
129
+ - README.md
130
+ - Rakefile
131
+ - autotest/discover.rb
132
+ - httpi-ntlm.gemspec
133
+ - lib/httpi-ntlm.rb
134
+ - lib/httpi.rb
135
+ - lib/httpi/adapter.rb
136
+ - lib/httpi/adapter/curb.rb
137
+ - lib/httpi/adapter/httpclient.rb
138
+ - lib/httpi/adapter/net_http.rb
139
+ - lib/httpi/auth/config.rb
140
+ - lib/httpi/auth/ssl.rb
141
+ - lib/httpi/dime.rb
142
+ - lib/httpi/request.rb
143
+ - lib/httpi/response.rb
144
+ - lib/httpi/version.rb
145
+ - spec/fixtures/attachment.gif
146
+ - spec/fixtures/client_cert.pem
147
+ - spec/fixtures/client_key.pem
148
+ - spec/fixtures/xml.gz
149
+ - spec/fixtures/xml.xml
150
+ - spec/fixtures/xml_dime.dime
151
+ - spec/fixtures/xml_dime.xml
152
+ - spec/httpi/adapter/curb_spec.rb
153
+ - spec/httpi/adapter/httpclient_spec.rb
154
+ - spec/httpi/adapter/net_http_spec.rb
155
+ - spec/httpi/adapter_spec.rb
156
+ - spec/httpi/auth/config_spec.rb
157
+ - spec/httpi/auth/ssl_spec.rb
158
+ - spec/httpi/httpi_spec.rb
159
+ - spec/httpi/request_spec.rb
160
+ - spec/httpi/response_spec.rb
161
+ - spec/integration/request_spec.rb
162
+ - spec/integration/server.rb
163
+ - spec/spec_helper.rb
164
+ - spec/support/fixture.rb
165
+ - spec/support/matchers.rb
166
+ homepage: http://github.com/rubiii/httpi
167
+ licenses: []
168
+
169
+ post_install_message:
170
+ rdoc_options: []
171
+
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ hash: 3
180
+ segments:
181
+ - 0
182
+ version: "0"
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ hash: 3
189
+ segments:
190
+ - 0
191
+ version: "0"
192
+ requirements: []
193
+
194
+ rubyforge_project: httpi-ntlm
195
+ rubygems_version: 1.8.5
196
+ signing_key:
197
+ specification_version: 3
198
+ summary: Interface for Ruby HTTP libraries
199
+ test_files: []
200
+