warden 1.2.3 → 1.2.4
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.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/lib/warden/config.rb +2 -3
- data/lib/warden/hooks.rb +9 -9
- data/lib/warden/manager.rb +21 -9
- data/lib/warden/mixins/common.rb +1 -1
- data/lib/warden/proxy.rb +12 -8
- data/lib/warden/strategies/base.rb +12 -7
- data/lib/warden/test/helpers.rb +1 -1
- data/lib/warden/test/warden_helpers.rb +1 -1
- data/lib/warden/version.rb +1 -1
- data/spec/helpers/strategies/fail_with_user.rb +10 -0
- data/spec/helpers/strategies/invalid.rb +1 -1
- data/spec/warden/authenticated_data_store_spec.rb +20 -20
- data/spec/warden/config_spec.rb +10 -10
- data/spec/warden/errors_spec.rb +7 -7
- data/spec/warden/hooks_spec.rb +40 -40
- data/spec/warden/manager_spec.rb +81 -57
- data/spec/warden/proxy_spec.rb +177 -168
- data/spec/warden/scoped_session_serializer.rb +9 -9
- data/spec/warden/session_serializer_spec.rb +13 -13
- data/spec/warden/strategies/base_spec.rb +37 -37
- data/spec/warden/strategies_spec.rb +14 -13
- data/spec/warden/test/helpers_spec.rb +23 -23
- data/spec/warden/test/test_mode_spec.rb +12 -13
- metadata +19 -23
data/spec/warden/proxy_spec.rb
CHANGED
@@ -23,45 +23,45 @@ describe Warden::Proxy do
|
|
23
23
|
|
24
24
|
it "should not check the authentication if it is not checked" do
|
25
25
|
app = setup_rack(@basic_app)
|
26
|
-
app.call(@env).first.
|
26
|
+
expect(app.call(@env).first).to eq(200)
|
27
27
|
end
|
28
28
|
|
29
|
-
it "should check the authentication if it is
|
29
|
+
it "should check the authentication if it is explicitly checked" do
|
30
30
|
app = setup_rack(@authd_app)
|
31
|
-
app.call(@env).first.
|
31
|
+
expect(app.call(@env).first).to eq(401)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should not allow the request if incorrect conditions are supplied" do
|
35
35
|
env = env_with_params("/", :foo => "bar")
|
36
36
|
app = setup_rack(@authd_app)
|
37
37
|
response = app.call(env)
|
38
|
-
response.first.
|
38
|
+
expect(response.first).to eq(401)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should allow the request if the correct conditions are supplied" do
|
42
42
|
env = env_with_params("/", :username => "fred", :password => "sekrit")
|
43
43
|
app = setup_rack(@authd_app)
|
44
44
|
resp = app.call(env)
|
45
|
-
resp.first.
|
45
|
+
expect(resp.first).to eq(200)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should allow authentication in my application" do
|
49
49
|
env = env_with_params('/', :username => "fred", :password => "sekrit")
|
50
|
-
app = lambda do |
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
app = lambda do |_env|
|
51
|
+
_env['warden'].authenticate
|
52
|
+
expect(_env['warden']).to be_authenticated
|
53
|
+
expect(_env['warden.spec.strategies']).to eq([:password])
|
54
54
|
valid_response
|
55
55
|
end
|
56
56
|
setup_rack(app).call(env)
|
57
57
|
end
|
58
58
|
|
59
|
-
it "should allow me to select which strategies I use in my
|
59
|
+
it "should allow me to select which strategies I use in my application" do
|
60
60
|
env = env_with_params("/", :foo => "bar")
|
61
|
-
app = lambda do |
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
app = lambda do |_env|
|
62
|
+
_env['warden'].authenticate(:failz)
|
63
|
+
expect(_env['warden']).not_to be_authenticated
|
64
|
+
expect(_env['warden.spec.strategies']).to eq([:failz])
|
65
65
|
valid_response
|
66
66
|
end
|
67
67
|
setup_rack(app).call(env)
|
@@ -71,9 +71,18 @@ describe Warden::Proxy do
|
|
71
71
|
app = lambda do |env|
|
72
72
|
env['warden'].authenticate(:unknown)
|
73
73
|
end
|
74
|
-
|
74
|
+
expect {
|
75
75
|
setup_rack(app).call(@env)
|
76
|
-
}.
|
76
|
+
}.to raise_error(RuntimeError, "Invalid strategy unknown")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise error if the strategy failed" do
|
80
|
+
app = lambda do |env|
|
81
|
+
env['warden'].authenticate(:fail_with_user)
|
82
|
+
expect(env['warden'].user).to be_nil
|
83
|
+
valid_response
|
84
|
+
end
|
85
|
+
setup_rack(app).call(@env)
|
77
86
|
end
|
78
87
|
|
79
88
|
it "should not raise error on missing strategies if silencing" do
|
@@ -81,16 +90,16 @@ describe Warden::Proxy do
|
|
81
90
|
env['warden'].authenticate
|
82
91
|
valid_response
|
83
92
|
end
|
84
|
-
|
93
|
+
expect {
|
85
94
|
setup_rack(app, :silence_missing_strategies => true, :default_strategies => [:unknown]).call(@env)
|
86
|
-
}.
|
95
|
+
}.not_to raise_error
|
87
96
|
end
|
88
97
|
|
89
98
|
it "should allow me to get access to the user at warden.user." do
|
90
99
|
app = lambda do |env|
|
91
100
|
env['warden'].authenticate(:pass)
|
92
|
-
env['warden'].
|
93
|
-
env['warden.spec.strategies'].
|
101
|
+
expect(env['warden']).to be_authenticated
|
102
|
+
expect(env['warden.spec.strategies']).to eq([:pass])
|
94
103
|
valid_response
|
95
104
|
end
|
96
105
|
setup_rack(app).call(@env)
|
@@ -98,10 +107,10 @@ describe Warden::Proxy do
|
|
98
107
|
|
99
108
|
it "should run strategies when authenticate? is asked" do
|
100
109
|
app = lambda do |env|
|
101
|
-
env['warden'].
|
110
|
+
expect(env['warden']).not_to be_authenticated
|
102
111
|
env['warden'].authenticate?(:pass)
|
103
|
-
env['warden'].
|
104
|
-
env['warden.spec.strategies'].
|
112
|
+
expect(env['warden']).to be_authenticated
|
113
|
+
expect(env['warden.spec.strategies']).to eq([:pass])
|
105
114
|
valid_response
|
106
115
|
end
|
107
116
|
setup_rack(app).call(@env)
|
@@ -110,8 +119,8 @@ describe Warden::Proxy do
|
|
110
119
|
it "should properly send the scope to the strategy" do
|
111
120
|
app = lambda do |env|
|
112
121
|
env['warden'].authenticate(:pass, :scope => :failz)
|
113
|
-
env['warden'].
|
114
|
-
env['warden.spec.strategies'].
|
122
|
+
expect(env['warden']).not_to be_authenticated
|
123
|
+
expect(env['warden.spec.strategies']).to eq([:pass])
|
115
124
|
valid_response
|
116
125
|
end
|
117
126
|
setup_rack(app).call(@env)
|
@@ -120,8 +129,8 @@ describe Warden::Proxy do
|
|
120
129
|
it "should try multiple authentication strategies" do
|
121
130
|
app = lambda do |env|
|
122
131
|
env['warden'].authenticate(:password,:pass)
|
123
|
-
env['warden'].
|
124
|
-
env['warden.spec.strategies'].
|
132
|
+
expect(env['warden']).to be_authenticated
|
133
|
+
expect(env['warden.spec.strategies']).to eq([:password, :pass])
|
125
134
|
valid_response
|
126
135
|
end
|
127
136
|
setup_rack(app).call(@env)
|
@@ -134,7 +143,7 @@ describe Warden::Proxy do
|
|
134
143
|
valid_response
|
135
144
|
end
|
136
145
|
setup_rack(app).call(@env)
|
137
|
-
@env['warden'].user.
|
146
|
+
expect(@env['warden'].user).to eq("foo as a user")
|
138
147
|
end
|
139
148
|
|
140
149
|
it "should look for an active user in the session with authenticate?" do
|
@@ -144,7 +153,7 @@ describe Warden::Proxy do
|
|
144
153
|
valid_response
|
145
154
|
end
|
146
155
|
setup_rack(app).call(@env)
|
147
|
-
@env['warden'].user(:foo_scope).
|
156
|
+
expect(@env['warden'].user(:foo_scope)).to eq("a foo user")
|
148
157
|
end
|
149
158
|
|
150
159
|
it "should look for an active user in the session with authenticate!" do
|
@@ -154,7 +163,7 @@ describe Warden::Proxy do
|
|
154
163
|
valid_response
|
155
164
|
end
|
156
165
|
setup_rack(app).call(@env)
|
157
|
-
@env['warden'].user(:foo_scope).
|
166
|
+
expect(@env['warden'].user(:foo_scope)).to eq("a foo user")
|
158
167
|
end
|
159
168
|
|
160
169
|
it "should throw an error when authenticate!" do
|
@@ -169,23 +178,23 @@ describe Warden::Proxy do
|
|
169
178
|
app = lambda do |env|
|
170
179
|
env['rack.session']['warden.user.foo.key'] = 'foo user'
|
171
180
|
env['rack.session']['warden.user.bar.key'] = 'bar user'
|
172
|
-
env['warden'].
|
173
|
-
env['warden'].
|
174
|
-
env['warden'].
|
181
|
+
expect(env['warden']).to be_authenticated(:foo)
|
182
|
+
expect(env['warden']).to be_authenticated(:bar)
|
183
|
+
expect(env['warden']).not_to be_authenticated # default scope
|
175
184
|
valid_response
|
176
185
|
end
|
177
186
|
setup_rack(app).call(@env)
|
178
|
-
@env['warden'].user(:foo).
|
179
|
-
@env['warden'].user(:bar).
|
180
|
-
@env['warden'].user.
|
187
|
+
expect(@env['warden'].user(:foo)).to eq('foo user')
|
188
|
+
expect(@env['warden'].user(:bar)).to eq('bar user')
|
189
|
+
expect(@env['warden'].user).to be_nil
|
181
190
|
end
|
182
191
|
|
183
192
|
it "should not authenticate other scopes just because the first is authenticated" do
|
184
193
|
app = lambda do |env|
|
185
194
|
env['warden'].authenticate(:pass, :scope => :foo)
|
186
195
|
env['warden'].authenticate(:invalid, :scope => :bar)
|
187
|
-
env['warden'].
|
188
|
-
env['warden'].
|
196
|
+
expect(env['warden']).to be_authenticated(:foo)
|
197
|
+
expect(env['warden']).not_to be_authenticated(:bar)
|
189
198
|
valid_response
|
190
199
|
end
|
191
200
|
setup_rack(app).call(@env)
|
@@ -199,7 +208,7 @@ describe Warden::Proxy do
|
|
199
208
|
env["rack.session"]["counter"] += 1
|
200
209
|
if env["warden.on"]
|
201
210
|
env["warden"].authenticate!(:pass)
|
202
|
-
env["warden"].
|
211
|
+
expect(env["warden"]).to be_authenticated
|
203
212
|
end
|
204
213
|
valid_response
|
205
214
|
end
|
@@ -207,29 +216,29 @@ describe Warden::Proxy do
|
|
207
216
|
# Setup a rack app with Pool session.
|
208
217
|
app = setup_rack(app, :session => Rack::Session::Pool).to_app
|
209
218
|
response = app.call(@env)
|
210
|
-
@env["rack.session"]["counter"].
|
219
|
+
expect(@env["rack.session"]["counter"]).to eq(1)
|
211
220
|
|
212
221
|
# Ensure a cookie was given back
|
213
222
|
cookie = response[1]["Set-Cookie"]
|
214
|
-
cookie.
|
223
|
+
expect(cookie).not_to be_nil
|
215
224
|
|
216
225
|
# Ensure a session id was given
|
217
226
|
sid = cookie.match(SID_REGEXP)[1]
|
218
|
-
sid.
|
227
|
+
expect(sid).not_to be_nil
|
219
228
|
|
220
229
|
# Do another request, giving a cookie but turning on warden authentication
|
221
230
|
env = env_with_params("/", {}, 'rack.session' => @env['rack.session'], "HTTP_COOKIE" => cookie, "warden.on" => true)
|
222
231
|
response = app.call(env)
|
223
|
-
env["rack.session"]["counter"].
|
232
|
+
expect(env["rack.session"]["counter"]).to be(2)
|
224
233
|
|
225
234
|
# Regardless of rack version, a cookie should be sent back
|
226
235
|
new_cookie = response[1]["Set-Cookie"]
|
227
|
-
new_cookie.
|
236
|
+
expect(new_cookie).not_to be_nil
|
228
237
|
|
229
238
|
# And the session id in this cookie should not be the same as the previous one
|
230
239
|
new_sid = new_cookie.match(SID_REGEXP)[1]
|
231
|
-
new_sid.
|
232
|
-
new_sid.
|
240
|
+
expect(new_sid).not_to be_nil
|
241
|
+
expect(new_sid).not_to eq(sid)
|
233
242
|
end
|
234
243
|
|
235
244
|
it "should not renew session when user is fetch" do
|
@@ -237,27 +246,27 @@ describe Warden::Proxy do
|
|
237
246
|
env["rack.session"]["counter"] ||= 0
|
238
247
|
env["rack.session"]["counter"] += 1
|
239
248
|
env["warden"].authenticate!(:pass)
|
240
|
-
env["warden"].
|
249
|
+
expect(env["warden"]).to be_authenticated
|
241
250
|
valid_response
|
242
251
|
end
|
243
252
|
|
244
253
|
# Setup a rack app with Pool session.
|
245
254
|
app = setup_rack(app, :session => Rack::Session::Pool).to_app
|
246
255
|
response = app.call(@env)
|
247
|
-
@env["rack.session"]["counter"].
|
256
|
+
expect(@env["rack.session"]["counter"]).to eq(1)
|
248
257
|
|
249
258
|
# Ensure a cookie was given back
|
250
259
|
cookie = response[1]["Set-Cookie"]
|
251
|
-
cookie.
|
260
|
+
expect(cookie).not_to be_nil
|
252
261
|
|
253
262
|
# Ensure a session id was given
|
254
263
|
sid = cookie.match(SID_REGEXP)[1]
|
255
|
-
sid.
|
264
|
+
expect(sid).not_to be_nil
|
256
265
|
|
257
266
|
# Do another request, passing the cookie. The user should be fetched from cookie.
|
258
267
|
env = env_with_params("/", {}, "HTTP_COOKIE" => cookie)
|
259
268
|
response = app.call(env)
|
260
|
-
env["rack.session"]["counter"].
|
269
|
+
expect(env["rack.session"]["counter"]).to eq(2)
|
261
270
|
|
262
271
|
# Depending on rack version, a cookie will be returned with the
|
263
272
|
# same session id or no cookie is given back (becase it did not change).
|
@@ -274,10 +283,10 @@ describe Warden::Proxy do
|
|
274
283
|
it "should run strategies just once for a given scope" do
|
275
284
|
app = lambda do |env|
|
276
285
|
env['warden'].authenticate(:password, :pass, :scope => :failz)
|
277
|
-
env['warden'].
|
286
|
+
expect(env['warden']).not_to be_authenticated(:failz)
|
278
287
|
env['warden'].authenticate(:password, :pass, :scope => :failz)
|
279
|
-
env['warden'].
|
280
|
-
env['warden.spec.strategies'].
|
288
|
+
expect(env['warden']).not_to be_authenticated(:failz)
|
289
|
+
expect(env['warden.spec.strategies']).to eq([:password, :pass])
|
281
290
|
valid_response
|
282
291
|
end
|
283
292
|
setup_rack(app).call(@env)
|
@@ -288,7 +297,7 @@ describe Warden::Proxy do
|
|
288
297
|
env['warden'].authenticate(:password, :pass, :scope => :failz)
|
289
298
|
env['warden'].clear_strategies_cache!(:scope => :failz)
|
290
299
|
env['warden'].authenticate(:password, :pass, :scope => :failz)
|
291
|
-
env['warden.spec.strategies'].
|
300
|
+
expect(env['warden.spec.strategies']).to eq([:password, :pass, :password, :pass])
|
292
301
|
valid_response
|
293
302
|
end
|
294
303
|
setup_rack(app).call(@env)
|
@@ -299,7 +308,7 @@ describe Warden::Proxy do
|
|
299
308
|
env['warden'].authenticate(:password, :pass, :scope => :failz)
|
300
309
|
env['warden'].clear_strategies_cache!(:password, :scope => :failz)
|
301
310
|
env['warden'].authenticate(:password, :pass, :scope => :failz)
|
302
|
-
env['warden.spec.strategies'].
|
311
|
+
expect(env['warden.spec.strategies']).to eq([:password, :pass, :password])
|
303
312
|
valid_response
|
304
313
|
end
|
305
314
|
setup_rack(app).call(@env)
|
@@ -308,10 +317,10 @@ describe Warden::Proxy do
|
|
308
317
|
it "should run the strategies several times for different scopes" do
|
309
318
|
app = lambda do |env|
|
310
319
|
env['warden'].authenticate(:password, :pass, :scope => :failz)
|
311
|
-
env['warden'].
|
320
|
+
expect(env['warden']).not_to be_authenticated(:failz)
|
312
321
|
env['warden'].authenticate(:password, :pass)
|
313
|
-
env['warden'].
|
314
|
-
env['warden.spec.strategies'].
|
322
|
+
expect(env['warden']).to be_authenticated
|
323
|
+
expect(env['warden.spec.strategies']).to eq([:password, :pass, :password, :pass])
|
315
324
|
valid_response
|
316
325
|
end
|
317
326
|
setup_rack(app).call(@env)
|
@@ -320,9 +329,9 @@ describe Warden::Proxy do
|
|
320
329
|
it "should not run strategies until cache is cleaned if latest winning strategy halted" do
|
321
330
|
app = lambda do |env|
|
322
331
|
env['warden'].authenticate(:failz)
|
323
|
-
env['warden'].
|
332
|
+
expect(env['warden']).not_to be_authenticated
|
324
333
|
env['warden'].authenticate(:pass)
|
325
|
-
env['warden'].winning_strategy.message.
|
334
|
+
expect(env['warden'].winning_strategy.message).to eq("The Fails Strategy Has Failed You")
|
326
335
|
valid_response
|
327
336
|
end
|
328
337
|
setup_rack(app).call(@env)
|
@@ -332,9 +341,9 @@ describe Warden::Proxy do
|
|
332
341
|
session = Warden::SessionSerializer.new(@env)
|
333
342
|
app = lambda do |env|
|
334
343
|
env['warden'].authenticate(:single)
|
335
|
-
env['warden'].
|
336
|
-
env['warden'].user.
|
337
|
-
session.
|
344
|
+
expect(env['warden']).to be_authenticated
|
345
|
+
expect(env['warden'].user).to eq("Valid User")
|
346
|
+
expect(session).not_to be_stored(:default)
|
338
347
|
valid_response
|
339
348
|
end
|
340
349
|
setup_rack(app).call(@env)
|
@@ -345,9 +354,9 @@ describe Warden::Proxy do
|
|
345
354
|
it "should store the user into the session" do
|
346
355
|
app = lambda do |env|
|
347
356
|
env['warden'].authenticate(:pass)
|
348
|
-
env['warden'].
|
349
|
-
env['warden'].user.
|
350
|
-
env['rack.session']["warden.user.default.key"].
|
357
|
+
expect(env['warden']).to be_authenticated
|
358
|
+
expect(env['warden'].user).to eq("Valid User")
|
359
|
+
expect(env['rack.session']["warden.user.default.key"]).to eq("Valid User")
|
351
360
|
valid_response
|
352
361
|
end
|
353
362
|
setup_rack(app).call(@env)
|
@@ -356,9 +365,9 @@ describe Warden::Proxy do
|
|
356
365
|
it "should not store the user if the :store option is set to false" do
|
357
366
|
app = lambda do |env|
|
358
367
|
env['warden'].authenticate(:pass, :store => false)
|
359
|
-
env['warden'].
|
360
|
-
env['warden'].user.
|
361
|
-
env['rack.session']['warden.user.default.key'].
|
368
|
+
expect(env['warden']).to be_authenticated
|
369
|
+
expect(env['warden'].user).to eq("Valid User")
|
370
|
+
expect(env['rack.session']['warden.user.default.key']).to be_nil
|
362
371
|
valid_response
|
363
372
|
end
|
364
373
|
setup_rack(app).call(@env)
|
@@ -368,8 +377,8 @@ describe Warden::Proxy do
|
|
368
377
|
app = lambda do |env|
|
369
378
|
env['rack.session'] = nil
|
370
379
|
env['warden'].authenticate(:pass, :store => false)
|
371
|
-
env['warden'].
|
372
|
-
env['warden'].user.
|
380
|
+
expect(env['warden']).to be_authenticated
|
381
|
+
expect(env['warden'].user).to eq("Valid User")
|
373
382
|
valid_response
|
374
383
|
end
|
375
384
|
setup_rack(app).call(@env)
|
@@ -377,7 +386,7 @@ describe Warden::Proxy do
|
|
377
386
|
|
378
387
|
it "should not run the callbacks when :run_callbacks is false" do
|
379
388
|
app = lambda do |env|
|
380
|
-
env['warden'].manager.
|
389
|
+
expect(env['warden'].manager).not_to receive(:_run_callbacks)
|
381
390
|
env['warden'].authenticate(:run_callbacks => false, :scope => :pass)
|
382
391
|
valid_response
|
383
392
|
end
|
@@ -386,7 +395,7 @@ describe Warden::Proxy do
|
|
386
395
|
|
387
396
|
it "should run the callbacks when :run_callbacks is true" do
|
388
397
|
app = lambda do |env|
|
389
|
-
env['warden'].manager.
|
398
|
+
expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once)
|
390
399
|
env['warden'].authenticate(:pass)
|
391
400
|
valid_response
|
392
401
|
end
|
@@ -395,29 +404,29 @@ describe Warden::Proxy do
|
|
395
404
|
|
396
405
|
it "should run the callbacks by default" do
|
397
406
|
app = lambda do |env|
|
398
|
-
env['warden'].manager.
|
407
|
+
expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once)
|
399
408
|
env['warden'].authenticate(:pass)
|
400
409
|
valid_response
|
401
410
|
end
|
402
411
|
setup_rack(app).call(@env)
|
403
|
-
end
|
412
|
+
end
|
404
413
|
end
|
405
414
|
|
406
415
|
describe "lock" do
|
407
416
|
it "should not run any strategy" do
|
408
|
-
|
417
|
+
_app = lambda do |env|
|
409
418
|
env['warden'].lock!
|
410
419
|
env['warden'].authenticate(:pass)
|
411
|
-
env['warden'].user.
|
420
|
+
expect(env['warden'].user).to be_nil
|
412
421
|
valid_response
|
413
422
|
end
|
414
423
|
end
|
415
424
|
|
416
425
|
it "should keep already authenticated users" do
|
417
|
-
|
426
|
+
_app = lambda do |env|
|
418
427
|
env['warden'].authenticate(:pass)
|
419
428
|
env['warden'].lock!
|
420
|
-
env['warden'].user.
|
429
|
+
expect(env['warden'].user).not_to be_nil
|
421
430
|
valid_response
|
422
431
|
end
|
423
432
|
end
|
@@ -431,7 +440,7 @@ describe Warden::Proxy do
|
|
431
440
|
|
432
441
|
it "should return nil when not logged in" do
|
433
442
|
app = lambda do |env|
|
434
|
-
env['warden'].user.
|
443
|
+
expect(env['warden'].user).to be_nil
|
435
444
|
valid_response
|
436
445
|
end
|
437
446
|
setup_rack(app).call(@env)
|
@@ -439,18 +448,18 @@ describe Warden::Proxy do
|
|
439
448
|
|
440
449
|
it "should not run strategies when not logged in" do
|
441
450
|
app = lambda do |env|
|
442
|
-
env['warden'].user.
|
443
|
-
env['warden.spec.strategies'].
|
451
|
+
expect(env['warden'].user).to be_nil
|
452
|
+
expect(env['warden.spec.strategies']).to be_nil
|
444
453
|
valid_response
|
445
454
|
end
|
446
455
|
setup_rack(app).call(@env)
|
447
456
|
end
|
448
457
|
|
449
458
|
it "should cache unfound user" do
|
450
|
-
Warden::SessionSerializer.
|
459
|
+
expect_any_instance_of(Warden::SessionSerializer).to receive(:fetch).once
|
451
460
|
app = lambda do |env|
|
452
|
-
env['warden'].user.
|
453
|
-
env['warden'].user.
|
461
|
+
expect(env['warden'].user).to be_nil
|
462
|
+
expect(env['warden'].user).to be_nil
|
454
463
|
valid_response
|
455
464
|
end
|
456
465
|
setup_rack(app).call(@env)
|
@@ -464,17 +473,17 @@ describe Warden::Proxy do
|
|
464
473
|
|
465
474
|
it "should take the user from the session when logged in" do
|
466
475
|
app = lambda do |env|
|
467
|
-
env['warden'].user.
|
476
|
+
expect(env['warden'].user).to eq("A Previous User")
|
468
477
|
valid_response
|
469
478
|
end
|
470
479
|
setup_rack(app).call(@env)
|
471
480
|
end
|
472
481
|
|
473
482
|
it "should cache found user" do
|
474
|
-
Warden::SessionSerializer.
|
483
|
+
expect_any_instance_of(Warden::SessionSerializer).to receive(:fetch).once.and_return "A Previous User"
|
475
484
|
app = lambda do |env|
|
476
|
-
env['warden'].user.
|
477
|
-
env['warden'].user.
|
485
|
+
expect(env['warden'].user).to eq("A Previous User")
|
486
|
+
expect(env['warden'].user).to eq("A Previous User")
|
478
487
|
valid_response
|
479
488
|
end
|
480
489
|
setup_rack(app).call(@env)
|
@@ -486,13 +495,13 @@ describe Warden::Proxy do
|
|
486
495
|
valid_response
|
487
496
|
end
|
488
497
|
setup_rack(app).call(@env)
|
489
|
-
@env['warden.spec.strategies'].
|
498
|
+
expect(@env['warden.spec.strategies']).not_to include(:pass)
|
490
499
|
end
|
491
500
|
|
492
501
|
describe "run callback option" do
|
493
502
|
it "should not call run_callbacks when we pass a :run_callback => false" do
|
494
503
|
app = lambda do |env|
|
495
|
-
env['warden'].manager.
|
504
|
+
expect(env['warden'].manager).not_to receive(:_run_callbacks)
|
496
505
|
env['warden'].user(:run_callbacks => false)
|
497
506
|
valid_response
|
498
507
|
end
|
@@ -501,7 +510,7 @@ describe Warden::Proxy do
|
|
501
510
|
|
502
511
|
it "should call run_callbacks when we pass a :run_callback => true" do
|
503
512
|
app = lambda do |env|
|
504
|
-
env['warden'].manager.
|
513
|
+
expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once)
|
505
514
|
env['warden'].user(:run_callbacks => true)
|
506
515
|
valid_response
|
507
516
|
end
|
@@ -510,7 +519,7 @@ describe Warden::Proxy do
|
|
510
519
|
|
511
520
|
it "should call run_callbacks by default" do
|
512
521
|
app = lambda do |env|
|
513
|
-
env['warden'].manager.
|
522
|
+
expect(env['warden'].manager).to receive(:_run_callbacks).at_least(:once)
|
514
523
|
env['warden'].user
|
515
524
|
valid_response
|
516
525
|
end
|
@@ -533,54 +542,54 @@ describe Warden::Proxy do
|
|
533
542
|
@app = setup_rack(@app)
|
534
543
|
@env['warden.spec.which_logout'] = :foo
|
535
544
|
@app.call(@env)
|
536
|
-
@env['rack.session']['warden.user.default.key'].
|
537
|
-
@env['rack.session']['warden.user.foo.key'].
|
538
|
-
@env['rack.session'][:foo].
|
545
|
+
expect(@env['rack.session']['warden.user.default.key']).to eq("default key")
|
546
|
+
expect(@env['rack.session']['warden.user.foo.key']).to be_nil
|
547
|
+
expect(@env['rack.session'][:foo]).to eq("bar")
|
539
548
|
end
|
540
549
|
|
541
550
|
it "should logout only the scoped default user" do
|
542
551
|
@app = setup_rack(@app)
|
543
552
|
@env['warden.spec.which_logout'] = :default
|
544
553
|
@app.call(@env)
|
545
|
-
@env['rack.session']['warden.user.default.key'].
|
546
|
-
@env['rack.session']['warden.user.foo.key'].
|
547
|
-
@env['rack.session'][:foo].
|
554
|
+
expect(@env['rack.session']['warden.user.default.key']).to be_nil
|
555
|
+
expect(@env['rack.session']['warden.user.foo.key']).to eq("foo key")
|
556
|
+
expect(@env['rack.session'][:foo]).to eq("bar")
|
548
557
|
end
|
549
558
|
|
550
559
|
it "should clear the session when no argument is given to logout" do
|
551
|
-
@env['rack.session'].
|
560
|
+
expect(@env['rack.session']).not_to be_nil
|
552
561
|
app = lambda do |e|
|
553
562
|
e['warden'].logout
|
554
563
|
valid_response
|
555
564
|
end
|
556
565
|
setup_rack(app).call(@env)
|
557
|
-
@env['rack.session'].
|
566
|
+
expect(@env['rack.session']).to be_empty
|
558
567
|
end
|
559
568
|
|
560
569
|
it "should not raise exception if raw_session is nil" do
|
561
570
|
@app = setup_rack(@app, { nil_session: true })
|
562
571
|
@env['rack.session'] = nil
|
563
572
|
@env['warden.spec.which_logout'] = :foo
|
564
|
-
expect { @app.call(@env) }.to_not raise_error
|
573
|
+
expect { @app.call(@env) }.to_not raise_error
|
565
574
|
end
|
566
575
|
|
567
576
|
it "should clear the user when logging out" do
|
568
|
-
@env['rack.session'].
|
577
|
+
expect(@env['rack.session']).not_to be_nil
|
569
578
|
app = lambda do |e|
|
570
|
-
e['warden'].user.
|
579
|
+
expect(e['warden'].user).not_to be_nil
|
571
580
|
e['warden'].logout
|
572
|
-
e['warden'].
|
573
|
-
e['warden'].user.
|
581
|
+
expect(e['warden']).not_to be_authenticated
|
582
|
+
expect(e['warden'].user).to be_nil
|
574
583
|
valid_response
|
575
584
|
end
|
576
585
|
setup_rack(app).call(@env)
|
577
|
-
@env['warden'].user.
|
586
|
+
expect(@env['warden'].user).to be_nil
|
578
587
|
end
|
579
588
|
|
580
589
|
it "should clear the session data when logging out" do
|
581
|
-
@env['rack.session'].
|
590
|
+
expect(@env['rack.session']).not_to be_nil
|
582
591
|
app = lambda do |e|
|
583
|
-
e['warden'].user.
|
592
|
+
expect(e['warden'].user).not_to be_nil
|
584
593
|
e['warden'].session[:foo] = :bar
|
585
594
|
e['warden'].logout
|
586
595
|
valid_response
|
@@ -589,10 +598,10 @@ describe Warden::Proxy do
|
|
589
598
|
end
|
590
599
|
|
591
600
|
it "should clear out the session by calling reset_session! so that plugins can setup their own session clearing" do
|
592
|
-
@env['rack.session'].
|
601
|
+
expect(@env['rack.session']).not_to be_nil
|
593
602
|
app = lambda do |e|
|
594
|
-
e['warden'].user.
|
595
|
-
e['warden'].
|
603
|
+
expect(e['warden'].user).not_to be_nil
|
604
|
+
expect(e['warden']).to receive(:reset_session!)
|
596
605
|
e['warden'].logout
|
597
606
|
valid_response
|
598
607
|
end
|
@@ -609,7 +618,7 @@ describe Warden::Proxy do
|
|
609
618
|
e['warden'].authenticate! :failz
|
610
619
|
end
|
611
620
|
result = setup_rack(app, :failure_app => failure).call(@env)
|
612
|
-
result.last.
|
621
|
+
expect(result.last).to eq(["The Fails Strategy Has Failed You"])
|
613
622
|
end
|
614
623
|
|
615
624
|
it "should allow access to the success message" do
|
@@ -621,15 +630,15 @@ describe Warden::Proxy do
|
|
621
630
|
success.call(e)
|
622
631
|
end
|
623
632
|
result = setup_rack(app).call(@env)
|
624
|
-
result.last.
|
633
|
+
expect(result.last).to eq(["The Success Strategy Has Accepted You"])
|
625
634
|
end
|
626
635
|
|
627
|
-
it "should not die when accessing a message from a source where no authentication has
|
636
|
+
it "should not die when accessing a message from a source where no authentication has occurred" do
|
628
637
|
app = lambda do |e|
|
629
638
|
[200, {"Content-Type" => "text/plain"}, [e['warden'].message]]
|
630
639
|
end
|
631
640
|
result = setup_rack(app).call(@env)
|
632
|
-
result[2].
|
641
|
+
expect(result[2]).to eq([nil])
|
633
642
|
end
|
634
643
|
end
|
635
644
|
|
@@ -637,8 +646,8 @@ describe Warden::Proxy do
|
|
637
646
|
it "should return false for authenticated? when there are no valid? strategies" do
|
638
647
|
@env['rack.session'] = {}
|
639
648
|
app = lambda do |e|
|
640
|
-
e['warden'].authenticate(:invalid).
|
641
|
-
e['warden'].
|
649
|
+
expect(e['warden'].authenticate(:invalid)).to be_nil
|
650
|
+
expect(e['warden']).not_to be_authenticated
|
642
651
|
end
|
643
652
|
setup_rack(app).call(@env)
|
644
653
|
end
|
@@ -646,7 +655,7 @@ describe Warden::Proxy do
|
|
646
655
|
it "should return nil for authenticate when there are no valid strategies" do
|
647
656
|
@env['rack.session'] = {}
|
648
657
|
app = lambda do |e|
|
649
|
-
e['warden'].authenticate(:invalid).
|
658
|
+
expect(e['warden'].authenticate(:invalid)).to be_nil
|
650
659
|
end
|
651
660
|
setup_rack(app).call(@env)
|
652
661
|
end
|
@@ -654,7 +663,7 @@ describe Warden::Proxy do
|
|
654
663
|
it "should return false for authenticate? when there are no valid strategies" do
|
655
664
|
@env['rack.session'] = {}
|
656
665
|
app = lambda do |e|
|
657
|
-
e['warden'].authenticate?(:invalid).
|
666
|
+
expect(e['warden'].authenticate?(:invalid)).to eq(false)
|
658
667
|
end
|
659
668
|
setup_rack(app).call(@env)
|
660
669
|
end
|
@@ -665,7 +674,7 @@ describe Warden::Proxy do
|
|
665
674
|
e['warden'].authenticate!(:invalid)
|
666
675
|
end
|
667
676
|
result = setup_rack(app).call(@env)
|
668
|
-
result.first.
|
677
|
+
expect(result.first).to eq(401)
|
669
678
|
end
|
670
679
|
end
|
671
680
|
|
@@ -678,7 +687,7 @@ describe Warden::Proxy do
|
|
678
687
|
|
679
688
|
it "should return true when authenticated in the session" do
|
680
689
|
app = lambda do |e|
|
681
|
-
e['warden'].
|
690
|
+
expect(e['warden']).to be_authenticated
|
682
691
|
end
|
683
692
|
setup_rack(app).call(@env)
|
684
693
|
end
|
@@ -690,7 +699,7 @@ describe Warden::Proxy do
|
|
690
699
|
end
|
691
700
|
end
|
692
701
|
setup_rack(app).call(@env)
|
693
|
-
$captures.
|
702
|
+
expect($captures).to eq([:in_the_block])
|
694
703
|
end
|
695
704
|
|
696
705
|
it "should authenticate for a user in a different scope" do
|
@@ -701,7 +710,7 @@ describe Warden::Proxy do
|
|
701
710
|
end
|
702
711
|
end
|
703
712
|
setup_rack(app).call(@env)
|
704
|
-
$captures.
|
713
|
+
expect($captures).to eq([:in_the_foo_block])
|
705
714
|
end
|
706
715
|
end
|
707
716
|
|
@@ -713,7 +722,7 @@ describe Warden::Proxy do
|
|
713
722
|
|
714
723
|
it "should return false when authenticated in the session" do
|
715
724
|
app = lambda do |e|
|
716
|
-
e['warden'].
|
725
|
+
expect(e['warden']).not_to be_authenticated
|
717
726
|
end
|
718
727
|
setup_rack(app).call(@env)
|
719
728
|
end
|
@@ -727,7 +736,7 @@ describe Warden::Proxy do
|
|
727
736
|
valid_response
|
728
737
|
end
|
729
738
|
setup_rack(app).call(@env)
|
730
|
-
@env['warden'].user(:foo_scope).
|
739
|
+
expect(@env['warden'].user(:foo_scope)).to be_nil
|
731
740
|
ensure
|
732
741
|
Warden::Manager.serialize_from_session { |k| k }
|
733
742
|
end
|
@@ -740,7 +749,7 @@ describe Warden::Proxy do
|
|
740
749
|
end
|
741
750
|
end
|
742
751
|
setup_rack(app).call(@env)
|
743
|
-
$captures.
|
752
|
+
expect($captures).to eq([])
|
744
753
|
end
|
745
754
|
|
746
755
|
it "should not yield for a user in a different scope" do
|
@@ -750,7 +759,7 @@ describe Warden::Proxy do
|
|
750
759
|
end
|
751
760
|
end
|
752
761
|
setup_rack(app).call(@env)
|
753
|
-
$captures.
|
762
|
+
expect($captures).to eq([])
|
754
763
|
end
|
755
764
|
end
|
756
765
|
end
|
@@ -764,9 +773,9 @@ describe Warden::Proxy do
|
|
764
773
|
|
765
774
|
it "should return false when authenticated in the session" do
|
766
775
|
app = lambda do |e|
|
767
|
-
e['warden'].
|
776
|
+
expect(e['warden']).not_to be_unauthenticated
|
768
777
|
end
|
769
|
-
|
778
|
+
_result = setup_rack(app).call(@env)
|
770
779
|
end
|
771
780
|
|
772
781
|
it "should not yield to a block when the block is passed and authenticated" do
|
@@ -776,7 +785,7 @@ describe Warden::Proxy do
|
|
776
785
|
end
|
777
786
|
end
|
778
787
|
setup_rack(app).call(@env)
|
779
|
-
$captures.
|
788
|
+
expect($captures).to eq([])
|
780
789
|
end
|
781
790
|
|
782
791
|
it "should not yield to the block for a user in a different scope" do
|
@@ -787,7 +796,7 @@ describe Warden::Proxy do
|
|
787
796
|
end
|
788
797
|
end
|
789
798
|
setup_rack(app).call(@env)
|
790
|
-
$captures.
|
799
|
+
expect($captures).to eq([])
|
791
800
|
end
|
792
801
|
end
|
793
802
|
|
@@ -799,7 +808,7 @@ describe Warden::Proxy do
|
|
799
808
|
|
800
809
|
it "should return false when unauthenticated in the session" do
|
801
810
|
app = lambda do |e|
|
802
|
-
e['warden'].
|
811
|
+
expect(e['warden']).to be_unauthenticated
|
803
812
|
end
|
804
813
|
setup_rack(app).call(@env)
|
805
814
|
end
|
@@ -811,7 +820,7 @@ describe Warden::Proxy do
|
|
811
820
|
end
|
812
821
|
end
|
813
822
|
setup_rack(app).call(@env)
|
814
|
-
$captures.
|
823
|
+
expect($captures).to eq([:in_the_block])
|
815
824
|
end
|
816
825
|
|
817
826
|
it "should yield for a user in a different scope" do
|
@@ -821,7 +830,7 @@ describe Warden::Proxy do
|
|
821
830
|
end
|
822
831
|
end
|
823
832
|
setup_rack(app).call(@env)
|
824
|
-
$captures.
|
833
|
+
expect($captures).to eq([:in_the_bar_block])
|
825
834
|
end
|
826
835
|
end
|
827
836
|
end
|
@@ -833,7 +842,7 @@ describe Warden::Proxy do
|
|
833
842
|
|
834
843
|
it "should have a config attribute" do
|
835
844
|
app = def_app do |e|
|
836
|
-
e['warden'].config.
|
845
|
+
expect(e['warden'].config).to be_a_kind_of(Hash)
|
837
846
|
valid_response
|
838
847
|
end
|
839
848
|
app.call(@env)
|
@@ -881,27 +890,27 @@ describe "dynamic default_strategies" do
|
|
881
890
|
|
882
891
|
it "should allow me to change the default strategies on the fly" do
|
883
892
|
app = wrap_app(@app) do |e|
|
884
|
-
e['warden'].default_strategies.
|
885
|
-
e['warden'].config.default_strategies.
|
893
|
+
expect(e['warden'].default_strategies).to eq([:password])
|
894
|
+
expect(e['warden'].config.default_strategies).to eq([:password])
|
886
895
|
e['warden'].default_strategies :one
|
887
896
|
e['warden'].authenticate!
|
888
897
|
Rack::Response.new("OK").finish
|
889
898
|
end
|
890
899
|
setup_rack(app).call(@env)
|
891
900
|
|
892
|
-
$captures.
|
901
|
+
expect($captures).to eq([:one])
|
893
902
|
end
|
894
903
|
|
895
904
|
it "should allow me to append to the default strategies on the fly" do
|
896
905
|
app = wrap_app(@app) do |e|
|
897
906
|
e['warden'].default_strategies << :one
|
898
|
-
e['warden'].default_strategies.
|
907
|
+
expect(e['warden'].default_strategies).to eq([:password, :one])
|
899
908
|
e['warden'].authenticate!
|
900
909
|
Rack::Response.new("OK").finish
|
901
910
|
end
|
902
911
|
setup_rack(app).call(@env)
|
903
912
|
|
904
|
-
$captures.
|
913
|
+
expect($captures).to eq([:one])
|
905
914
|
end
|
906
915
|
|
907
916
|
it "should allow me to set the default strategies on a per scope basis" do
|
@@ -909,15 +918,15 @@ describe "dynamic default_strategies" do
|
|
909
918
|
w = e['warden']
|
910
919
|
w.default_strategies(:two, :one, :scope => :foo)
|
911
920
|
w.default_strategies(:two, :scope => :default)
|
912
|
-
w.default_strategies(:scope => :foo).
|
921
|
+
expect(w.default_strategies(:scope => :foo)).to eq([:two, :one])
|
913
922
|
w.authenticate(:scope => :foo)
|
914
|
-
$captures.
|
923
|
+
expect($captures).to eq([:two, :one])
|
915
924
|
$captures.clear
|
916
925
|
w.authenticate
|
917
|
-
$captures.
|
926
|
+
expect($captures).to eq([:two])
|
918
927
|
end
|
919
928
|
setup_rack(app).call(@env)
|
920
|
-
$captures.
|
929
|
+
expect($captures).to eq([:two])
|
921
930
|
end
|
922
931
|
|
923
932
|
it "should allow me to setup default strategies for each scope on the manager" do
|
@@ -931,28 +940,25 @@ describe "dynamic default_strategies" do
|
|
931
940
|
run(lambda do |e|
|
932
941
|
w = e['warden']
|
933
942
|
w.authenticate
|
934
|
-
$captures.should == [:one]
|
935
|
-
$captures.clear
|
936
943
|
w.authenticate(:scope => :foo)
|
937
|
-
$captures.should == [:two, :one]
|
938
944
|
$captures << :complete
|
939
945
|
end)
|
940
946
|
end
|
941
947
|
builder.to_app.call(@env)
|
942
|
-
$captures.
|
948
|
+
expect($captures).to eq([:one, :two, :one, :complete])
|
943
949
|
end
|
944
950
|
|
945
951
|
it "should not change the master configurations strategies when I change them" do
|
946
952
|
app = wrap_app(@app) do |e|
|
947
953
|
e['warden'].default_strategies << :one
|
948
|
-
e['warden'].default_strategies.
|
949
|
-
e['warden'].manager.config.default_strategies.
|
954
|
+
expect(e['warden'].default_strategies).to eq([:password, :one])
|
955
|
+
expect(e['warden'].manager.config.default_strategies).to eq([:password])
|
950
956
|
e['warden'].authenticate!
|
951
957
|
Rack::Response.new("OK").finish
|
952
958
|
end
|
953
959
|
setup_rack(app).call(@env)
|
954
960
|
|
955
|
-
$captures.
|
961
|
+
expect($captures).to eq([:one])
|
956
962
|
end
|
957
963
|
|
958
964
|
describe "default scope options" do
|
@@ -974,11 +980,12 @@ describe "dynamic default_strategies" do
|
|
974
980
|
env["rack.session"] = {}
|
975
981
|
builder.to_app.call(env)
|
976
982
|
request = Rack::Request.new(env)
|
977
|
-
request.path.
|
983
|
+
expect(request.path).to eq("/some_bad_action")
|
978
984
|
end
|
979
985
|
|
980
986
|
it "should allow me to set store, false on a given scope" do
|
981
987
|
$captures = []
|
988
|
+
warden = []
|
982
989
|
builder = Rack::Builder.new do
|
983
990
|
use Warden::Manager do |config|
|
984
991
|
config.default_strategies :one
|
@@ -995,22 +1002,24 @@ describe "dynamic default_strategies" do
|
|
995
1002
|
w.authenticate(:scope => :foo)
|
996
1003
|
w.authenticate(:one, :scope => :bar)
|
997
1004
|
w.authenticate(:one, :scope => :baz, :store => true)
|
998
|
-
|
999
|
-
w.user(:foo).should == "User"
|
1000
|
-
w.user(:bar).should == "User"
|
1001
|
-
w.user(:baz).should == "User"
|
1005
|
+
warden << w
|
1002
1006
|
$captures << :complete
|
1003
1007
|
Rack::Response.new("OK").finish
|
1004
1008
|
end)
|
1005
1009
|
end
|
1006
1010
|
session = @env["rack.session"] = {}
|
1007
1011
|
builder.to_app.call(@env)
|
1008
|
-
$captures.
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1012
|
+
expect($captures).to include(:complete)
|
1013
|
+
w = warden.first
|
1014
|
+
expect(w.user).to eq("User")
|
1015
|
+
expect(w.user(:foo)).to eq("User")
|
1016
|
+
expect(w.user(:bar)).to eq("User")
|
1017
|
+
expect(w.user(:baz)).to eq("User")
|
1018
|
+
expect(session['warden.user.default.key']).to eq("User")
|
1019
|
+
expect(session['warden.user.foo.key']).to eq("User")
|
1020
|
+
expect(session.key?('warden.user.bar.key')).to eq(false)
|
1021
|
+
expect(session['warden.user.bar.key']).to be_nil
|
1022
|
+
expect(session['warden.user.baz.key']).to eq("User")
|
1014
1023
|
end
|
1015
1024
|
end
|
1016
1025
|
|
@@ -1025,8 +1034,8 @@ describe "dynamic default_strategies" do
|
|
1025
1034
|
setup_rack(success_app).call(env)
|
1026
1035
|
proxy = env["warden"]
|
1027
1036
|
|
1028
|
-
proxy.env['PATH_INFO'].
|
1029
|
-
proxy.
|
1037
|
+
expect(proxy.env['PATH_INFO']).to match(@asset_regex)
|
1038
|
+
expect(proxy).to be_asset_request
|
1030
1039
|
end
|
1031
1040
|
|
1032
1041
|
it "should return false if PATH_INFO is not in asset list" do
|
@@ -1034,8 +1043,8 @@ describe "dynamic default_strategies" do
|
|
1034
1043
|
setup_rack(success_app).call(env)
|
1035
1044
|
proxy = env["warden"]
|
1036
1045
|
|
1037
|
-
proxy.env['PATH_INFO'].
|
1038
|
-
proxy.
|
1046
|
+
expect(proxy.env['PATH_INFO']).not_to match(@asset_regex)
|
1047
|
+
expect(proxy).not_to be_asset_request
|
1039
1048
|
end
|
1040
1049
|
end
|
1041
1050
|
end
|