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