warden 1.2.7 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitignore +6 -0
  4. data/.rspec +3 -0
  5. data/{History.rdoc → CHANGELOG.md} +74 -39
  6. data/Gemfile +2 -2
  7. data/LICENSE +2 -1
  8. data/README.md +18 -0
  9. data/Rakefile +3 -8
  10. data/lib/warden/config.rb +1 -1
  11. data/lib/warden/errors.rb +2 -2
  12. data/lib/warden/hooks.rb +1 -1
  13. data/lib/warden/manager.rb +2 -2
  14. data/lib/warden/mixins/common.rb +1 -1
  15. data/lib/warden/proxy.rb +24 -5
  16. data/lib/warden/session_serializer.rb +1 -1
  17. data/lib/warden/strategies/base.rb +2 -1
  18. data/lib/warden/test/helpers.rb +2 -2
  19. data/lib/warden/test/mock.rb +5 -5
  20. data/lib/warden/test/warden_helpers.rb +1 -1
  21. data/lib/warden/version.rb +2 -2
  22. data/lib/warden.rb +1 -1
  23. data/warden.gemspec +18 -18
  24. metadata +18 -36
  25. data/README.textile +0 -9
  26. data/spec/helpers/request_helper.rb +0 -52
  27. data/spec/helpers/strategies/fail_with_user.rb +0 -11
  28. data/spec/helpers/strategies/failz.rb +0 -9
  29. data/spec/helpers/strategies/invalid.rb +0 -9
  30. data/spec/helpers/strategies/pass.rb +0 -9
  31. data/spec/helpers/strategies/pass_with_message.rb +0 -9
  32. data/spec/helpers/strategies/password.rb +0 -14
  33. data/spec/helpers/strategies/single.rb +0 -13
  34. data/spec/spec_helper.rb +0 -26
  35. data/spec/warden/authenticated_data_store_spec.rb +0 -115
  36. data/spec/warden/config_spec.rb +0 -49
  37. data/spec/warden/errors_spec.rb +0 -48
  38. data/spec/warden/hooks_spec.rb +0 -374
  39. data/spec/warden/manager_spec.rb +0 -341
  40. data/spec/warden/proxy_spec.rb +0 -1051
  41. data/spec/warden/scoped_session_serializer.rb +0 -124
  42. data/spec/warden/session_serializer_spec.rb +0 -54
  43. data/spec/warden/strategies/base_spec.rb +0 -314
  44. data/spec/warden/strategies_spec.rb +0 -95
  45. data/spec/warden/test/helpers_spec.rb +0 -94
  46. data/spec/warden/test/mock_spec.rb +0 -16
  47. data/spec/warden/test/test_mode_spec.rb +0 -76
@@ -1,374 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require 'spec_helper'
4
-
5
- describe "standard authentication hooks" do
6
-
7
- before(:all) do
8
- load_strategies
9
- end
10
-
11
- describe "after_set_user" do
12
- before(:each) do
13
- RAM = Warden::Manager unless defined?(RAM)
14
- RAM._after_set_user.clear
15
- end
16
-
17
- after(:each) do
18
- RAM._after_set_user.clear
19
- end
20
-
21
- it "should allow me to add an after_set_user hook" do
22
- RAM.after_set_user do |user, auth, opts|
23
- "boo"
24
- end
25
- expect(RAM._after_set_user.length).to eq(1)
26
- end
27
-
28
- it "should allow me to add multiple after_set_user hooks" do
29
- RAM.after_set_user{|user, auth, opts| "foo"}
30
- RAM.after_set_user{|u,a| "bar"}
31
- expect(RAM._after_set_user.length).to eq(2)
32
- end
33
-
34
- it "should run each after_set_user hook after the user is set" do
35
- RAM.after_set_user{|u,a,o| a.env['warden.spec.hook.foo'] = "run foo"}
36
- RAM.after_set_user{|u,a,o| a.env['warden.spec.hook.bar'] = "run bar"}
37
- RAM.after_set_user{|u,a,o| a.logout}
38
- app = lambda do |e|
39
- e['warden'].set_user("foo")
40
- valid_response
41
- end
42
- env = env_with_params
43
- setup_rack(app).call(env)
44
- expect(env['warden'].user).to be_nil
45
- expect(env['warden.spec.hook.foo']).to eq("run foo")
46
- expect(env['warden.spec.hook.bar']).to eq("run bar")
47
- end
48
-
49
- it "should not run the event specified with except" do
50
- RAM.after_set_user(:except => :set_user){|u,a,o| fail}
51
- app = lambda do |e|
52
- e['warden'].set_user("foo")
53
- valid_response
54
- end
55
- env = env_with_params
56
- setup_rack(app).call(env)
57
- end
58
-
59
- it "should only run the event specified with only" do
60
- RAM.after_set_user(:only => :set_user){|u,a,o| fail}
61
- app = lambda do |e|
62
- e['warden'].authenticate(:pass)
63
- valid_response
64
- end
65
- env = env_with_params
66
- setup_rack(app).call(env)
67
- end
68
-
69
- it "should run filters in the given order" do
70
- RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 2}
71
- RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 3}
72
- RAM.prepend_after_set_user{|u,a,o| a.env['warden.spec.order'] << 1}
73
- app = lambda do |e|
74
- e['warden.spec.order'] = []
75
- e['warden'].set_user("foo")
76
- valid_response
77
- end
78
- env = env_with_params
79
- setup_rack(app).call(env)
80
- expect(env['warden.spec.order']).to eq([1,2,3])
81
- end
82
-
83
- context "after_authentication" do
84
- it "should be a wrapper to after_set_user behavior" do
85
- RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
86
- RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
87
- RAM.after_authentication{|u,a,o| expect(o[:event]).to eq(:authentication) }
88
- app = lambda do |e|
89
- e['warden'].authenticate(:pass)
90
- valid_response
91
- end
92
- env = env_with_params
93
- setup_rack(app).call(env)
94
- expect(env['warden.spec.hook.baz']).to eq('run baz')
95
- expect(env['warden.spec.hook.paz']).to eq('run paz')
96
- end
97
-
98
- it "should not be invoked on default after_set_user scenario" do
99
- RAM.after_authentication{|u,a,o| fail}
100
- app = lambda do |e|
101
- e['warden'].set_user("foo")
102
- valid_response
103
- end
104
- env = env_with_params
105
- setup_rack(app).call(env)
106
- end
107
-
108
- it "should run filters in the given order" do
109
- RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 2}
110
- RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 3}
111
- RAM.prepend_after_authentication{|u,a,o| a.env['warden.spec.order'] << 1}
112
- app = lambda do |e|
113
- e['warden.spec.order'] = []
114
- e['warden'].authenticate(:pass)
115
- valid_response
116
- end
117
- env = env_with_params
118
- setup_rack(app).call(env)
119
- expect(env['warden.spec.order']).to eq([1,2,3])
120
- end
121
-
122
- it "should allow me to log out a user in an after_set_user block" do
123
- RAM.after_set_user{|u,a,o| a.logout}
124
-
125
- app = lambda do |e|
126
- e['warden'].authenticate(:pass)
127
- valid_response
128
- end
129
- env = env_with_params
130
- setup_rack(app).call(env)
131
- expect(env['warden']).not_to be_authenticated
132
- end
133
- end
134
-
135
- context "after_fetch" do
136
- it "should be a wrapper to after_set_user behavior" do
137
- RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
138
- RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
139
- RAM.after_fetch{|u,a,o| expect(o[:event]).to eq(:fetch) }
140
- env = env_with_params
141
- setup_rack(lambda { |e| valid_response }).call(env)
142
- env['rack.session']['warden.user.default.key'] = "Foo"
143
- expect(env['warden'].user).to eq("Foo")
144
- expect(env['warden.spec.hook.baz']).to eq('run baz')
145
- expect(env['warden.spec.hook.paz']).to eq('run paz')
146
- end
147
-
148
- it "should not be invoked on default after_set_user scenario" do
149
- RAM.after_fetch{|u,a,o| fail}
150
- app = lambda do |e|
151
- e['warden'].set_user("foo")
152
- valid_response
153
- end
154
- env = env_with_params
155
- setup_rack(app).call(env)
156
- end
157
-
158
- it "should not be invoked if fetched user is nil" do
159
- RAM.after_fetch{|u,a,o| fail}
160
- env = env_with_params
161
- setup_rack(lambda { |e| valid_response }).call(env)
162
- env['rack.session']['warden.user.default.key'] = nil
163
- expect(env['warden'].user).to be_nil
164
- end
165
-
166
- it "should run filters in the given order" do
167
- RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 2}
168
- RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 3}
169
- RAM.prepend_after_fetch{|u,a,o| a.env['warden.spec.order'] << 1}
170
- app = lambda do |e|
171
- e['warden.spec.order'] = []
172
- e['rack.session']['warden.user.default.key'] = "Foo"
173
- e['warden'].user
174
- valid_response
175
- end
176
- env = env_with_params
177
- setup_rack(app).call(env)
178
- expect(env['warden.spec.order']).to eq([1,2,3])
179
- end
180
- end
181
- end
182
-
183
-
184
- describe "after_failed_fetch" do
185
- before(:each) do
186
- RAM = Warden::Manager unless defined?(RAM)
187
- RAM._after_failed_fetch.clear
188
- end
189
-
190
- after(:each) do
191
- RAM._after_failed_fetch.clear
192
- end
193
-
194
- it "should not be called when user is fetched" do
195
- RAM.after_failed_fetch{|u,a,o| fail }
196
- env = env_with_params
197
- setup_rack(lambda { |e| valid_response }).call(env)
198
- env['rack.session']['warden.user.default.key'] = "Foo"
199
- expect(env['warden'].user).to eq("Foo")
200
- end
201
-
202
- it "should be called if fetched user is nil" do
203
- calls = 0
204
- RAM.after_failed_fetch{|u,a,o| calls += 1 }
205
- env = env_with_params
206
- setup_rack(lambda { |e| valid_response }).call(env)
207
- expect(env['warden'].user).to be_nil
208
- expect(calls).to eq(1)
209
- end
210
- end
211
-
212
- describe "before_failure" do
213
- before(:each) do
214
- RAM = Warden::Manager unless defined?(RAM)
215
- RAM._before_failure.clear
216
- end
217
-
218
- after(:each) do
219
- RAM._before_failure.clear
220
- end
221
-
222
- it "should allow me to add a before_failure hook" do
223
- RAM.before_failure{|env, opts| "foo"}
224
- expect(RAM._before_failure.length).to eq(1)
225
- end
226
-
227
- it "should allow me to add multiple before_failure hooks" do
228
- RAM.before_failure{|env, opts| "foo"}
229
- RAM.before_failure{|env, opts| "bar"}
230
- expect(RAM._before_failure.length).to eq(2)
231
- end
232
-
233
- it "should run each before_failure hooks before failing" do
234
- RAM.before_failure{|e,o| e['warden.spec.before_failure.foo'] = "foo"}
235
- RAM.before_failure{|e,o| e['warden.spec.before_failure.bar'] = "bar"}
236
- app = lambda{|e| e['warden'].authenticate!(:failz); valid_response}
237
- env = env_with_params
238
- setup_rack(app).call(env)
239
- expect(env['warden.spec.before_failure.foo']).to eq("foo")
240
- expect(env['warden.spec.before_failure.bar']).to eq("bar")
241
- end
242
-
243
- it "should run filters in the given order" do
244
- RAM.before_failure{|e,o| e['warden.spec.order'] << 2}
245
- RAM.before_failure{|e,o| e['warden.spec.order'] << 3}
246
- RAM.prepend_before_failure{|e,o| e['warden.spec.order'] << 1}
247
- app = lambda do |e|
248
- e['warden.spec.order'] = []
249
- e['warden'].authenticate!(:failz)
250
- valid_response
251
- end
252
- env = env_with_params
253
- setup_rack(app).call(env)
254
- expect(env['warden.spec.order']).to eq([1,2,3])
255
- end
256
- end
257
-
258
- describe "before_logout" do
259
- before(:each) do
260
- RAM = Warden::Manager unless defined?(RAM)
261
- RAM._before_logout.clear
262
- end
263
-
264
- after(:each) do
265
- RAM._before_logout.clear
266
- end
267
-
268
- it "should allow me to add an before_logout hook" do
269
- RAM.before_logout{|user, auth, scopes| "foo"}
270
- expect(RAM._before_logout.length).to eq(1)
271
- end
272
-
273
- it "should allow me to add multiple after_authentication hooks" do
274
- RAM.before_logout{|u,a,o| "bar"}
275
- RAM.before_logout{|u,a,o| "baz"}
276
- expect(RAM._before_logout.length).to eq(2)
277
- end
278
-
279
- it "should run each before_logout hook before logout is run" do
280
- RAM.before_logout{|u,a,o| a.env['warden.spec.hook.lorem'] = "run lorem"}
281
- RAM.before_logout{|u,a,o| a.env['warden.spec.hook.ipsum'] = "run ipsum"}
282
- app = lambda{|e| e['warden'].authenticate(:pass); valid_response}
283
- env = env_with_params
284
- setup_rack(app).call(env)
285
- env['warden'].logout
286
- expect(env['warden.spec.hook.lorem']).to eq('run lorem')
287
- expect(env['warden.spec.hook.ipsum']).to eq('run ipsum')
288
- end
289
-
290
- it "should run before_logout hook for a specified scope" do
291
- RAM.before_logout(:scope => :scope1){|u,a,o| a.env["warden.spec.hook.a"] << :scope1 }
292
- RAM.before_logout(:scope => [:scope2]){|u,a,o| a.env["warden.spec.hook.b"] << :scope2 }
293
-
294
- app = lambda do |e|
295
- e['warden'].authenticate(:pass, :scope => :scope1)
296
- e['warden'].authenticate(:pass, :scope => :scope2)
297
- valid_response
298
- end
299
- env = env_with_params
300
- env["warden.spec.hook.a"] ||= []
301
- env["warden.spec.hook.b"] ||= []
302
- setup_rack(app).call(env)
303
-
304
- env['warden'].logout(:scope1)
305
- expect(env['warden.spec.hook.a']).to eq([:scope1])
306
- expect(env['warden.spec.hook.b']).to eq([])
307
-
308
- env['warden'].logout(:scope2)
309
- expect(env['warden.spec.hook.a']).to eq([:scope1])
310
- expect(env['warden.spec.hook.b']).to eq([:scope2])
311
- end
312
-
313
- it "should run filters in the given order" do
314
- RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 2}
315
- RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 3}
316
- RAM.prepend_before_logout{|u,a,o| a.env['warden.spec.order'] << 1}
317
- app = lambda do |e|
318
- e['warden.spec.order'] = []
319
- e['warden'].authenticate(:pass)
320
- e['warden'].logout
321
- valid_response
322
- end
323
- env = env_with_params
324
- setup_rack(app).call(env)
325
- expect(env['warden.spec.order']).to eq([1,2,3])
326
- end
327
- end
328
-
329
- describe "on_request" do
330
- before(:each) do
331
- RAM = Warden::Manager unless defined?(RAM)
332
- @old_on_request = RAM._on_request.dup
333
- RAM._on_request.clear
334
- end
335
-
336
- after(:each) do
337
- RAM._on_request.clear
338
- RAM._on_request.replace(@old_on_request)
339
- end
340
-
341
- it "should allow me to add an on_request hook" do
342
- RAM.on_request{|proxy| "foo"}
343
- expect(RAM._on_request.length).to eq(1)
344
- end
345
-
346
- it "should allow me to add multiple on_request hooks" do
347
- RAM.on_request{|proxy| "foo"}
348
- RAM.on_request{|proxy| "bar"}
349
- expect(RAM._on_request.length).to eq(2)
350
- end
351
-
352
- it "should run each on_request hooks when initializing" do
353
- RAM.on_request{|proxy| proxy.env['warden.spec.on_request.foo'] = "foo"}
354
- RAM.on_request{|proxy| proxy.env['warden.spec.on_request.bar'] = "bar"}
355
- app = lambda{|e| valid_response}
356
- env = env_with_params
357
- setup_rack(app).call(env)
358
- expect(env['warden.spec.on_request.foo']).to eq("foo")
359
- expect(env['warden.spec.on_request.bar']).to eq("bar")
360
- end
361
-
362
- it "should run filters in the given order" do
363
- RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 2}
364
- RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 3}
365
- RAM.prepend_on_request{|proxy| proxy.env['warden.spec.order'] << 1}
366
- app = lambda do |e|
367
- valid_response
368
- end
369
- env = Rack::MockRequest.env_for("/", "warden.spec.order" => [])
370
- setup_rack(app).call(env)
371
- expect(env['warden.spec.order']).to eq([1,2,3])
372
- end
373
- end
374
- end