warden 1.2.5 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
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,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
- expect(RAM._after_set_user.length).to eq(1)
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
- expect(RAM._after_set_user.length).to eq(2)
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
- expect(env['warden'].user).to be_nil
44
- expect(env['warden.spec.hook.foo']).to eq("run foo")
45
- expect(env['warden.spec.hook.bar']).to eq("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
- expect(env['warden.spec.order']).to eq([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| expect(o[:event]).to eq(: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
- expect(env['warden.spec.hook.baz']).to eq('run baz')
94
- expect(env['warden.spec.hook.paz']).to eq('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
- expect(env['warden.spec.order']).to eq([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
- expect(env['warden']).not_to be_authenticated
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| expect(o[:event]).to eq(: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
- expect(env['warden'].user).to eq("Foo")
143
- expect(env['warden.spec.hook.baz']).to eq('run baz')
144
- expect(env['warden.spec.hook.paz']).to eq('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
- expect(env['warden'].user).to 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
- expect(env['warden.spec.order']).to eq([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
- expect(env['warden'].user).to eq("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
- expect(env['warden'].user).to be_nil
207
- expect(calls).to eq(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
- expect(RAM._before_failure.length).to eq(1)
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
- expect(RAM._before_failure.length).to eq(2)
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
- expect(env['warden.spec.before_failure.foo']).to eq("foo")
239
- expect(env['warden.spec.before_failure.bar']).to eq("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
- expect(env['warden.spec.order']).to eq([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
- expect(RAM._before_logout.length).to eq(1)
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
- expect(RAM._before_logout.length).to eq(2)
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
- expect(env['warden.spec.hook.lorem']).to eq('run lorem')
286
- expect(env['warden.spec.hook.ipsum']).to eq('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
- expect(env['warden.spec.hook.a']).to eq([:scope1])
305
- expect(env['warden.spec.hook.b']).to eq([])
306
-
307
- env['warden'].logout(:scope2)
308
- expect(env['warden.spec.hook.a']).to eq([:scope1])
309
- expect(env['warden.spec.hook.b']).to eq([: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
- expect(env['warden.spec.order']).to eq([1,2,3])
325
- end
326
- end
327
-
328
- describe "on_request" do
329
- before(:each) do
330
- RAM = Warden::Manager unless defined?(RAM)
331
- @old_on_request = RAM._on_request.dup
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
- expect(RAM._on_request.length).to eq(1)
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
- expect(RAM._on_request.length).to eq(2)
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
- expect(env['warden.spec.on_request.foo']).to eq("foo")
358
- expect(env['warden.spec.on_request.bar']).to eq("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
- expect(env['warden.spec.order']).to eq([1,2,3])
371
- end
372
- end
373
- end