warden 1.2.3 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/{History.rdoc → CHANGELOG.md} +16 -3
  6. data/Gemfile +3 -2
  7. data/Gemfile.lock +40 -0
  8. data/LICENSE +1 -1
  9. data/README.md +18 -0
  10. data/Rakefile +4 -8
  11. data/lib/warden/config.rb +3 -3
  12. data/lib/warden/errors.rb +2 -1
  13. data/lib/warden/hooks.rb +10 -9
  14. data/lib/warden/manager.rb +23 -10
  15. data/lib/warden/mixins/common.rb +2 -1
  16. data/lib/warden/proxy.rb +27 -11
  17. data/lib/warden/session_serializer.rb +1 -0
  18. data/lib/warden/strategies/base.rb +14 -8
  19. data/lib/warden/strategies.rb +1 -0
  20. data/lib/warden/test/helpers.rb +3 -2
  21. data/lib/warden/test/mock.rb +69 -0
  22. data/lib/warden/test/warden_helpers.rb +2 -1
  23. data/lib/warden/version.rb +2 -1
  24. data/lib/warden.rb +2 -0
  25. data/warden.gemspec +21 -18
  26. metadata +33 -50
  27. data/README.textile +0 -9
  28. data/spec/helpers/request_helper.rb +0 -51
  29. data/spec/helpers/strategies/failz.rb +0 -8
  30. data/spec/helpers/strategies/invalid.rb +0 -8
  31. data/spec/helpers/strategies/pass.rb +0 -8
  32. data/spec/helpers/strategies/pass_with_message.rb +0 -8
  33. data/spec/helpers/strategies/password.rb +0 -13
  34. data/spec/helpers/strategies/single.rb +0 -12
  35. data/spec/spec_helper.rb +0 -24
  36. data/spec/warden/authenticated_data_store_spec.rb +0 -114
  37. data/spec/warden/config_spec.rb +0 -48
  38. data/spec/warden/errors_spec.rb +0 -47
  39. data/spec/warden/hooks_spec.rb +0 -373
  40. data/spec/warden/manager_spec.rb +0 -316
  41. data/spec/warden/proxy_spec.rb +0 -1041
  42. data/spec/warden/scoped_session_serializer.rb +0 -123
  43. data/spec/warden/session_serializer_spec.rb +0 -53
  44. data/spec/warden/strategies/base_spec.rb +0 -313
  45. data/spec/warden/strategies_spec.rb +0 -93
  46. data/spec/warden/test/helpers_spec.rb +0 -93
  47. data/spec/warden/test/test_mode_spec.rb +0 -76
@@ -1,373 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe "standard authentication hooks" do
5
-
6
- before(:all) do
7
- load_strategies
8
- end
9
-
10
- describe "after_set_user" do
11
- before(:each) do
12
- RAM = Warden::Manager unless defined?(RAM)
13
- RAM._after_set_user.clear
14
- end
15
-
16
- after(:each) do
17
- RAM._after_set_user.clear
18
- end
19
-
20
- it "should allow me to add an after_set_user hook" do
21
- RAM.after_set_user do |user, auth, opts|
22
- "boo"
23
- end
24
- RAM._after_set_user.should have(1).item
25
- end
26
-
27
- it "should allow me to add multiple after_set_user hooks" do
28
- RAM.after_set_user{|user, auth, opts| "foo"}
29
- RAM.after_set_user{|u,a| "bar"}
30
- RAM._after_set_user.should have(2).items
31
- end
32
-
33
- it "should run each after_set_user hook after the user is set" do
34
- RAM.after_set_user{|u,a,o| a.env['warden.spec.hook.foo'] = "run foo"}
35
- RAM.after_set_user{|u,a,o| a.env['warden.spec.hook.bar'] = "run bar"}
36
- RAM.after_set_user{|u,a,o| a.logout}
37
- app = lambda do |e|
38
- e['warden'].set_user("foo")
39
- valid_response
40
- end
41
- env = env_with_params
42
- setup_rack(app).call(env)
43
- env['warden'].user.should be_nil
44
- env['warden.spec.hook.foo'].should == "run foo"
45
- env['warden.spec.hook.bar'].should == "run bar"
46
- end
47
-
48
- it "should not run the event specified with except" do
49
- RAM.after_set_user(:except => :set_user){|u,a,o| fail}
50
- app = lambda do |e|
51
- e['warden'].set_user("foo")
52
- valid_response
53
- end
54
- env = env_with_params
55
- setup_rack(app).call(env)
56
- end
57
-
58
- it "should only run the event specified with only" do
59
- RAM.after_set_user(:only => :set_user){|u,a,o| fail}
60
- app = lambda do |e|
61
- e['warden'].authenticate(:pass)
62
- valid_response
63
- end
64
- env = env_with_params
65
- setup_rack(app).call(env)
66
- end
67
-
68
- it "should run filters in the given order" do
69
- RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 2}
70
- RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 3}
71
- RAM.prepend_after_set_user{|u,a,o| a.env['warden.spec.order'] << 1}
72
- app = lambda do |e|
73
- e['warden.spec.order'] = []
74
- e['warden'].set_user("foo")
75
- valid_response
76
- end
77
- env = env_with_params
78
- setup_rack(app).call(env)
79
- env['warden.spec.order'].should == [1,2,3]
80
- end
81
-
82
- context "after_authentication" do
83
- it "should be a wrapper to after_set_user behavior" do
84
- RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
85
- RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
86
- RAM.after_authentication{|u,a,o| o[:event].should == :authentication }
87
- app = lambda do |e|
88
- e['warden'].authenticate(:pass)
89
- valid_response
90
- end
91
- env = env_with_params
92
- setup_rack(app).call(env)
93
- env['warden.spec.hook.baz'].should == 'run baz'
94
- env['warden.spec.hook.paz'].should == 'run paz'
95
- end
96
-
97
- it "should not be invoked on default after_set_user scenario" do
98
- RAM.after_authentication{|u,a,o| fail}
99
- app = lambda do |e|
100
- e['warden'].set_user("foo")
101
- valid_response
102
- end
103
- env = env_with_params
104
- setup_rack(app).call(env)
105
- end
106
-
107
- it "should run filters in the given order" do
108
- RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 2}
109
- RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 3}
110
- RAM.prepend_after_authentication{|u,a,o| a.env['warden.spec.order'] << 1}
111
- app = lambda do |e|
112
- e['warden.spec.order'] = []
113
- e['warden'].authenticate(:pass)
114
- valid_response
115
- end
116
- env = env_with_params
117
- setup_rack(app).call(env)
118
- env['warden.spec.order'].should == [1,2,3]
119
- end
120
-
121
- it "should allow me to log out a user in an after_set_user block" do
122
- RAM.after_set_user{|u,a,o| a.logout}
123
-
124
- app = lambda do |e|
125
- e['warden'].authenticate(:pass)
126
- valid_response
127
- end
128
- env = env_with_params
129
- setup_rack(app).call(env)
130
- env['warden'].authenticated?.should be_false
131
- end
132
- end
133
-
134
- context "after_fetch" do
135
- it "should be a wrapper to after_set_user behavior" do
136
- RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
137
- RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
138
- RAM.after_fetch{|u,a,o| o[:event].should == :fetch }
139
- env = env_with_params
140
- setup_rack(lambda { |e| valid_response }).call(env)
141
- env['rack.session']['warden.user.default.key'] = "Foo"
142
- env['warden'].user.should == "Foo"
143
- env['warden.spec.hook.baz'].should == 'run baz'
144
- env['warden.spec.hook.paz'].should == 'run paz'
145
- end
146
-
147
- it "should not be invoked on default after_set_user scenario" do
148
- RAM.after_fetch{|u,a,o| fail}
149
- app = lambda do |e|
150
- e['warden'].set_user("foo")
151
- valid_response
152
- end
153
- env = env_with_params
154
- setup_rack(app).call(env)
155
- end
156
-
157
- it "should not be invoked if fetched user is nil" do
158
- RAM.after_fetch{|u,a,o| fail}
159
- env = env_with_params
160
- setup_rack(lambda { |e| valid_response }).call(env)
161
- env['rack.session']['warden.user.default.key'] = nil
162
- env['warden'].user.should be_nil
163
- end
164
-
165
- it "should run filters in the given order" do
166
- RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 2}
167
- RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 3}
168
- RAM.prepend_after_fetch{|u,a,o| a.env['warden.spec.order'] << 1}
169
- app = lambda do |e|
170
- e['warden.spec.order'] = []
171
- e['rack.session']['warden.user.default.key'] = "Foo"
172
- e['warden'].user
173
- valid_response
174
- end
175
- env = env_with_params
176
- setup_rack(app).call(env)
177
- env['warden.spec.order'].should == [1,2,3]
178
- end
179
- end
180
- end
181
-
182
-
183
- describe "after_failed_fetch" do
184
- before(:each) do
185
- RAM = Warden::Manager unless defined?(RAM)
186
- RAM._after_failed_fetch.clear
187
- end
188
-
189
- after(:each) do
190
- RAM._after_failed_fetch.clear
191
- end
192
-
193
- it "should not be called when user is fetched" do
194
- RAM.after_failed_fetch{|u,a,o| fail }
195
- env = env_with_params
196
- setup_rack(lambda { |e| valid_response }).call(env)
197
- env['rack.session']['warden.user.default.key'] = "Foo"
198
- env['warden'].user.should == "Foo"
199
- end
200
-
201
- it "should be called if fetched user is nil" do
202
- calls = 0
203
- RAM.after_failed_fetch{|u,a,o| calls += 1 }
204
- env = env_with_params
205
- setup_rack(lambda { |e| valid_response }).call(env)
206
- env['warden'].user.should be_nil
207
- calls.should == 1
208
- end
209
- end
210
-
211
- describe "before_failure" do
212
- before(:each) do
213
- RAM = Warden::Manager unless defined?(RAM)
214
- RAM._before_failure.clear
215
- end
216
-
217
- after(:each) do
218
- RAM._before_failure.clear
219
- end
220
-
221
- it "should allow me to add a before_failure hook" do
222
- RAM.before_failure{|env, opts| "foo"}
223
- RAM._before_failure.should have(1).item
224
- end
225
-
226
- it "should allow me to add multiple before_failure hooks" do
227
- RAM.before_failure{|env, opts| "foo"}
228
- RAM.before_failure{|env, opts| "bar"}
229
- RAM._before_failure.should have(2).items
230
- end
231
-
232
- it "should run each before_failure hooks before failing" do
233
- RAM.before_failure{|e,o| e['warden.spec.before_failure.foo'] = "foo"}
234
- RAM.before_failure{|e,o| e['warden.spec.before_failure.bar'] = "bar"}
235
- app = lambda{|e| e['warden'].authenticate!(:failz); valid_response}
236
- env = env_with_params
237
- setup_rack(app).call(env)
238
- env['warden.spec.before_failure.foo'].should == "foo"
239
- env['warden.spec.before_failure.bar'].should == "bar"
240
- end
241
-
242
- it "should run filters in the given order" do
243
- RAM.before_failure{|e,o| e['warden.spec.order'] << 2}
244
- RAM.before_failure{|e,o| e['warden.spec.order'] << 3}
245
- RAM.prepend_before_failure{|e,o| e['warden.spec.order'] << 1}
246
- app = lambda do |e|
247
- e['warden.spec.order'] = []
248
- e['warden'].authenticate!(:failz)
249
- valid_response
250
- end
251
- env = env_with_params
252
- setup_rack(app).call(env)
253
- env['warden.spec.order'].should == [1,2,3]
254
- end
255
- end
256
-
257
- describe "before_logout" do
258
- before(:each) do
259
- RAM = Warden::Manager unless defined?(RAM)
260
- RAM._before_logout.clear
261
- end
262
-
263
- after(:each) do
264
- RAM._before_logout.clear
265
- end
266
-
267
- it "should allow me to add an before_logout hook" do
268
- RAM.before_logout{|user, auth, scopes| "foo"}
269
- RAM._before_logout.should have(1).item
270
- end
271
-
272
- it "should allow me to add multiple after_authentication hooks" do
273
- RAM.before_logout{|u,a,o| "bar"}
274
- RAM.before_logout{|u,a,o| "baz"}
275
- RAM._before_logout.should have(2).items
276
- end
277
-
278
- it "should run each before_logout hook before logout is run" do
279
- RAM.before_logout{|u,a,o| a.env['warden.spec.hook.lorem'] = "run lorem"}
280
- RAM.before_logout{|u,a,o| a.env['warden.spec.hook.ipsum'] = "run ipsum"}
281
- app = lambda{|e| e['warden'].authenticate(:pass); valid_response}
282
- env = env_with_params
283
- setup_rack(app).call(env)
284
- env['warden'].logout
285
- env['warden.spec.hook.lorem'].should == 'run lorem'
286
- env['warden.spec.hook.ipsum'].should == 'run ipsum'
287
- end
288
-
289
- it "should run before_logout hook for a specified scope" do
290
- RAM.before_logout(:scope => :scope1){|u,a,o| a.env["warden.spec.hook.a"] << :scope1 }
291
- RAM.before_logout(:scope => [:scope2]){|u,a,o| a.env["warden.spec.hook.b"] << :scope2 }
292
-
293
- app = lambda do |e|
294
- e['warden'].authenticate(:pass, :scope => :scope1)
295
- e['warden'].authenticate(:pass, :scope => :scope2)
296
- valid_response
297
- end
298
- env = env_with_params
299
- env["warden.spec.hook.a"] ||= []
300
- env["warden.spec.hook.b"] ||= []
301
- setup_rack(app).call(env)
302
-
303
- env['warden'].logout(:scope1)
304
- env['warden.spec.hook.a'].should == [:scope1]
305
- env['warden.spec.hook.b'].should == []
306
-
307
- env['warden'].logout(:scope2)
308
- env['warden.spec.hook.a'].should == [:scope1]
309
- env['warden.spec.hook.b'].should == [:scope2]
310
- end
311
-
312
- it "should run filters in the given order" do
313
- RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 2}
314
- RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 3}
315
- RAM.prepend_before_logout{|u,a,o| a.env['warden.spec.order'] << 1}
316
- app = lambda do |e|
317
- e['warden.spec.order'] = []
318
- e['warden'].authenticate(:pass)
319
- e['warden'].logout
320
- valid_response
321
- end
322
- env = env_with_params
323
- setup_rack(app).call(env)
324
- env['warden.spec.order'].should == [1,2,3]
325
- end
326
- end
327
-
328
- describe "on_request" do
329
- before(:each) do
330
- @old_on_request = RAM._on_request.dup
331
- RAM = Warden::Manager unless defined?(RAM)
332
- RAM._on_request.clear
333
- end
334
-
335
- after(:each) do
336
- RAM._on_request.clear
337
- RAM._on_request.replace(@old_on_request)
338
- end
339
-
340
- it "should allow me to add an on_request hook" do
341
- RAM.on_request{|proxy| "foo"}
342
- RAM._on_request.should have(1).item
343
- end
344
-
345
- it "should allow me to add multiple on_request hooks" do
346
- RAM.on_request{|proxy| "foo"}
347
- RAM.on_request{|proxy| "bar"}
348
- RAM._on_request.should have(2).items
349
- end
350
-
351
- it "should run each on_request hooks when initializing" do
352
- RAM.on_request{|proxy| proxy.env['warden.spec.on_request.foo'] = "foo"}
353
- RAM.on_request{|proxy| proxy.env['warden.spec.on_request.bar'] = "bar"}
354
- app = lambda{|e| valid_response}
355
- env = env_with_params
356
- setup_rack(app).call(env)
357
- env['warden.spec.on_request.foo'].should == "foo"
358
- env['warden.spec.on_request.bar'].should == "bar"
359
- end
360
-
361
- it "should run filters in the given order" do
362
- RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 2}
363
- RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 3}
364
- RAM.prepend_on_request{|proxy| proxy.env['warden.spec.order'] << 1}
365
- app = lambda do |e|
366
- valid_response
367
- end
368
- env = Rack::MockRequest.env_for("/", "warden.spec.order" => [])
369
- setup_rack(app).call(env)
370
- env['warden.spec.order'].should == [1,2,3]
371
- end
372
- end
373
- end
@@ -1,316 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Warden::Manager do
5
-
6
- before(:all) do
7
- load_strategies
8
- end
9
-
10
- it "should insert a Proxy object into the rack env" do
11
- env = env_with_params
12
- setup_rack(success_app).call(env)
13
- env["warden"].should be_an_instance_of(Warden::Proxy)
14
- end
15
-
16
- describe "thrown auth" do
17
- before(:each) do
18
- @basic_app = lambda{|env| [200,{'Content-Type' => 'text/plain'},'OK']}
19
- @authd_app = lambda do |e|
20
- if e['warden'].authenticated?
21
- [200,{'Content-Type' => 'text/plain'},"OK"]
22
- else
23
- [401,{'Content-Type' => 'text/plain'},"Fail From The App"]
24
- end
25
- end
26
- @env = Rack::MockRequest.
27
- env_for('/', 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => 'GET')
28
- end # before(:each)
29
-
30
- describe "Failure" do
31
- it "should respond with a 401 response if the strategy fails authentication" do
32
- env = env_with_params("/", :foo => "bar")
33
- app = lambda do |env|
34
- env['warden'].authenticate(:failz)
35
- throw(:warden, :action => :unauthenticated)
36
- end
37
- result = setup_rack(app, :failure_app => @fail_app).call(env)
38
- result.first.should == 401
39
- end
40
-
41
- it "should use the failure message given to the failure method" do
42
- env = env_with_params("/", {})
43
- app = lambda do |env|
44
- env['warden'].authenticate(:failz)
45
- throw(:warden)
46
- end
47
- result = setup_rack(app, :failure_app => @fail_app).call(env)
48
- result.last.should == ["You Fail!"]
49
- end
50
-
51
- it "should render the failure app when there's a failure" do
52
- app = lambda do |e|
53
- throw(:warden, :action => :unauthenticated) unless e['warden'].authenticated?(:failz)
54
- end
55
- fail_app = lambda do |e|
56
- [401, {"Content-Type" => "text/plain"}, ["Failure App"]]
57
- end
58
- result = setup_rack(app, :failure_app => fail_app).call(env_with_params)
59
- result.last.should == ["Failure App"]
60
- end
61
-
62
- it "should call failure app if warden is thrown even after successful authentication" do
63
- env = env_with_params("/", {})
64
- app = lambda do |env|
65
- env['warden'].authenticate(:pass)
66
- throw(:warden)
67
- end
68
- result = setup_rack(app, :failure_app => @fail_app).call(env)
69
- result.first.should == 401
70
- result.last.should == ["You Fail!"]
71
- end
72
-
73
- it "should set the attempted url in warden.options hash" do
74
- env = env_with_params("/access/path", {})
75
- app = lambda do |env|
76
- env['warden'].authenticate(:pass)
77
- throw(:warden)
78
- end
79
- result = setup_rack(app, :failure_app => @fail_app).call(env)
80
- result.first.should == 401
81
- env["warden.options"][:attempted_path].should == "/access/path"
82
- end
83
-
84
- it "should catch a resubmitted request" do
85
- # this is a bit convoluted. but it's occurred in the field with Rack::OpenID
86
- $count = 0
87
- $throw_count = 0
88
- env = env_with_params("/foo")
89
- class ::ResubmittingMiddleware
90
- @@app = nil
91
- def initialize(app)
92
- @@app = app
93
- end
94
-
95
- def self.call(env)
96
- if $count > 1
97
- Rack::Response.new("Bad", 401)
98
- else
99
- $count += 1
100
- @@app.call(env)
101
- end
102
- end
103
-
104
- def call(env)
105
- $count += 1
106
- @@app.call(env)
107
- end
108
-
109
- end
110
-
111
- app = lambda do |e|
112
- $throw_count += 1
113
- throw(:warden)
114
- end
115
-
116
- builder = Rack::Builder.new do
117
- use ResubmittingMiddleware
118
- use Warden::Manager do |config|
119
- config.failure_app = ResubmittingMiddleware
120
- end
121
- run app
122
- end
123
-
124
- result = builder.to_app.call(env)
125
- result[0].should == 401
126
- result[2].body.should == ["Bad"]
127
- $throw_count.should == 2
128
- end
129
-
130
- it "should use the default scopes action when a bare throw is used" do
131
- env = env_with_params("/", :foo => "bar")
132
- action = nil
133
-
134
- failure = lambda do |env|
135
- action = env['PATH_INFO']
136
- [401, {}, ['fail']]
137
- end
138
-
139
- app = lambda do |env|
140
- throw(:warden)
141
- end
142
- result = setup_rack(app,
143
- :failure_app => failure,
144
- :configurator => lambda{ |c| c.scope_defaults(:default, :action => 'my_action', :strategies => [:password]) }
145
- ).call(env)
146
-
147
- action.should == "/my_action"
148
- result.first.should == 401
149
- end
150
- end # failure
151
- end
152
-
153
- describe "integrated strategies" do
154
- before(:each) do
155
- RAS = Warden::Strategies unless defined?(RAS)
156
- Warden::Strategies.clear!
157
- @app = setup_rack do |env|
158
- env['warden'].authenticate!(:foobar)
159
- [200, {"Content-Type" => "text/plain"}, ["Foo Is A Winna"]]
160
- end
161
- end
162
-
163
- describe "redirecting" do
164
-
165
- it "should redirect with a message" do
166
- RAS.add(:foobar) do
167
- def authenticate!
168
- redirect!("/foo/bar", {:foo => "bar"}, :message => "custom redirection message")
169
- end
170
- end
171
- result = @app.call(env_with_params)
172
- result[0].should == 302
173
- result[1]["Location"].should == "/foo/bar?foo=bar"
174
- result[2].should == ["custom redirection message"]
175
- end
176
-
177
- it "should redirect with a default message" do
178
- RAS.add(:foobar) do
179
- def authenticate!
180
- redirect!("/foo/bar", {:foo => "bar"})
181
- end
182
- end
183
- result = @app.call(env_with_params)
184
- result[0].should == 302
185
- result[1]['Location'].should == "/foo/bar?foo=bar"
186
- result[2].should == ["You are being redirected to /foo/bar?foo=bar"]
187
- end
188
-
189
- it "should redirect with a permanent redirect" do
190
- RAS.add(:foobar) do
191
- def authenticate!
192
- redirect!("/foo/bar", {}, :permanent => true)
193
- end
194
- end
195
- result = @app.call(env_with_params)
196
- result[0].should == 301
197
- end
198
-
199
- it "should redirect with a content type" do
200
- RAS.add(:foobar) do
201
- def authenticate!
202
- redirect!("/foo/bar", {:foo => "bar"}, :content_type => "text/xml")
203
- end
204
- end
205
- result = @app.call(env_with_params)
206
- result[0].should == 302
207
- result[1]["Location"].should == "/foo/bar?foo=bar"
208
- result[1]["Content-Type"].should == "text/xml"
209
- end
210
-
211
- it "should redirect with a default content type" do
212
- RAS.add(:foobar) do
213
- def authenticate!
214
- redirect!("/foo/bar", {:foo => "bar"})
215
- end
216
- end
217
- result = @app.call(env_with_params)
218
- result[0].should == 302
219
- result[1]["Location"].should == "/foo/bar?foo=bar"
220
- result[1]["Content-Type"].should == "text/plain"
221
- end
222
- end
223
-
224
- describe "failing" do
225
- it "should fail according to the failure app" do
226
- RAS.add(:foobar) do
227
- def authenticate!
228
- fail!
229
- end
230
- end
231
- env = env_with_params
232
- result = @app.call(env)
233
- result[0].should == 401
234
- result[2].should == ["You Fail!"]
235
- env['PATH_INFO'].should == "/unauthenticated"
236
- end
237
-
238
- it "should allow you to customize the response" do
239
- app = lambda do |e|
240
- e['warden'].custom_failure!
241
- [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
242
- end
243
- env = env_with_params
244
- result = setup_rack(app).call(env)
245
- result[0].should == 401
246
- result[2].should == ["Fail From The App"]
247
- end
248
-
249
- it "should allow you to customize the response without the explicit call to custom_failure! if not intercepting 401" do
250
- app = lambda do |e|
251
- [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
252
- end
253
- env = env_with_params
254
- result = setup_rack(app, :intercept_401 => false).call(env)
255
- result[0].should == 401
256
- result[2].should == ["Fail From The App"]
257
- end
258
-
259
- it "should render the failure application for a 401 if no custom_failure flag is set" do
260
- app = lambda do |e|
261
- [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
262
- end
263
- result = setup_rack(app).call(env_with_params)
264
- result[0].should == 401
265
- result[2].should == ["You Fail!"]
266
- end
267
-
268
- end # failing
269
-
270
- describe "custom rack response" do
271
- it "should return a custom rack response" do
272
- RAS.add(:foobar) do
273
- def authenticate!
274
- custom!([523, {"Content-Type" => "text/plain", "Custom-Header" => "foo"}, ["Custom Stuff"]])
275
- end
276
- end
277
- result = @app.call(env_with_params)
278
- result[0].should == 523
279
- result[1]["Custom-Header"].should == "foo"
280
- result[2].should == ["Custom Stuff"]
281
- end
282
- end
283
-
284
- describe "success" do
285
- it "should pass through to the application when there is success" do
286
- RAS.add(:foobar) do
287
- def authenticate!
288
- success!("A User")
289
- end
290
- end
291
- env = env_with_params
292
- result = @app.call(env)
293
- result[0].should == 200
294
- result[2].should == ["Foo Is A Winna"]
295
- end
296
- end
297
- end # integrated strategies
298
-
299
- it "should allow me to set a different default scope for warden" do
300
- Rack::Builder.new do
301
- use Warden::Manager, :default_scope => :default do |manager|
302
- manager.default_scope.should == :default
303
- manager.default_scope = :other
304
- manager.default_scope.should == :other
305
- end
306
- end
307
- end
308
-
309
- it "should allow me to access strategies through manager" do
310
- Rack::Builder.new do
311
- use Warden::Manager do |manager|
312
- manager.strategies.should == Warden::Strategies
313
- end
314
- end
315
- end
316
- end