warden 1.2.3 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/History.rdoc +3 -0
- 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 +56 -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 +31 -23
- data/spec/warden/test/test_mode_spec.rb +12 -13
- metadata +19 -22
data/spec/warden/hooks_spec.rb
CHANGED
@@ -21,13 +21,13 @@ describe "standard authentication hooks" do
|
|
21
21
|
RAM.after_set_user do |user, auth, opts|
|
22
22
|
"boo"
|
23
23
|
end
|
24
|
-
RAM._after_set_user.
|
24
|
+
expect(RAM._after_set_user.length).to eq(1)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should allow me to add multiple after_set_user hooks" do
|
28
28
|
RAM.after_set_user{|user, auth, opts| "foo"}
|
29
29
|
RAM.after_set_user{|u,a| "bar"}
|
30
|
-
RAM._after_set_user.
|
30
|
+
expect(RAM._after_set_user.length).to eq(2)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should run each after_set_user hook after the user is set" do
|
@@ -40,9 +40,9 @@ describe "standard authentication hooks" do
|
|
40
40
|
end
|
41
41
|
env = env_with_params
|
42
42
|
setup_rack(app).call(env)
|
43
|
-
env['warden'].user.
|
44
|
-
env['warden.spec.hook.foo'].
|
45
|
-
env['warden.spec.hook.bar'].
|
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
46
|
end
|
47
47
|
|
48
48
|
it "should not run the event specified with except" do
|
@@ -76,22 +76,22 @@ describe "standard authentication hooks" do
|
|
76
76
|
end
|
77
77
|
env = env_with_params
|
78
78
|
setup_rack(app).call(env)
|
79
|
-
env['warden.spec.order'].
|
79
|
+
expect(env['warden.spec.order']).to eq([1,2,3])
|
80
80
|
end
|
81
81
|
|
82
82
|
context "after_authentication" do
|
83
83
|
it "should be a wrapper to after_set_user behavior" do
|
84
84
|
RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
|
85
85
|
RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
|
86
|
-
RAM.after_authentication{|u,a,o| o[:event].
|
86
|
+
RAM.after_authentication{|u,a,o| expect(o[:event]).to eq(:authentication) }
|
87
87
|
app = lambda do |e|
|
88
88
|
e['warden'].authenticate(:pass)
|
89
89
|
valid_response
|
90
90
|
end
|
91
91
|
env = env_with_params
|
92
92
|
setup_rack(app).call(env)
|
93
|
-
env['warden.spec.hook.baz'].
|
94
|
-
env['warden.spec.hook.paz'].
|
93
|
+
expect(env['warden.spec.hook.baz']).to eq('run baz')
|
94
|
+
expect(env['warden.spec.hook.paz']).to eq('run paz')
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should not be invoked on default after_set_user scenario" do
|
@@ -115,7 +115,7 @@ describe "standard authentication hooks" do
|
|
115
115
|
end
|
116
116
|
env = env_with_params
|
117
117
|
setup_rack(app).call(env)
|
118
|
-
env['warden.spec.order'].
|
118
|
+
expect(env['warden.spec.order']).to eq([1,2,3])
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should allow me to log out a user in an after_set_user block" do
|
@@ -127,7 +127,7 @@ describe "standard authentication hooks" do
|
|
127
127
|
end
|
128
128
|
env = env_with_params
|
129
129
|
setup_rack(app).call(env)
|
130
|
-
env['warden'].
|
130
|
+
expect(env['warden']).not_to be_authenticated
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -135,13 +135,13 @@ describe "standard authentication hooks" do
|
|
135
135
|
it "should be a wrapper to after_set_user behavior" do
|
136
136
|
RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
|
137
137
|
RAM.after_fetch{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
|
138
|
-
RAM.after_fetch{|u,a,o| o[:event].
|
138
|
+
RAM.after_fetch{|u,a,o| expect(o[:event]).to eq(:fetch) }
|
139
139
|
env = env_with_params
|
140
140
|
setup_rack(lambda { |e| valid_response }).call(env)
|
141
141
|
env['rack.session']['warden.user.default.key'] = "Foo"
|
142
|
-
env['warden'].user.
|
143
|
-
env['warden.spec.hook.baz'].
|
144
|
-
env['warden.spec.hook.paz'].
|
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
145
|
end
|
146
146
|
|
147
147
|
it "should not be invoked on default after_set_user scenario" do
|
@@ -159,7 +159,7 @@ describe "standard authentication hooks" do
|
|
159
159
|
env = env_with_params
|
160
160
|
setup_rack(lambda { |e| valid_response }).call(env)
|
161
161
|
env['rack.session']['warden.user.default.key'] = nil
|
162
|
-
env['warden'].user.
|
162
|
+
expect(env['warden'].user).to be_nil
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should run filters in the given order" do
|
@@ -174,7 +174,7 @@ describe "standard authentication hooks" do
|
|
174
174
|
end
|
175
175
|
env = env_with_params
|
176
176
|
setup_rack(app).call(env)
|
177
|
-
env['warden.spec.order'].
|
177
|
+
expect(env['warden.spec.order']).to eq([1,2,3])
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
@@ -195,7 +195,7 @@ describe "standard authentication hooks" do
|
|
195
195
|
env = env_with_params
|
196
196
|
setup_rack(lambda { |e| valid_response }).call(env)
|
197
197
|
env['rack.session']['warden.user.default.key'] = "Foo"
|
198
|
-
env['warden'].user.
|
198
|
+
expect(env['warden'].user).to eq("Foo")
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should be called if fetched user is nil" do
|
@@ -203,8 +203,8 @@ describe "standard authentication hooks" do
|
|
203
203
|
RAM.after_failed_fetch{|u,a,o| calls += 1 }
|
204
204
|
env = env_with_params
|
205
205
|
setup_rack(lambda { |e| valid_response }).call(env)
|
206
|
-
env['warden'].user.
|
207
|
-
calls.
|
206
|
+
expect(env['warden'].user).to be_nil
|
207
|
+
expect(calls).to eq(1)
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
@@ -220,13 +220,13 @@ describe "standard authentication hooks" do
|
|
220
220
|
|
221
221
|
it "should allow me to add a before_failure hook" do
|
222
222
|
RAM.before_failure{|env, opts| "foo"}
|
223
|
-
RAM._before_failure.
|
223
|
+
expect(RAM._before_failure.length).to eq(1)
|
224
224
|
end
|
225
225
|
|
226
226
|
it "should allow me to add multiple before_failure hooks" do
|
227
227
|
RAM.before_failure{|env, opts| "foo"}
|
228
228
|
RAM.before_failure{|env, opts| "bar"}
|
229
|
-
RAM._before_failure.
|
229
|
+
expect(RAM._before_failure.length).to eq(2)
|
230
230
|
end
|
231
231
|
|
232
232
|
it "should run each before_failure hooks before failing" do
|
@@ -235,8 +235,8 @@ describe "standard authentication hooks" do
|
|
235
235
|
app = lambda{|e| e['warden'].authenticate!(:failz); valid_response}
|
236
236
|
env = env_with_params
|
237
237
|
setup_rack(app).call(env)
|
238
|
-
env['warden.spec.before_failure.foo'].
|
239
|
-
env['warden.spec.before_failure.bar'].
|
238
|
+
expect(env['warden.spec.before_failure.foo']).to eq("foo")
|
239
|
+
expect(env['warden.spec.before_failure.bar']).to eq("bar")
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should run filters in the given order" do
|
@@ -250,7 +250,7 @@ describe "standard authentication hooks" do
|
|
250
250
|
end
|
251
251
|
env = env_with_params
|
252
252
|
setup_rack(app).call(env)
|
253
|
-
env['warden.spec.order'].
|
253
|
+
expect(env['warden.spec.order']).to eq([1,2,3])
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
@@ -266,13 +266,13 @@ describe "standard authentication hooks" do
|
|
266
266
|
|
267
267
|
it "should allow me to add an before_logout hook" do
|
268
268
|
RAM.before_logout{|user, auth, scopes| "foo"}
|
269
|
-
RAM._before_logout.
|
269
|
+
expect(RAM._before_logout.length).to eq(1)
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should allow me to add multiple after_authentication hooks" do
|
273
273
|
RAM.before_logout{|u,a,o| "bar"}
|
274
274
|
RAM.before_logout{|u,a,o| "baz"}
|
275
|
-
RAM._before_logout.
|
275
|
+
expect(RAM._before_logout.length).to eq(2)
|
276
276
|
end
|
277
277
|
|
278
278
|
it "should run each before_logout hook before logout is run" do
|
@@ -282,8 +282,8 @@ describe "standard authentication hooks" do
|
|
282
282
|
env = env_with_params
|
283
283
|
setup_rack(app).call(env)
|
284
284
|
env['warden'].logout
|
285
|
-
env['warden.spec.hook.lorem'].
|
286
|
-
env['warden.spec.hook.ipsum'].
|
285
|
+
expect(env['warden.spec.hook.lorem']).to eq('run lorem')
|
286
|
+
expect(env['warden.spec.hook.ipsum']).to eq('run ipsum')
|
287
287
|
end
|
288
288
|
|
289
289
|
it "should run before_logout hook for a specified scope" do
|
@@ -301,12 +301,12 @@ describe "standard authentication hooks" do
|
|
301
301
|
setup_rack(app).call(env)
|
302
302
|
|
303
303
|
env['warden'].logout(:scope1)
|
304
|
-
env['warden.spec.hook.a'].
|
305
|
-
env['warden.spec.hook.b'].
|
304
|
+
expect(env['warden.spec.hook.a']).to eq([:scope1])
|
305
|
+
expect(env['warden.spec.hook.b']).to eq([])
|
306
306
|
|
307
307
|
env['warden'].logout(:scope2)
|
308
|
-
env['warden.spec.hook.a'].
|
309
|
-
env['warden.spec.hook.b'].
|
308
|
+
expect(env['warden.spec.hook.a']).to eq([:scope1])
|
309
|
+
expect(env['warden.spec.hook.b']).to eq([:scope2])
|
310
310
|
end
|
311
311
|
|
312
312
|
it "should run filters in the given order" do
|
@@ -321,14 +321,14 @@ describe "standard authentication hooks" do
|
|
321
321
|
end
|
322
322
|
env = env_with_params
|
323
323
|
setup_rack(app).call(env)
|
324
|
-
env['warden.spec.order'].
|
324
|
+
expect(env['warden.spec.order']).to eq([1,2,3])
|
325
325
|
end
|
326
326
|
end
|
327
327
|
|
328
328
|
describe "on_request" do
|
329
329
|
before(:each) do
|
330
|
-
@old_on_request = RAM._on_request.dup
|
331
330
|
RAM = Warden::Manager unless defined?(RAM)
|
331
|
+
@old_on_request = RAM._on_request.dup
|
332
332
|
RAM._on_request.clear
|
333
333
|
end
|
334
334
|
|
@@ -339,13 +339,13 @@ describe "standard authentication hooks" do
|
|
339
339
|
|
340
340
|
it "should allow me to add an on_request hook" do
|
341
341
|
RAM.on_request{|proxy| "foo"}
|
342
|
-
RAM._on_request.
|
342
|
+
expect(RAM._on_request.length).to eq(1)
|
343
343
|
end
|
344
344
|
|
345
345
|
it "should allow me to add multiple on_request hooks" do
|
346
346
|
RAM.on_request{|proxy| "foo"}
|
347
347
|
RAM.on_request{|proxy| "bar"}
|
348
|
-
RAM._on_request.
|
348
|
+
expect(RAM._on_request.length).to eq(2)
|
349
349
|
end
|
350
350
|
|
351
351
|
it "should run each on_request hooks when initializing" do
|
@@ -354,8 +354,8 @@ describe "standard authentication hooks" do
|
|
354
354
|
app = lambda{|e| valid_response}
|
355
355
|
env = env_with_params
|
356
356
|
setup_rack(app).call(env)
|
357
|
-
env['warden.spec.on_request.foo'].
|
358
|
-
env['warden.spec.on_request.bar'].
|
357
|
+
expect(env['warden.spec.on_request.foo']).to eq("foo")
|
358
|
+
expect(env['warden.spec.on_request.bar']).to eq("bar")
|
359
359
|
end
|
360
360
|
|
361
361
|
it "should run filters in the given order" do
|
@@ -367,7 +367,7 @@ describe "standard authentication hooks" do
|
|
367
367
|
end
|
368
368
|
env = Rack::MockRequest.env_for("/", "warden.spec.order" => [])
|
369
369
|
setup_rack(app).call(env)
|
370
|
-
env['warden.spec.order'].
|
370
|
+
expect(env['warden.spec.order']).to eq([1,2,3])
|
371
371
|
end
|
372
372
|
end
|
373
373
|
end
|
data/spec/warden/manager_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Warden::Manager do
|
|
10
10
|
it "should insert a Proxy object into the rack env" do
|
11
11
|
env = env_with_params
|
12
12
|
setup_rack(success_app).call(env)
|
13
|
-
env["warden"].
|
13
|
+
expect(env["warden"]).to be_an_instance_of(Warden::Proxy)
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "thrown auth" do
|
@@ -30,22 +30,32 @@ describe Warden::Manager do
|
|
30
30
|
describe "Failure" do
|
31
31
|
it "should respond with a 401 response if the strategy fails authentication" do
|
32
32
|
env = env_with_params("/", :foo => "bar")
|
33
|
-
app = lambda do |
|
34
|
-
|
33
|
+
app = lambda do |_env|
|
34
|
+
_env['warden'].authenticate(:failz)
|
35
35
|
throw(:warden, :action => :unauthenticated)
|
36
36
|
end
|
37
|
-
result = setup_rack(app, :failure_app => @fail_app).call(env)
|
38
|
-
result.first.
|
37
|
+
result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app?
|
38
|
+
expect(result.first).to eq(401)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should use the failure message given to the failure method" do
|
42
42
|
env = env_with_params("/", {})
|
43
|
-
app = lambda do |
|
44
|
-
|
43
|
+
app = lambda do |_env|
|
44
|
+
_env['warden'].authenticate(:failz)
|
45
45
|
throw(:warden)
|
46
46
|
end
|
47
|
-
result = setup_rack(app, :failure_app => @fail_app).call(env)
|
48
|
-
result.last.
|
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")
|
49
59
|
end
|
50
60
|
|
51
61
|
it "should render the failure app when there's a failure" do
|
@@ -56,29 +66,29 @@ describe Warden::Manager do
|
|
56
66
|
[401, {"Content-Type" => "text/plain"}, ["Failure App"]]
|
57
67
|
end
|
58
68
|
result = setup_rack(app, :failure_app => fail_app).call(env_with_params)
|
59
|
-
result.last.
|
69
|
+
expect(result.last).to eq(["Failure App"])
|
60
70
|
end
|
61
71
|
|
62
72
|
it "should call failure app if warden is thrown even after successful authentication" do
|
63
73
|
env = env_with_params("/", {})
|
64
|
-
app = lambda do |
|
65
|
-
|
74
|
+
app = lambda do |_env|
|
75
|
+
_env['warden'].authenticate(:pass)
|
66
76
|
throw(:warden)
|
67
77
|
end
|
68
78
|
result = setup_rack(app, :failure_app => @fail_app).call(env)
|
69
|
-
result.first.
|
70
|
-
result.last.
|
79
|
+
expect(result.first).to eq(401)
|
80
|
+
expect(result.last).to eq(["You Fail!"])
|
71
81
|
end
|
72
82
|
|
73
83
|
it "should set the attempted url in warden.options hash" do
|
74
84
|
env = env_with_params("/access/path", {})
|
75
|
-
app = lambda do |
|
76
|
-
|
85
|
+
app = lambda do |_env|
|
86
|
+
_env['warden'].authenticate(:pass)
|
77
87
|
throw(:warden)
|
78
88
|
end
|
79
|
-
result = setup_rack(app, :failure_app => @fail_app).call(env)
|
80
|
-
result.first.
|
81
|
-
env["warden.options"][:attempted_path].
|
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")
|
82
92
|
end
|
83
93
|
|
84
94
|
it "should catch a resubmitted request" do
|
@@ -122,21 +132,21 @@ describe Warden::Manager do
|
|
122
132
|
end
|
123
133
|
|
124
134
|
result = builder.to_app.call(env)
|
125
|
-
result[0].
|
126
|
-
result[2].body.
|
127
|
-
$throw_count.
|
135
|
+
expect(result[0]).to eq(401)
|
136
|
+
expect(result[2].body).to eq(["Bad"])
|
137
|
+
expect($throw_count).to eq(2)
|
128
138
|
end
|
129
139
|
|
130
140
|
it "should use the default scopes action when a bare throw is used" do
|
131
141
|
env = env_with_params("/", :foo => "bar")
|
132
142
|
action = nil
|
133
143
|
|
134
|
-
failure = lambda do |
|
135
|
-
action =
|
144
|
+
failure = lambda do |_env|
|
145
|
+
action = _env['PATH_INFO']
|
136
146
|
[401, {}, ['fail']]
|
137
147
|
end
|
138
148
|
|
139
|
-
app = lambda do |
|
149
|
+
app = lambda do |_env|
|
140
150
|
throw(:warden)
|
141
151
|
end
|
142
152
|
result = setup_rack(app,
|
@@ -144,8 +154,8 @@ describe Warden::Manager do
|
|
144
154
|
:configurator => lambda{ |c| c.scope_defaults(:default, :action => 'my_action', :strategies => [:password]) }
|
145
155
|
).call(env)
|
146
156
|
|
147
|
-
action.
|
148
|
-
result.first.
|
157
|
+
expect(action).to eq("/my_action")
|
158
|
+
expect(result.first).to eq(401)
|
149
159
|
end
|
150
160
|
end # failure
|
151
161
|
end
|
@@ -169,9 +179,9 @@ describe Warden::Manager do
|
|
169
179
|
end
|
170
180
|
end
|
171
181
|
result = @app.call(env_with_params)
|
172
|
-
result[0].
|
173
|
-
result[1]["Location"].
|
174
|
-
result[2].
|
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"])
|
175
185
|
end
|
176
186
|
|
177
187
|
it "should redirect with a default message" do
|
@@ -181,9 +191,9 @@ describe Warden::Manager do
|
|
181
191
|
end
|
182
192
|
end
|
183
193
|
result = @app.call(env_with_params)
|
184
|
-
result[0].
|
185
|
-
result[1]['Location'].
|
186
|
-
result[2].
|
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"])
|
187
197
|
end
|
188
198
|
|
189
199
|
it "should redirect with a permanent redirect" do
|
@@ -193,7 +203,7 @@ describe Warden::Manager do
|
|
193
203
|
end
|
194
204
|
end
|
195
205
|
result = @app.call(env_with_params)
|
196
|
-
result[0].
|
206
|
+
expect(result[0]).to eq(301)
|
197
207
|
end
|
198
208
|
|
199
209
|
it "should redirect with a content type" do
|
@@ -203,9 +213,9 @@ describe Warden::Manager do
|
|
203
213
|
end
|
204
214
|
end
|
205
215
|
result = @app.call(env_with_params)
|
206
|
-
result[0].
|
207
|
-
result[1]["Location"].
|
208
|
-
result[1]["Content-Type"].
|
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")
|
209
219
|
end
|
210
220
|
|
211
221
|
it "should redirect with a default content type" do
|
@@ -215,9 +225,9 @@ describe Warden::Manager do
|
|
215
225
|
end
|
216
226
|
end
|
217
227
|
result = @app.call(env_with_params)
|
218
|
-
result[0].
|
219
|
-
result[1]["Location"].
|
220
|
-
result[1]["Content-Type"].
|
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")
|
221
231
|
end
|
222
232
|
end
|
223
233
|
|
@@ -230,9 +240,9 @@ describe Warden::Manager do
|
|
230
240
|
end
|
231
241
|
env = env_with_params
|
232
242
|
result = @app.call(env)
|
233
|
-
result[0].
|
234
|
-
result[2].
|
235
|
-
env['PATH_INFO'].
|
243
|
+
expect(result[0]).to eq(401)
|
244
|
+
expect(result[2]).to eq(["You Fail!"])
|
245
|
+
expect(env['PATH_INFO']).to eq("/unauthenticated")
|
236
246
|
end
|
237
247
|
|
238
248
|
it "should allow you to customize the response" do
|
@@ -242,8 +252,8 @@ describe Warden::Manager do
|
|
242
252
|
end
|
243
253
|
env = env_with_params
|
244
254
|
result = setup_rack(app).call(env)
|
245
|
-
result[0].
|
246
|
-
result[2].
|
255
|
+
expect(result[0]).to eq(401)
|
256
|
+
expect(result[2]).to eq(["Fail From The App"])
|
247
257
|
end
|
248
258
|
|
249
259
|
it "should allow you to customize the response without the explicit call to custom_failure! if not intercepting 401" do
|
@@ -252,8 +262,8 @@ describe Warden::Manager do
|
|
252
262
|
end
|
253
263
|
env = env_with_params
|
254
264
|
result = setup_rack(app, :intercept_401 => false).call(env)
|
255
|
-
result[0].
|
256
|
-
result[2].
|
265
|
+
expect(result[0]).to eq(401)
|
266
|
+
expect(result[2]).to eq(["Fail From The App"])
|
257
267
|
end
|
258
268
|
|
259
269
|
it "should render the failure application for a 401 if no custom_failure flag is set" do
|
@@ -261,8 +271,8 @@ describe Warden::Manager do
|
|
261
271
|
[401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
|
262
272
|
end
|
263
273
|
result = setup_rack(app).call(env_with_params)
|
264
|
-
result[0].
|
265
|
-
result[2].
|
274
|
+
expect(result[0]).to eq(401)
|
275
|
+
expect(result[2]).to eq(["You Fail!"])
|
266
276
|
end
|
267
277
|
|
268
278
|
end # failing
|
@@ -275,9 +285,23 @@ describe Warden::Manager do
|
|
275
285
|
end
|
276
286
|
end
|
277
287
|
result = @app.call(env_with_params)
|
278
|
-
result[0].
|
279
|
-
result[1]["Custom-Header"].
|
280
|
-
result[2].
|
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')
|
281
305
|
end
|
282
306
|
end
|
283
307
|
|
@@ -290,8 +314,8 @@ describe Warden::Manager do
|
|
290
314
|
end
|
291
315
|
env = env_with_params
|
292
316
|
result = @app.call(env)
|
293
|
-
result[0].
|
294
|
-
result[2].
|
317
|
+
expect(result[0]).to eq(200)
|
318
|
+
expect(result[2]).to eq(["Foo Is A Winna"])
|
295
319
|
end
|
296
320
|
end
|
297
321
|
end # integrated strategies
|
@@ -299,9 +323,9 @@ describe Warden::Manager do
|
|
299
323
|
it "should allow me to set a different default scope for warden" do
|
300
324
|
Rack::Builder.new do
|
301
325
|
use Warden::Manager, :default_scope => :default do |manager|
|
302
|
-
manager.default_scope.
|
326
|
+
expect(manager.default_scope).to eq(:default)
|
303
327
|
manager.default_scope = :other
|
304
|
-
manager.default_scope.
|
328
|
+
expect(manager.default_scope).to eq(:other)
|
305
329
|
end
|
306
330
|
end
|
307
331
|
end
|
@@ -309,7 +333,7 @@ describe Warden::Manager do
|
|
309
333
|
it "should allow me to access strategies through manager" do
|
310
334
|
Rack::Builder.new do
|
311
335
|
use Warden::Manager do |manager|
|
312
|
-
manager.strategies.
|
336
|
+
expect(manager.strategies).to eq(Warden::Strategies)
|
313
337
|
end
|
314
338
|
end
|
315
339
|
end
|