paul-resourceful 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/Manifest +30 -0
  2. data/Rakefile +44 -14
  3. data/lib/resourceful.rb +11 -21
  4. data/lib/resourceful/authentication_manager.rb +3 -2
  5. data/lib/resourceful/cache_manager.rb +58 -1
  6. data/lib/resourceful/exceptions.rb +34 -0
  7. data/lib/resourceful/header.rb +95 -0
  8. data/lib/resourceful/http_accessor.rb +0 -2
  9. data/lib/resourceful/memcache_cache_manager.rb +3 -13
  10. data/lib/resourceful/net_http_adapter.rb +15 -5
  11. data/lib/resourceful/request.rb +180 -18
  12. data/lib/resourceful/resource.rb +38 -141
  13. data/lib/resourceful/response.rb +142 -95
  14. data/resourceful.gemspec +9 -7
  15. data/spec/acceptance/authorization_spec.rb +16 -0
  16. data/spec/acceptance/caching_spec.rb +191 -0
  17. data/spec/acceptance/header_spec.rb +24 -0
  18. data/spec/acceptance/redirecting_spec.rb +12 -0
  19. data/spec/acceptance/resource_spec.rb +84 -0
  20. data/spec/acceptance_shared_specs.rb +12 -17
  21. data/spec/{acceptance_spec.rb → old_acceptance_specs.rb} +27 -57
  22. data/spec/simple_sinatra_server.rb +73 -0
  23. data/spec/simple_sinatra_server_spec.rb +98 -0
  24. data/spec/spec_helper.rb +21 -7
  25. metadata +55 -42
  26. data/spec/resourceful/authentication_manager_spec.rb +0 -249
  27. data/spec/resourceful/cache_manager_spec.rb +0 -223
  28. data/spec/resourceful/header_spec.rb +0 -38
  29. data/spec/resourceful/http_accessor_spec.rb +0 -164
  30. data/spec/resourceful/memcache_cache_manager_spec.rb +0 -111
  31. data/spec/resourceful/net_http_adapter_spec.rb +0 -96
  32. data/spec/resourceful/options_interpreter_spec.rb +0 -102
  33. data/spec/resourceful/request_spec.rb +0 -186
  34. data/spec/resourceful/resource_spec.rb +0 -600
  35. data/spec/resourceful/response_spec.rb +0 -238
  36. data/spec/resourceful/stubbed_resource_proxy_spec.rb +0 -58
  37. data/spec/simple_http_server_shared_spec.rb +0 -162
  38. data/spec/simple_http_server_shared_spec_spec.rb +0 -212
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,28 @@
1
1
  require 'rubygems'
2
- require 'pathname'
3
2
  require 'spec'
4
- require 'pp'
5
- require 'facets'
6
3
 
7
- $LOAD_PATH << Pathname(__FILE__).dirname + "../lib"
8
- require 'resourceful/util'
4
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
9
5
  require 'resourceful'
10
- require 'resourceful/http_accessor'
11
6
 
12
- require Pathname(__FILE__).dirname + 'simple_http_server_shared_spec'
7
+ $LOAD_PATH << File.dirname(__FILE__) # ./spec
13
8
 
9
+ # Spawn the server in another process
10
+
11
+ @server = Thread.new do
12
+
13
+ require 'simple_sinatra_server'
14
+ Sinatra::Default.set(
15
+ :run => true,
16
+ :logging => false
17
+ )
18
+
19
+ end
20
+
21
+ # Kill the server process when rspec finishes
22
+ at_exit { @server.exit }
23
+
24
+
25
+ # Give the app a change to initialize
26
+ $stderr.puts "Waiting for thin to initialize..."
27
+ sleep 0.2
14
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paul-resourceful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-05 00:00:00 -08:00
12
+ date: 2009-05-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: httpauth
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -32,6 +34,7 @@ dependencies:
32
34
  version:
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: rspec
37
+ type: :runtime
35
38
  version_requirement:
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
@@ -41,6 +44,7 @@ dependencies:
41
44
  version:
42
45
  - !ruby/object:Gem::Dependency
43
46
  name: facets
47
+ type: :runtime
44
48
  version_requirement:
45
49
  version_requirements: !ruby/object:Gem::Requirement
46
50
  requirements:
@@ -50,6 +54,7 @@ dependencies:
50
54
  version:
51
55
  - !ruby/object:Gem::Dependency
52
56
  name: andand
57
+ type: :runtime
53
58
  version_requirement:
54
59
  version_requirements: !ruby/object:Gem::Requirement
55
60
  requirements:
@@ -59,6 +64,7 @@ dependencies:
59
64
  version:
60
65
  - !ruby/object:Gem::Dependency
61
66
  name: thin
67
+ type: :development
62
68
  version_requirement:
63
69
  version_requirements: !ruby/object:Gem::Requirement
64
70
  requirements:
@@ -68,6 +74,17 @@ dependencies:
68
74
  version:
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: yard
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: sinatra
87
+ type: :development
71
88
  version_requirement:
72
89
  version_requirements: !ruby/object:Gem::Requirement
73
90
  requirements:
@@ -82,57 +99,53 @@ executables: []
82
99
  extensions: []
83
100
 
84
101
  extra_rdoc_files:
85
- - lib/resourceful.rb
86
- - lib/resourceful/authentication_manager.rb
87
- - lib/resourceful/util.rb
88
- - lib/resourceful/resource.rb
89
- - lib/resourceful/memcache_cache_manager.rb
102
+ - README.markdown
103
+ - lib/resourceful/cache_manager.rb
104
+ - lib/resourceful/exceptions.rb
90
105
  - lib/resourceful/net_http_adapter.rb
91
- - lib/resourceful/http_accessor.rb
92
106
  - lib/resourceful/stubbed_resource_proxy.rb
93
107
  - lib/resourceful/header.rb
94
- - lib/resourceful/cache_manager.rb
95
- - lib/resourceful/options_interpreter.rb
96
- - lib/resourceful/response.rb
97
- - lib/resourceful/request.rb
98
- - README.markdown
99
- files:
100
- - lib/resourceful.rb
101
108
  - lib/resourceful/authentication_manager.rb
102
- - lib/resourceful/util.rb
109
+ - lib/resourceful/request.rb
103
110
  - lib/resourceful/resource.rb
111
+ - lib/resourceful/response.rb
112
+ - lib/resourceful/util.rb
113
+ - lib/resourceful/http_accessor.rb
114
+ - lib/resourceful/options_interpreter.rb
104
115
  - lib/resourceful/memcache_cache_manager.rb
116
+ - lib/resourceful.rb
117
+ files:
118
+ - Manifest
119
+ - spec/spec.opts
120
+ - spec/simple_sinatra_server_spec.rb
121
+ - spec/simple_sinatra_server.rb
122
+ - spec/acceptance/header_spec.rb
123
+ - spec/acceptance/caching_spec.rb
124
+ - spec/acceptance/resource_spec.rb
125
+ - spec/acceptance/redirecting_spec.rb
126
+ - spec/acceptance/authorization_spec.rb
127
+ - spec/acceptance_shared_specs.rb
128
+ - spec/spec_helper.rb
129
+ - spec/old_acceptance_specs.rb
130
+ - README.markdown
131
+ - resourceful.gemspec
132
+ - lib/resourceful/cache_manager.rb
133
+ - lib/resourceful/exceptions.rb
105
134
  - lib/resourceful/net_http_adapter.rb
106
- - lib/resourceful/http_accessor.rb
107
135
  - lib/resourceful/stubbed_resource_proxy.rb
108
136
  - lib/resourceful/header.rb
109
- - lib/resourceful/cache_manager.rb
110
- - lib/resourceful/options_interpreter.rb
111
- - lib/resourceful/response.rb
137
+ - lib/resourceful/authentication_manager.rb
112
138
  - lib/resourceful/request.rb
113
- - spec/acceptance_shared_specs.rb
114
- - spec/spec.opts
115
- - spec/acceptance_spec.rb
116
- - spec/simple_http_server_shared_spec_spec.rb
117
- - spec/spec_helper.rb
118
- - spec/resourceful/header_spec.rb
119
- - spec/resourceful/authentication_manager_spec.rb
120
- - spec/resourceful/memcache_cache_manager_spec.rb
121
- - spec/resourceful/response_spec.rb
122
- - spec/resourceful/options_interpreter_spec.rb
123
- - spec/resourceful/http_accessor_spec.rb
124
- - spec/resourceful/stubbed_resource_proxy_spec.rb
125
- - spec/resourceful/request_spec.rb
126
- - spec/resourceful/resource_spec.rb
127
- - spec/resourceful/cache_manager_spec.rb
128
- - spec/resourceful/net_http_adapter_spec.rb
129
- - spec/simple_http_server_shared_spec.rb
130
- - Manifest
139
+ - lib/resourceful/resource.rb
140
+ - lib/resourceful/response.rb
141
+ - lib/resourceful/util.rb
142
+ - lib/resourceful/http_accessor.rb
143
+ - lib/resourceful/options_interpreter.rb
144
+ - lib/resourceful/memcache_cache_manager.rb
145
+ - lib/resourceful.rb
131
146
  - Rakefile
132
- - README.markdown
133
147
  - MIT-LICENSE
134
- - resourceful.gemspec
135
- has_rdoc: true
148
+ has_rdoc: false
136
149
  homepage: http://github.com/paul/resourceful
137
150
  post_install_message:
138
151
  rdoc_options:
@@ -161,7 +174,7 @@ requirements: []
161
174
  rubyforge_project: resourceful
162
175
  rubygems_version: 1.2.0
163
176
  signing_key:
164
- specification_version: 2
177
+ specification_version: 3
165
178
  summary: An HTTP library for Ruby that takes advantage of everything HTTP has to offer.
166
179
  test_files: []
167
180
 
@@ -1,249 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + '../spec_helper'
3
-
4
- require 'resourceful/authentication_manager'
5
-
6
- describe Resourceful::AuthenticationManager do
7
-
8
- before do
9
- @authmgr = Resourceful::AuthenticationManager.new
10
-
11
- @authenticator = mock('Authenticator')
12
- end
13
-
14
- [:add_auth_handler, :associate_auth_info, :add_credentials].each do |meth|
15
- it "should have ##{meth}" do
16
- @authmgr.should respond_to(meth)
17
- end
18
- end
19
-
20
- it 'should add an authenticator to its list' do
21
- @authmgr.add_auth_handler(@authenticator)
22
- @authmgr.instance_variable_get("@authenticators").should include(@authenticator)
23
- end
24
-
25
- describe 'associating authenticators with challanges' do
26
- before do
27
- @authmgr.add_auth_handler(@authenticator)
28
- @authenticator.stub!(:valid_for?).and_return(true)
29
- @authenticator.stub!(:update_credentials)
30
- @challenge = mock('Response')
31
- end
32
-
33
- it 'should check that an authenticator is valid for a challenge' do
34
- @authenticator.should_receive(:valid_for?).with(@challenge).and_return(true)
35
- @authmgr.associate_auth_info(@challenge)
36
- end
37
-
38
- it 'should update the credentials of the authenticator if it is valid for the challenge' do
39
- @authenticator.should_receive(:update_credentials).with(@challenge)
40
- @authmgr.associate_auth_info(@challenge)
41
- end
42
-
43
- it 'should not update the credentials of the authenticator if it is not valid for the challenge' do
44
- @authenticator.stub!(:valid_for?).and_return(false)
45
- @authenticator.should_not_receive(:update_credentials).with(@challenge)
46
- @authmgr.associate_auth_info(@challenge)
47
- end
48
-
49
- end
50
-
51
- describe 'adding credentials to a request' do
52
- before do
53
- @authmgr.add_auth_handler(@authenticator)
54
- @authenticator.stub!(:can_handle?).and_return(true)
55
- @authenticator.stub!(:add_credentials_to)
56
- @request = mock('Request')
57
- end
58
-
59
- it 'should find an authenticator that can handle the request' do
60
- @authenticator.should_receive(:can_handle?).with(@request).and_return(true)
61
- @authmgr.add_credentials(@request)
62
- end
63
-
64
- it 'should add the authenticators credentials to the request' do
65
- @authenticator.should_receive(:add_credentials_to).with(@request)
66
- @authmgr.add_credentials(@request)
67
- end
68
-
69
- it 'should not add the authenticators credentials to the request if it cant handle it' do
70
- @authenticator.should_receive(:can_handle?).with(@request).and_return(false)
71
- @authenticator.should_not_receive(:add_credentials_to).with(@request)
72
- @authmgr.add_credentials(@request)
73
- end
74
-
75
- end
76
-
77
- end
78
-
79
- describe Resourceful::BasicAuthenticator do
80
- before do
81
- @auth = Resourceful::BasicAuthenticator.new('Test Auth', 'admin', 'secret')
82
- end
83
-
84
- {:realm => 'Test Auth', :username => 'admin', :password => 'secret'}.each do |meth,val|
85
- it "should initialize with a #{meth}" do
86
- @auth.instance_variable_get("@#{meth}").should == val
87
- end
88
- end
89
-
90
- describe "Updating from a challenge response" do
91
- before do
92
- @header = {'WWW-Authenticate' => ['Basic realm="Test Auth"']}
93
- @chal = mock('response', :header => @header, :uri => 'http://example.com/foo/bar')
94
- end
95
-
96
- it 'should be valid for a challenge response with scheme "Basic" and the same realm' do
97
- @auth.valid_for?(@chal).should be_true
98
- end
99
-
100
- it 'should be valid for a challenge response with multiple schemes including matchin "Basic" challenge' do
101
- @header = {'WWW-Authenticate' => ['Digest some other stuff', 'Basic realm="Test Auth"', 'Weird scheme']}
102
-
103
- @auth.valid_for?(@chal).should be_true
104
- end
105
-
106
- it 'should not be sensitive to case variances in the scheme' do
107
- @header['WWW-Authenticate'] = ['bAsIc realm="Test Auth"']
108
- @auth.valid_for?(@chal).should be_true
109
- end
110
-
111
- it 'should not be sensitive to case variances in the realm directive' do
112
- @header['WWW-Authenticate'] = ['Basic rEaLm="Test Auth"']
113
- @auth.valid_for?(@chal).should be_true
114
- end
115
-
116
- it 'should not be sensitive to case variances in the realm value' do
117
- @header['WWW-Authenticate'] = ['Basic realm="test auth"']
118
- @auth.valid_for?(@chal).should be_true
119
- end
120
-
121
- it 'should not be valid if the scheme is not "Basic"' do
122
- @header['WWW-Authenticate'] = ["Digest"]
123
- @auth.valid_for?(@chal).should be_false
124
- end
125
-
126
- it 'should not be valid if the realm does not match' do
127
- @header['WWW-Authenticate'] = ['Basic realm="not test auth"']
128
- @auth.valid_for?(@chal).should be_false
129
- end
130
-
131
- it 'should not be valid if the header is unreadable' do
132
- @header['WWW-Authenticate'] = nil
133
- @auth.valid_for?(@chal).should be_false
134
- end
135
-
136
- it 'should set the valid domain from the host part of the challenge uri' do
137
- @auth.update_credentials(@chal)
138
- @auth.instance_variable_get("@domain").should == 'example.com'
139
- end
140
-
141
- end
142
-
143
- describe 'updating a request with credentials' do
144
- before do
145
- @auth.instance_variable_set("@domain", 'example.com')
146
- @header = {}
147
- @req = mock('request', :uri => 'http://example.com/bar/foo', :header => @header)
148
- end
149
-
150
- it 'should be able to handle a request for the matching domain' do
151
- @auth.can_handle?(@req).should be_true
152
- end
153
-
154
- it 'should add credentials to a request' do
155
- @header.should_receive(:[]=).with('Authorization', 'Basic YWRtaW46c2VjcmV0')
156
- @auth.add_credentials_to(@req)
157
- end
158
-
159
- it 'should build the credentials string for the header' do
160
- @auth.credentials.should == 'Basic YWRtaW46c2VjcmV0'
161
- end
162
- end
163
-
164
- end
165
-
166
- describe Resourceful::DigestAuthenticator do
167
-
168
- before do
169
- @header = {'WWW-Authenticate' => ['Digest realm="Test Auth"']}
170
- @chal = mock('response', :header => @header, :uri => 'http://example.com/foo/bar')
171
-
172
- @req_header = {}
173
- @req = mock('request', :header => @req_header,
174
- :uri => 'http://example.com',
175
- :method => 'GET')
176
-
177
- @auth = Resourceful::DigestAuthenticator.new('Test Auth', 'admin', 'secret')
178
- end
179
-
180
- {:realm => 'Test Auth', :username => 'admin', :password => 'secret'}.each do |meth,val|
181
- it "should initialize with a #{meth}" do
182
- @auth.instance_variable_get("@#{meth}").should == val
183
- end
184
- end
185
-
186
- describe "Updating credentials from a challenge response" do
187
-
188
- it "should set the domain from the host part of the challenge response uri" do
189
- @auth.update_credentials(@chal)
190
- @auth.domain.should == 'example.com'
191
- end
192
-
193
- it "should create an HTTPAuth Digest Challenge from the challenge response WWW-Authenticate header" do
194
- HTTPAuth::Digest::Challenge.should_receive(:from_header).with(@header['WWW-Authenticate'].first)
195
- @auth.update_credentials(@chal)
196
- end
197
-
198
- end
199
-
200
- describe "Validating a challenge" do
201
- it 'should be valid for a challenge response with scheme "Digest" and the same realm' do
202
- @auth.valid_for?(@chal).should be_true
203
- end
204
-
205
- it 'should not be valid if the scheme is not "Digest"' do
206
- @header['WWW-Authenticate'] = ["Basic"]
207
- @auth.valid_for?(@chal).should be_false
208
- end
209
-
210
- it 'should not be valid if the realm does not match' do
211
- @header['WWW-Authenticate'] = ['Digest realm="not test auth"']
212
- @auth.valid_for?(@chal).should be_false
213
- end
214
-
215
- it 'should not be valid if the header is unreadable' do
216
- @header['WWW-Authenticate'] = nil
217
- @auth.valid_for?(@chal).should be_false
218
- end
219
- end
220
-
221
- it "should be able to handle requests to the same domain" do
222
- @auth.instance_variable_set("@domain", 'example.com')
223
- @auth.can_handle?(@req).should be_true
224
- end
225
-
226
- it "should not handle requests to a different domain" do
227
- @auth.instance_variable_set("@domain", 'example2.com')
228
- @auth.can_handle?(@req).should be_false
229
- end
230
-
231
- it "should add credentials to a request" do
232
- @auth.update_credentials(@chal)
233
- @auth.add_credentials_to(@req)
234
- @req_header.should have_key('Authorization')
235
- @req_header['Authorization'].should_not be_blank
236
- end
237
-
238
- it "should have HTTPAuth::Digest generate the Authorization header" do
239
- @auth.update_credentials(@chal)
240
- cred = mock('digest_credentials', :to_header => nil)
241
-
242
- HTTPAuth::Digest::Credentials.should_receive(:from_challenge).with(
243
- @auth.challenge, :username => 'admin', :password => 'secret', :method => 'GET', :uri => ''
244
- ).and_return(cred)
245
-
246
- cred = @auth.credentials_for(@req)
247
- end
248
-
249
- end