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 +24 -28
  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 +192 -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 +74 -0
  23. data/spec/simple_sinatra_server_spec.rb +98 -0
  24. data/spec/spec_helper.rb +21 -7
  25. metadata +50 -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
@@ -1,212 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname + 'spec_helper'
3
- require 'rubygems'
4
- require 'addressable/uri'
5
-
6
- require 'resourceful/net_http_adapter'
7
-
8
- describe 'http server' do
9
- it_should_behave_like 'simple http server'
10
-
11
- it 'should have a response code of 200 if the path is /get' do
12
- Resourceful::NetHttpAdapter.make_request(:get, 'http://localhost:3000/get')[0].should == 200
13
- end
14
-
15
- it 'should reply with the posted document in the body if the path is /post' do
16
- resp = Resourceful::NetHttpAdapter.make_request(:get, 'http://localhost:3000/post', 'Hello from POST!')
17
- resp[2].should == 'Hello from POST!'
18
- resp[0].should == 201
19
- end
20
-
21
- it 'should reply with the puted document in the body if the path is /put' do
22
- resp = Resourceful::NetHttpAdapter.make_request(:put, 'http://localhost:3000/put', 'Hello from PUT!')
23
- resp[2].should == 'Hello from PUT!'
24
- resp[0].should == 200
25
- end
26
-
27
- it 'should reply with "KABOOM!" in the body if the path is /delete' do
28
- resp = Resourceful::NetHttpAdapter.make_request(:delete, 'http://localhost:3000/delete')
29
- resp[2].should == 'KABOOM!'
30
- resp[0].should == 200
31
- end
32
-
33
- it 'should have a response code of whatever the path is' do
34
- Resourceful::NetHttpAdapter.make_request(:get, 'http://localhost:3000/code/304')[0].should == 304
35
- end
36
-
37
- it 'should redirect to a given url' do
38
- resp = Resourceful::NetHttpAdapter.make_request(:get, 'http://localhost:3000/redirect/301?http://localhost:3000/get')
39
-
40
- resp[0].should == 301
41
- resp[1]['Location'].should == ['http://localhost:3000/get']
42
- end
43
-
44
- it 'should respond with the request method in the body' do
45
- resp = Resourceful::NetHttpAdapter.make_request(:delete, 'http://localhost:3000/method')
46
-
47
- resp[0].should == 200
48
- resp[2].should == "DELETE"
49
- end
50
-
51
- it 'should respond with the header set from the query string' do
52
- uri = URI.escape('http://localhost:3000/header?{Foo: "bar"}')
53
- resp = Resourceful::NetHttpAdapter.make_request(:get, uri)
54
-
55
- resp[1].should have_key('Foo')
56
- resp[1]['Foo'].should == ['bar']
57
- end
58
-
59
- it 'should allow the Date header to be overridden' do
60
- uri = URI.escape("http://localhost:3000/header?{Date: \"Thu, 21 Aug 2008 20:00:00 GMT\"}")
61
- resp = Resourceful::NetHttpAdapter.make_request(:get, uri)
62
-
63
- resp[1].should have_key('Date')
64
- resp[1]['Date'].should == ['Thu, 21 Aug 2008 20:00:00 GMT']
65
- end
66
-
67
-
68
- it 'should parse escaped uris properly' do
69
- uri = URI.escape("http://localhost:3000/header?{Expire: \"#{Time.now.httpdate}\"}")
70
-
71
- resp = Resourceful::NetHttpAdapter.make_request(:get, uri)
72
-
73
- resp[1].should have_key('Expire')
74
- resp[1]['Expire'].first.should_not =~ /%/
75
- end
76
-
77
- it 'should echo the request header in the response body' do
78
- uri = URI.escape("http://localhost:3000/echo_header")
79
-
80
- resp = Resourceful::NetHttpAdapter.make_request(:get, uri)
81
-
82
- resp[2].should =~ /HTTP_HOST/
83
- end
84
-
85
- describe '/modified' do
86
- it 'should be 200 if no I-M-S header' do
87
- uri = URI.escape("http://localhost:3000/modified?#{(Time.now + 3600).httpdate}")
88
-
89
- resp = Resourceful::NetHttpAdapter.make_request(:get, uri)
90
-
91
- resp[0].should == 200
92
- end
93
-
94
- it 'should be 304 if I-M-S header is set' do
95
- now = Time.utc(2008,5,29,12,00)
96
- uri = URI.escape("http://localhost:3000/modified?#{(now + 3600).httpdate}")
97
-
98
- resp = Resourceful::NetHttpAdapter.make_request(:get, uri, nil, {'If-Modified-Since' => now.httpdate})
99
-
100
- resp[0].should == 304
101
- end
102
-
103
- end
104
-
105
- describe '/auth' do
106
- before do
107
- @uri = "http://localhost:3000/auth?basic"
108
- end
109
-
110
- it 'should return a 401 if no auth info is provided' do
111
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
112
- resp[0].should == 401
113
- end
114
-
115
- describe 'basic' do
116
- before do
117
- @uri = "http://localhost:3000/auth?basic"
118
- end
119
-
120
- it 'should return a 401 if no auth info is provided' do
121
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
122
- resp[0].should == 401
123
- end
124
-
125
- it 'should provide a WWW-Authenticate header when 401' do
126
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
127
- header = resp[1]
128
- header.should have_key('WWW-Authenticate')
129
- end
130
-
131
- it 'should set the scheme to "Basic"' do
132
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
133
- auth = resp[1]['WWW-Authenticate'].first
134
- auth.should =~ /^Basic/
135
- end
136
-
137
- it 'should set the realm to "Test Auth"' do
138
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
139
- auth = resp[1]['WWW-Authenticate'].first
140
- auth.should =~ /realm="Test Auth"/
141
- end
142
-
143
- it 'should authorize on u/p:admin/secret' do
144
- creds = HTTPAuth::Basic.pack_authorization('admin', 'secret')
145
- header = {'Authorization' => creds}
146
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri, nil, header)
147
- resp[0].should == 200
148
- end
149
-
150
- it 'should authorize if u/p is incorrect' do
151
- creds = HTTPAuth::Basic.pack_authorization('admin', 'not secret')
152
- header = {'Authorization' => creds}
153
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri, nil, header)
154
- resp[0].should == 401
155
- end
156
-
157
- end
158
-
159
- describe 'digest' do
160
- before do
161
- @uri = "http://localhost:3000/auth?digest"
162
- end
163
-
164
- it 'should return a 401 if no auth info is provided' do
165
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
166
- resp[0].should == 401
167
- end
168
-
169
- it 'should provide a WWW-Authenticate header when 401' do
170
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
171
- header = resp[1]
172
- header.should have_key('WWW-Authenticate')
173
- end
174
-
175
- it 'should set the scheme to "Digest"' do
176
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
177
- auth = resp[1]['WWW-Authenticate'].first
178
- auth.should =~ /^Digest/
179
- end
180
-
181
- it 'should set the realm to "Test Auth"' do
182
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
183
- auth = resp[1]['WWW-Authenticate'].first
184
- auth.should =~ /realm="Test Auth"/
185
- end
186
-
187
- def challenge
188
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri)
189
- HTTPAuth::Digest::Challenge.from_header(resp[1]['WWW-Authenticate'].first)
190
- end
191
-
192
- it 'should authorize on u/p:admin/secret' do
193
- creds = HTTPAuth::Digest::Credentials.from_challenge(challenge, :username => 'admin', :password => 'secret', :uri => @uri)
194
- header = {'Authorization' => creds.to_header}
195
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri, nil, header)
196
- resp[0].should == 200
197
- end
198
-
199
- it 'should not authorize if u/p is incorrect' do
200
- pending
201
- creds = HTTPAuth::Digest::Credentials.from_challenge(challenge, :username => 'admin', :password => 'not secret', :uri => @uri)
202
- header = {'Authorization' => creds.to_header}
203
- resp = Resourceful::NetHttpAdapter.make_request(:get, @uri, nil, header)
204
- resp[0].should == 401
205
- end
206
-
207
- end
208
-
209
- end
210
-
211
- end
212
-