warden 0.9.2 → 0.9.3
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/History.rdoc +16 -0
- data/lib/warden/hooks.rb +20 -11
- data/lib/warden/version.rb +1 -1
- data/spec/warden/hooks_spec.rb +76 -1
- data/warden.gemspec +2 -2
- metadata +2 -2
data/History.rdoc
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
== Version 0.9.3 / 2010-02-17
|
2
|
+
|
3
|
+
* Add prepend_ to all hooks (josevalim)
|
4
|
+
|
5
|
+
== Version 0.9.2 / 2010-02-10
|
6
|
+
|
7
|
+
* Ruby 1.9 compatibility changes (grimen)
|
8
|
+
|
9
|
+
== Version 0.9.1 / 2010-02-09
|
10
|
+
|
11
|
+
* Support for passing a custom message with Warden::Strategy::Base#success! as second optional (grimen)
|
12
|
+
|
13
|
+
== Version 0.9.0 / 2010-01-21
|
14
|
+
|
15
|
+
* Remove serializers and make strategies more powerful, including cache behavior (josevalim)
|
16
|
+
|
1
17
|
== Version 0.8.1 / 2010-01-06
|
2
18
|
|
3
19
|
* Fix a bug when silence missing serializers is set (josevalim)
|
data/lib/warden/hooks.rb
CHANGED
@@ -4,7 +4,7 @@ module Warden
|
|
4
4
|
|
5
5
|
# Hook to _run_callbacks asserting for conditions.
|
6
6
|
def _run_callbacks(kind, *args) #:nodoc:
|
7
|
-
options = args.last # Last callback
|
7
|
+
options = args.last # Last callback arg MUST be a Hash
|
8
8
|
|
9
9
|
send("_#{kind}").each do |callback, conditions|
|
10
10
|
invalid = conditions.find do |key, value|
|
@@ -49,7 +49,7 @@ module Warden
|
|
49
49
|
# end
|
50
50
|
#
|
51
51
|
# :api: public
|
52
|
-
def after_set_user(options={}, &block)
|
52
|
+
def after_set_user(options = {}, method = :push, &block)
|
53
53
|
raise BlockNotGiven unless block_given?
|
54
54
|
|
55
55
|
if options.key?(:only)
|
@@ -58,7 +58,7 @@ module Warden
|
|
58
58
|
options[:event] = [:set_user, :authentication, :fetch] - Array(options.delete(:except))
|
59
59
|
end
|
60
60
|
|
61
|
-
_after_set_user
|
61
|
+
_after_set_user.send(method, [block, options])
|
62
62
|
end
|
63
63
|
|
64
64
|
# Provides access to the array of after_set_user blocks to run
|
@@ -72,8 +72,8 @@ module Warden
|
|
72
72
|
# are the same as in after_set_user.
|
73
73
|
#
|
74
74
|
# :api: public
|
75
|
-
def after_authentication(options={}, &block)
|
76
|
-
after_set_user(options.merge(:event => :authentication), &block)
|
75
|
+
def after_authentication(options = {}, method = :push, &block)
|
76
|
+
after_set_user(options.merge(:event => :authentication), method, &block)
|
77
77
|
end
|
78
78
|
|
79
79
|
# after_fetch is just a wrapper to after_set_user, which is only invoked
|
@@ -81,8 +81,8 @@ module Warden
|
|
81
81
|
# are the same as in after_set_user.
|
82
82
|
#
|
83
83
|
# :api: public
|
84
|
-
def after_fetch(options={}, &block)
|
85
|
-
after_set_user(options.merge(:event => :fetch), &block)
|
84
|
+
def after_fetch(options = {}, method = :push, &block)
|
85
|
+
after_set_user(options.merge(:event => :fetch), method, &block)
|
86
86
|
end
|
87
87
|
|
88
88
|
# A callback that runs just prior to the failur application being called.
|
@@ -106,9 +106,9 @@ module Warden
|
|
106
106
|
# end
|
107
107
|
#
|
108
108
|
# :api: public
|
109
|
-
def before_failure(options={}, &block)
|
109
|
+
def before_failure(options = {}, method = :push, &block)
|
110
110
|
raise BlockNotGiven unless block_given?
|
111
|
-
_before_failure
|
111
|
+
_before_failure.send(method, [block, options])
|
112
112
|
end
|
113
113
|
|
114
114
|
# Provides access to the callback array for before_failure
|
@@ -134,9 +134,9 @@ module Warden
|
|
134
134
|
# end
|
135
135
|
#
|
136
136
|
# :api: public
|
137
|
-
def before_logout(options={}, &block)
|
137
|
+
def before_logout(options = {}, method = :push, &block)
|
138
138
|
raise BlockNotGiven unless block_given?
|
139
|
-
_before_logout
|
139
|
+
_before_logout.send(method, [block, options])
|
140
140
|
end
|
141
141
|
|
142
142
|
# Provides access to the callback array for before_logout
|
@@ -145,5 +145,14 @@ module Warden
|
|
145
145
|
@_before_logout ||= []
|
146
146
|
end
|
147
147
|
|
148
|
+
# Add prepend filters version
|
149
|
+
%w(after_set_user after_authentication after_fetch
|
150
|
+
before_failure before_logout).each do |filter|
|
151
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
152
|
+
def prepend_#{filter}(options={}, &block)
|
153
|
+
#{filter}(options, :unshift, &block)
|
154
|
+
end
|
155
|
+
METHOD
|
156
|
+
end
|
148
157
|
end # Hooks
|
149
158
|
end # Warden
|
data/lib/warden/version.rb
CHANGED
data/spec/warden/hooks_spec.rb
CHANGED
@@ -65,12 +65,29 @@ describe "standard authentication hooks" do
|
|
65
65
|
setup_rack(app).call(env)
|
66
66
|
end
|
67
67
|
|
68
|
+
it "should run filters in the given order" do
|
69
|
+
RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 2}
|
70
|
+
RAM.after_set_user{|u,a,o| a.env['warden.spec.order'] << 3}
|
71
|
+
RAM.prepend_after_set_user{|u,a,o| a.env['warden.spec.order'] << 1}
|
72
|
+
app = lambda do |e|
|
73
|
+
e['warden.spec.order'] = []
|
74
|
+
e['warden'].set_user("foo")
|
75
|
+
valid_response
|
76
|
+
end
|
77
|
+
env = env_with_params
|
78
|
+
setup_rack(app).call(env)
|
79
|
+
env['warden.spec.order'].should == [1,2,3]
|
80
|
+
end
|
81
|
+
|
68
82
|
context "after_authentication" do
|
69
83
|
it "should be a wrapper to after_set_user behavior" do
|
70
84
|
RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.baz'] = "run baz"}
|
71
85
|
RAM.after_authentication{|u,a,o| a.env['warden.spec.hook.paz'] = "run paz"}
|
72
86
|
RAM.after_authentication{|u,a,o| o[:event].should == :authentication }
|
73
|
-
app = lambda
|
87
|
+
app = lambda do |e|
|
88
|
+
e['warden'].authenticate(:pass)
|
89
|
+
valid_response
|
90
|
+
end
|
74
91
|
env = env_with_params
|
75
92
|
setup_rack(app).call(env)
|
76
93
|
env['warden.spec.hook.baz'].should == 'run baz'
|
@@ -86,6 +103,20 @@ describe "standard authentication hooks" do
|
|
86
103
|
env = env_with_params
|
87
104
|
setup_rack(app).call(env)
|
88
105
|
end
|
106
|
+
|
107
|
+
it "should run filters in the given order" do
|
108
|
+
RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 2}
|
109
|
+
RAM.after_authentication{|u,a,o| a.env['warden.spec.order'] << 3}
|
110
|
+
RAM.prepend_after_authentication{|u,a,o| a.env['warden.spec.order'] << 1}
|
111
|
+
app = lambda do |e|
|
112
|
+
e['warden.spec.order'] = []
|
113
|
+
e['warden'].authenticate(:pass)
|
114
|
+
valid_response
|
115
|
+
end
|
116
|
+
env = env_with_params
|
117
|
+
setup_rack(app).call(env)
|
118
|
+
env['warden.spec.order'].should == [1,2,3]
|
119
|
+
end
|
89
120
|
end
|
90
121
|
|
91
122
|
context "after_fetch" do
|
@@ -118,6 +149,21 @@ describe "standard authentication hooks" do
|
|
118
149
|
env['rack.session']['warden.user.default.key'] = nil
|
119
150
|
env['warden'].user.should be_nil
|
120
151
|
end
|
152
|
+
|
153
|
+
it "should run filters in the given order" do
|
154
|
+
RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 2}
|
155
|
+
RAM.after_fetch{|u,a,o| a.env['warden.spec.order'] << 3}
|
156
|
+
RAM.prepend_after_fetch{|u,a,o| a.env['warden.spec.order'] << 1}
|
157
|
+
app = lambda do |e|
|
158
|
+
e['warden.spec.order'] = []
|
159
|
+
e['rack.session']['warden.user.default.key'] = "Foo"
|
160
|
+
e['warden'].user
|
161
|
+
valid_response
|
162
|
+
end
|
163
|
+
env = env_with_params
|
164
|
+
setup_rack(app).call(env)
|
165
|
+
env['warden.spec.order'].should == [1,2,3]
|
166
|
+
end
|
121
167
|
end
|
122
168
|
|
123
169
|
end
|
@@ -152,6 +198,20 @@ describe "standard authentication hooks" do
|
|
152
198
|
env['warden.spec.before_failure.foo'].should == "foo"
|
153
199
|
env['warden.spec.before_failure.bar'].should == "bar"
|
154
200
|
end
|
201
|
+
|
202
|
+
it "should run filters in the given order" do
|
203
|
+
RAM.before_failure{|e,o| e['warden.spec.order'] << 2}
|
204
|
+
RAM.before_failure{|e,o| e['warden.spec.order'] << 3}
|
205
|
+
RAM.prepend_before_failure{|e,o| e['warden.spec.order'] << 1}
|
206
|
+
app = lambda do |e|
|
207
|
+
e['warden.spec.order'] = []
|
208
|
+
e['warden'].authenticate!(:failz)
|
209
|
+
valid_response
|
210
|
+
end
|
211
|
+
env = env_with_params
|
212
|
+
setup_rack(app).call(env)
|
213
|
+
env['warden.spec.order'].should == [1,2,3]
|
214
|
+
end
|
155
215
|
end
|
156
216
|
|
157
217
|
describe "before_logout" do
|
@@ -208,6 +268,21 @@ describe "standard authentication hooks" do
|
|
208
268
|
env['warden.spec.hook.a'].should == [:scope1]
|
209
269
|
env['warden.spec.hook.b'].should == [:scope2]
|
210
270
|
end
|
271
|
+
|
272
|
+
it "should run filters in the given order" do
|
273
|
+
RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 2}
|
274
|
+
RAM.before_logout{|u,a,o| a.env['warden.spec.order'] << 3}
|
275
|
+
RAM.prepend_before_logout{|u,a,o| a.env['warden.spec.order'] << 1}
|
276
|
+
app = lambda do |e|
|
277
|
+
e['warden.spec.order'] = []
|
278
|
+
e['warden'].authenticate(:pass)
|
279
|
+
e['warden'].logout
|
280
|
+
valid_response
|
281
|
+
end
|
282
|
+
env = env_with_params
|
283
|
+
setup_rack(app).call(env)
|
284
|
+
env['warden.spec.order'].should == [1,2,3]
|
285
|
+
end
|
211
286
|
end
|
212
287
|
|
213
288
|
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.3"
|
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-02-
|
12
|
+
s.date = %q{2010-02-17}
|
13
13
|
s.email = %q{has.sox@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warden
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Neighman
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-17 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|