warden 1.2.5 → 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 (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/{History.rdoc → CHANGELOG.md} +13 -3
  6. data/Gemfile +2 -1
  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 +1 -0
  12. data/lib/warden/errors.rb +2 -1
  13. data/lib/warden/hooks.rb +1 -0
  14. data/lib/warden/manager.rb +2 -1
  15. data/lib/warden/mixins/common.rb +1 -0
  16. data/lib/warden/proxy.rb +15 -3
  17. data/lib/warden/session_serializer.rb +1 -0
  18. data/lib/warden/strategies/base.rb +2 -1
  19. data/lib/warden/strategies.rb +1 -0
  20. data/lib/warden/test/helpers.rb +2 -56
  21. data/lib/warden/test/mock.rb +69 -0
  22. data/lib/warden/test/warden_helpers.rb +1 -0
  23. data/lib/warden/version.rb +2 -1
  24. data/lib/warden.rb +2 -0
  25. data/warden.gemspec +21 -18
  26. metadata +19 -33
  27. data/README.textile +0 -9
  28. data/spec/helpers/request_helper.rb +0 -51
  29. data/spec/helpers/strategies/fail_with_user.rb +0 -10
  30. data/spec/helpers/strategies/failz.rb +0 -8
  31. data/spec/helpers/strategies/invalid.rb +0 -8
  32. data/spec/helpers/strategies/pass.rb +0 -8
  33. data/spec/helpers/strategies/pass_with_message.rb +0 -8
  34. data/spec/helpers/strategies/password.rb +0 -13
  35. data/spec/helpers/strategies/single.rb +0 -12
  36. data/spec/spec_helper.rb +0 -24
  37. data/spec/warden/authenticated_data_store_spec.rb +0 -114
  38. data/spec/warden/config_spec.rb +0 -48
  39. data/spec/warden/errors_spec.rb +0 -47
  40. data/spec/warden/hooks_spec.rb +0 -373
  41. data/spec/warden/manager_spec.rb +0 -340
  42. data/spec/warden/proxy_spec.rb +0 -1050
  43. data/spec/warden/scoped_session_serializer.rb +0 -123
  44. data/spec/warden/session_serializer_spec.rb +0 -53
  45. data/spec/warden/strategies/base_spec.rb +0 -313
  46. data/spec/warden/strategies_spec.rb +0 -94
  47. data/spec/warden/test/helpers_spec.rb +0 -101
  48. data/spec/warden/test/test_mode_spec.rb +0 -75
@@ -1,340 +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
- expect(env["warden"]).to 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) # TODO: What is @fail_app?
38
- expect(result.first).to eq(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) # TODO: What is @fail_app?
48
- expect(result.last).to eq(["You Fail!"])
49
- end
50
-
51
- it "should set the message from the winning strategy in warden.options hash" do
52
- env = env_with_params("/", {})
53
- app = lambda do |_env|
54
- _env['warden'].authenticate(:failz)
55
- throw(:warden)
56
- end
57
- setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app?
58
- expect(env["warden.options"][:message]).to eq("The Fails Strategy Has Failed You")
59
- end
60
-
61
- it "should render the failure app when there's a failure" do
62
- app = lambda do |e|
63
- throw(:warden, :action => :unauthenticated) unless e['warden'].authenticated?(:failz)
64
- end
65
- fail_app = lambda do |e|
66
- [401, {"Content-Type" => "text/plain"}, ["Failure App"]]
67
- end
68
- result = setup_rack(app, :failure_app => fail_app).call(env_with_params)
69
- expect(result.last).to eq(["Failure App"])
70
- end
71
-
72
- it "should call failure app if warden is thrown even after successful authentication" do
73
- env = env_with_params("/", {})
74
- app = lambda do |_env|
75
- _env['warden'].authenticate(:pass)
76
- throw(:warden)
77
- end
78
- result = setup_rack(app, :failure_app => @fail_app).call(env)
79
- expect(result.first).to eq(401)
80
- expect(result.last).to eq(["You Fail!"])
81
- end
82
-
83
- it "should set the attempted url in warden.options hash" do
84
- env = env_with_params("/access/path", {})
85
- app = lambda do |_env|
86
- _env['warden'].authenticate(:pass)
87
- throw(:warden)
88
- end
89
- result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app?
90
- expect(result.first).to eq(401)
91
- expect(env["warden.options"][:attempted_path]).to eq("/access/path")
92
- end
93
-
94
- it "should catch a resubmitted request" do
95
- # this is a bit convoluted. but it's occurred in the field with Rack::OpenID
96
- $count = 0
97
- $throw_count = 0
98
- env = env_with_params("/foo")
99
- class ::ResubmittingMiddleware
100
- @@app = nil
101
- def initialize(app)
102
- @@app = app
103
- end
104
-
105
- def self.call(env)
106
- if $count > 1
107
- Rack::Response.new("Bad", 401)
108
- else
109
- $count += 1
110
- @@app.call(env)
111
- end
112
- end
113
-
114
- def call(env)
115
- $count += 1
116
- @@app.call(env)
117
- end
118
-
119
- end
120
-
121
- app = lambda do |e|
122
- $throw_count += 1
123
- throw(:warden)
124
- end
125
-
126
- builder = Rack::Builder.new do
127
- use ResubmittingMiddleware
128
- use Warden::Manager do |config|
129
- config.failure_app = ResubmittingMiddleware
130
- end
131
- run app
132
- end
133
-
134
- result = builder.to_app.call(env)
135
- expect(result[0]).to eq(401)
136
- expect(result[2].body).to eq(["Bad"])
137
- expect($throw_count).to eq(2)
138
- end
139
-
140
- it "should use the default scopes action when a bare throw is used" do
141
- env = env_with_params("/", :foo => "bar")
142
- action = nil
143
-
144
- failure = lambda do |_env|
145
- action = _env['PATH_INFO']
146
- [401, {}, ['fail']]
147
- end
148
-
149
- app = lambda do |_env|
150
- throw(:warden)
151
- end
152
- result = setup_rack(app,
153
- :failure_app => failure,
154
- :configurator => lambda{ |c| c.scope_defaults(:default, :action => 'my_action', :strategies => [:password]) }
155
- ).call(env)
156
-
157
- expect(action).to eq("/my_action")
158
- expect(result.first).to eq(401)
159
- end
160
- end # failure
161
- end
162
-
163
- describe "integrated strategies" do
164
- before(:each) do
165
- RAS = Warden::Strategies unless defined?(RAS)
166
- Warden::Strategies.clear!
167
- @app = setup_rack do |env|
168
- env['warden'].authenticate!(:foobar)
169
- [200, {"Content-Type" => "text/plain"}, ["Foo Is A Winna"]]
170
- end
171
- end
172
-
173
- describe "redirecting" do
174
-
175
- it "should redirect with a message" do
176
- RAS.add(:foobar) do
177
- def authenticate!
178
- redirect!("/foo/bar", {:foo => "bar"}, :message => "custom redirection message")
179
- end
180
- end
181
- result = @app.call(env_with_params)
182
- expect(result[0]).to be(302)
183
- expect(result[1]["Location"]).to eq("/foo/bar?foo=bar")
184
- expect(result[2]).to eq(["custom redirection message"])
185
- end
186
-
187
- it "should redirect with a default message" do
188
- RAS.add(:foobar) do
189
- def authenticate!
190
- redirect!("/foo/bar", {:foo => "bar"})
191
- end
192
- end
193
- result = @app.call(env_with_params)
194
- expect(result[0]).to eq(302)
195
- expect(result[1]['Location']).to eq("/foo/bar?foo=bar")
196
- expect(result[2]).to eq(["You are being redirected to /foo/bar?foo=bar"])
197
- end
198
-
199
- it "should redirect with a permanent redirect" do
200
- RAS.add(:foobar) do
201
- def authenticate!
202
- redirect!("/foo/bar", {}, :permanent => true)
203
- end
204
- end
205
- result = @app.call(env_with_params)
206
- expect(result[0]).to eq(301)
207
- end
208
-
209
- it "should redirect with a content type" do
210
- RAS.add(:foobar) do
211
- def authenticate!
212
- redirect!("/foo/bar", {:foo => "bar"}, :content_type => "text/xml")
213
- end
214
- end
215
- result = @app.call(env_with_params)
216
- expect(result[0]).to eq(302)
217
- expect(result[1]["Location"]).to eq("/foo/bar?foo=bar")
218
- expect(result[1]["Content-Type"]).to eq("text/xml")
219
- end
220
-
221
- it "should redirect with a default content type" do
222
- RAS.add(:foobar) do
223
- def authenticate!
224
- redirect!("/foo/bar", {:foo => "bar"})
225
- end
226
- end
227
- result = @app.call(env_with_params)
228
- expect(result[0]).to eq(302)
229
- expect(result[1]["Location"]).to eq("/foo/bar?foo=bar")
230
- expect(result[1]["Content-Type"]).to eq("text/plain")
231
- end
232
- end
233
-
234
- describe "failing" do
235
- it "should fail according to the failure app" do
236
- RAS.add(:foobar) do
237
- def authenticate!
238
- fail!
239
- end
240
- end
241
- env = env_with_params
242
- result = @app.call(env)
243
- expect(result[0]).to eq(401)
244
- expect(result[2]).to eq(["You Fail!"])
245
- expect(env['PATH_INFO']).to eq("/unauthenticated")
246
- end
247
-
248
- it "should allow you to customize the response" do
249
- app = lambda do |e|
250
- e['warden'].custom_failure!
251
- [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
252
- end
253
- env = env_with_params
254
- result = setup_rack(app).call(env)
255
- expect(result[0]).to eq(401)
256
- expect(result[2]).to eq(["Fail From The App"])
257
- end
258
-
259
- it "should allow you to customize the response without the explicit call to custom_failure! if not intercepting 401" do
260
- app = lambda do |e|
261
- [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
262
- end
263
- env = env_with_params
264
- result = setup_rack(app, :intercept_401 => false).call(env)
265
- expect(result[0]).to eq(401)
266
- expect(result[2]).to eq(["Fail From The App"])
267
- end
268
-
269
- it "should render the failure application for a 401 if no custom_failure flag is set" do
270
- app = lambda do |e|
271
- [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
272
- end
273
- result = setup_rack(app).call(env_with_params)
274
- expect(result[0]).to eq(401)
275
- expect(result[2]).to eq(["You Fail!"])
276
- end
277
-
278
- end # failing
279
-
280
- describe "custom rack response" do
281
- it "should return a custom rack response" do
282
- RAS.add(:foobar) do
283
- def authenticate!
284
- custom!([523, {"Content-Type" => "text/plain", "Custom-Header" => "foo"}, ["Custom Stuff"]])
285
- end
286
- end
287
- result = @app.call(env_with_params)
288
- expect(result[0]).to be(523)
289
- expect(result[1]["Custom-Header"]).to eq("foo")
290
- expect(result[2]).to eq(["Custom Stuff"])
291
- end
292
- end
293
-
294
- describe "app returns Rack::Response" do
295
- it "should return it" do
296
- RAS.add(:foobar) do
297
- def authenticate!
298
- custom!(Rack::Response.new(['body'], 201, {"Content-Type" => "text/plain"}))
299
- end
300
- end
301
- result = @app.call(env_with_params)
302
- expect(result.status).to eq(201)
303
- expect(result.body).to eq(['body'])
304
- expect(result.header['Content-Type']).to eq('text/plain')
305
- end
306
- end
307
-
308
- describe "success" do
309
- it "should pass through to the application when there is success" do
310
- RAS.add(:foobar) do
311
- def authenticate!
312
- success!("A User")
313
- end
314
- end
315
- env = env_with_params
316
- result = @app.call(env)
317
- expect(result[0]).to eq(200)
318
- expect(result[2]).to eq(["Foo Is A Winna"])
319
- end
320
- end
321
- end # integrated strategies
322
-
323
- it "should allow me to set a different default scope for warden" do
324
- Rack::Builder.new do
325
- use Warden::Manager, :default_scope => :default do |manager|
326
- expect(manager.default_scope).to eq(:default)
327
- manager.default_scope = :other
328
- expect(manager.default_scope).to eq(:other)
329
- end
330
- end
331
- end
332
-
333
- it "should allow me to access strategies through manager" do
334
- Rack::Builder.new do
335
- use Warden::Manager do |manager|
336
- expect(manager.strategies).to eq(Warden::Strategies)
337
- end
338
- end
339
- end
340
- end