warden 0.9.5 → 0.9.6
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.
- data/lib/warden/proxy.rb +17 -1
- data/lib/warden/version.rb +1 -1
- data/spec/warden/proxy_spec.rb +72 -0
- data/warden.gemspec +2 -2
- metadata +3 -3
data/lib/warden/proxy.rb
CHANGED
@@ -60,6 +60,22 @@ module Warden
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
# Provides access to the currently defined default strategies for the proxy.
|
64
|
+
# This can change as it moves throughout the rack graph
|
65
|
+
# Any changes to this are reflected only for the duration of the request
|
66
|
+
# By changing this value, you can change the default strategies for a downstream branch of you rack graph.
|
67
|
+
#
|
68
|
+
# @api public
|
69
|
+
def default_strategies
|
70
|
+
@default_strategies ||= config.default_strategies.dup
|
71
|
+
end
|
72
|
+
|
73
|
+
# Allows you to set the default strategies for this request.
|
74
|
+
# @api public
|
75
|
+
def default_strategies=(*strategies)
|
76
|
+
@default_strategies = strategies.flatten
|
77
|
+
end
|
78
|
+
|
63
79
|
# Run the authentiation strategies for the given strategies.
|
64
80
|
# If there is already a user logged in for a given scope, the strategies are not run
|
65
81
|
# This does not halt the flow of control and is a passive attempt to authenticate only
|
@@ -265,7 +281,7 @@ module Warden
|
|
265
281
|
# Run the strategies for a given scope
|
266
282
|
def _run_strategies_for(scope, args) #:nodoc:
|
267
283
|
self.winning_strategy = nil
|
268
|
-
strategies = args.empty? ?
|
284
|
+
strategies = args.empty? ? default_strategies : args
|
269
285
|
|
270
286
|
strategies.each do |name|
|
271
287
|
strategy = _fetch_strategy(name, scope)
|
data/lib/warden/version.rb
CHANGED
data/spec/warden/proxy_spec.rb
CHANGED
@@ -647,5 +647,77 @@ describe Warden::Proxy do
|
|
647
647
|
app.call(@env)
|
648
648
|
end
|
649
649
|
end
|
650
|
+
end
|
651
|
+
|
652
|
+
describe "dynamic default_strategies" do
|
653
|
+
before(:all) do
|
654
|
+
class ::DynamicDefaultStrategies
|
655
|
+
def initialize(app, &blk)
|
656
|
+
@app, @blk = app, blk
|
657
|
+
end
|
658
|
+
|
659
|
+
def call(env)
|
660
|
+
@blk.call(env)
|
661
|
+
@app.call(env)
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
Warden::Strategies.add(:one) do
|
666
|
+
def authenticate!; $captures << :one; success!("User") end
|
667
|
+
end
|
668
|
+
|
669
|
+
Warden::Strategies.add(:two) do
|
670
|
+
def authenticate!; $captures << :two; fail!("User not found") end
|
671
|
+
end
|
672
|
+
end
|
673
|
+
|
674
|
+
before(:each) do
|
675
|
+
$captures = []
|
676
|
+
@app = lambda{|e| e['warden'].authenticate! }
|
677
|
+
end
|
678
|
+
|
679
|
+
def wrap_app(app, &blk)
|
680
|
+
builder = Rack::Builder.new do
|
681
|
+
use DynamicDefaultStrategies, &blk
|
682
|
+
run app
|
683
|
+
end
|
684
|
+
builder.to_app
|
685
|
+
end
|
686
|
+
|
687
|
+
it "should allow me to change the default strategies on the fly" do
|
688
|
+
app = wrap_app(@app) do |e|
|
689
|
+
e['warden'].default_strategies.should == [:password]
|
690
|
+
e['warden'].config.default_strategies.should == [:password]
|
691
|
+
e['warden'].default_strategies = [:one]
|
692
|
+
e['warden'].authenticate!
|
693
|
+
Rack::Response.new("OK").finish
|
694
|
+
end
|
695
|
+
setup_rack(app).call(env_with_params)
|
696
|
+
|
697
|
+
$captures.should == [:one]
|
698
|
+
end
|
699
|
+
|
700
|
+
it "should allow me to append to the default strategies on the fly" do
|
701
|
+
app = wrap_app(@app) do |e|
|
702
|
+
e['warden'].default_strategies << :one
|
703
|
+
e['warden'].default_strategies.should == [:password, :one]
|
704
|
+
e['warden'].authenticate!
|
705
|
+
Rack::Response.new("OK").finish
|
706
|
+
end
|
707
|
+
setup_rack(app).call(env_with_params)
|
650
708
|
|
709
|
+
$captures.should == [:one]
|
710
|
+
end
|
711
|
+
it "should not change the master configurations strategies when I change them" do
|
712
|
+
app = wrap_app(@app) do |e|
|
713
|
+
e['warden'].default_strategies << :one
|
714
|
+
e['warden'].default_strategies.should == [:password, :one]
|
715
|
+
e['warden'].config.default_strategies.should == [:password]
|
716
|
+
e['warden'].authenticate!
|
717
|
+
Rack::Response.new("OK").finish
|
718
|
+
end
|
719
|
+
setup_rack(app).call(env_with_params)
|
720
|
+
|
721
|
+
$captures.should == [:one]
|
722
|
+
end
|
651
723
|
end
|
data/warden.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{warden}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Neighman"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-04}
|
13
13
|
s.email = %q{has.sox@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 6
|
9
|
+
version: 0.9.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Neighman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-04 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|