warden 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +8 -0
- data/lib/warden/hooks.rb +27 -1
- data/lib/warden/proxy.rb +1 -0
- data/lib/warden/test/helpers.rb +35 -0
- data/lib/warden/test/warden_helpers.rb +29 -0
- data/lib/warden/version.rb +1 -1
- data/lib/warden.rb +29 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/warden/authenticated_data_store_spec.rb +1 -1
- data/spec/warden/config_spec.rb +1 -1
- data/spec/warden/errors_spec.rb +9 -9
- data/spec/warden/hooks_spec.rb +46 -1
- data/spec/warden/manager_spec.rb +2 -2
- data/spec/warden/proxy_spec.rb +1 -1
- data/spec/warden/session_serializer_spec.rb +3 -3
- data/spec/warden/strategies/base_spec.rb +32 -32
- data/spec/warden/strategies_spec.rb +5 -5
- data/spec/warden/test/helpers_spec.rb +90 -0
- data/spec/warden/test/test_mode_spec.rb +67 -0
- data/warden.gemspec +9 -3
- metadata +34 -13
data/History.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== Version 0.9.5 / 2010-02-28
|
2
|
+
|
3
|
+
* Add Warden.test_mode!
|
4
|
+
* Add Warden.on_next_request
|
5
|
+
* Add test helpers in Warden::Test::Helpers
|
6
|
+
** login_as
|
7
|
+
** logout
|
8
|
+
|
1
9
|
== Version 0.9.4 / 2010-02-23
|
2
10
|
|
3
11
|
* Fix an issue where winning_strategy was not cleaned, allowing multiple scopes to sign in, even when the second one should not
|
data/lib/warden/hooks.rb
CHANGED
@@ -145,8 +145,34 @@ module Warden
|
|
145
145
|
@_before_logout ||= []
|
146
146
|
end
|
147
147
|
|
148
|
+
# A callback that runs on each request, just after the proxy is initialized
|
149
|
+
#
|
150
|
+
# Parameters:
|
151
|
+
# <block> A block to contain logic for the callback
|
152
|
+
# Block Parameters: |proxy|
|
153
|
+
# proxy - The warden proxy object for the request
|
154
|
+
#
|
155
|
+
# Example:
|
156
|
+
# user = "A User"
|
157
|
+
# Warden::Manager.on_request do |proxy|
|
158
|
+
# proxy.set_user = user
|
159
|
+
# end
|
160
|
+
#
|
161
|
+
# :api: public
|
162
|
+
def on_request(options = {}, method = :push, &block)
|
163
|
+
raise BlockNotGiven unless block_given?
|
164
|
+
_on_request.send(method, [block, options])
|
165
|
+
end
|
166
|
+
|
167
|
+
# Provides access to the callback array for before_logout
|
168
|
+
# :api: private
|
169
|
+
def _on_request
|
170
|
+
@_on_request ||= []
|
171
|
+
end
|
172
|
+
|
173
|
+
|
148
174
|
# Add prepend filters version
|
149
|
-
%w(after_set_user after_authentication after_fetch
|
175
|
+
%w(after_set_user after_authentication after_fetch on_request
|
150
176
|
before_failure before_logout).each do |filter|
|
151
177
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
152
178
|
def prepend_#{filter}(options={}, &block)
|
data/lib/warden/proxy.rb
CHANGED
@@ -22,6 +22,7 @@ module Warden
|
|
22
22
|
@strategies = Hash.new { |h,k| h[k] = {} }
|
23
23
|
@manager, @config = manager, manager.config
|
24
24
|
errors # setup the error object in the session
|
25
|
+
manager._run_callbacks(:on_request, self)
|
25
26
|
end
|
26
27
|
|
27
28
|
# Points to a SessionSerializer instance responsible for handling
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Warden
|
4
|
+
module Test
|
5
|
+
# A collection of test helpers for testing full stack rack applications using Warden
|
6
|
+
# These provide the ability to login and logout on any given request
|
7
|
+
# Note: During the teardown phase of your specs you should include: Warden.test_reset!
|
8
|
+
module Helpers
|
9
|
+
def self.included(base)
|
10
|
+
::Warden.test_mode!
|
11
|
+
end
|
12
|
+
|
13
|
+
# A helper method that will peform a login of a user in warden for the next request
|
14
|
+
# Provide it the same options as you would to Warden::Proxy#set_user
|
15
|
+
# @see Warden::Proxy#set_user
|
16
|
+
# @api public
|
17
|
+
def login_as(user, opts = {})
|
18
|
+
Warden.on_next_request do |proxy|
|
19
|
+
proxy.set_user(user, opts)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Logs out a user from the session.
|
24
|
+
# Without arguments, all users will be logged out
|
25
|
+
# Provide a list of scopes to only log out users with that scope.
|
26
|
+
# @see Warden::Proxy#logout
|
27
|
+
# @api public
|
28
|
+
def logout(*scopes)
|
29
|
+
Warden.on_next_request do |proxy|
|
30
|
+
proxy.logout(*scopes)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Warden
|
4
|
+
|
5
|
+
module Test
|
6
|
+
module WardenHelpers
|
7
|
+
# Adds a block to be executed on the next request when the stack reaches warden.
|
8
|
+
# The warden proxy is yielded to the block
|
9
|
+
# @api public
|
10
|
+
def on_next_request(&blk)
|
11
|
+
_on_next_request << blk
|
12
|
+
end
|
13
|
+
|
14
|
+
# resets wardens tests
|
15
|
+
# any blocks queued to execute will be removed
|
16
|
+
# @api public
|
17
|
+
def test_reset!
|
18
|
+
_on_next_request.clear
|
19
|
+
end
|
20
|
+
|
21
|
+
# A containter for the on_next_request items.
|
22
|
+
# @api private
|
23
|
+
def _on_next_request
|
24
|
+
@_on_next_request ||= []
|
25
|
+
@_on_next_request
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/warden/version.rb
CHANGED
data/lib/warden.rb
CHANGED
@@ -11,4 +11,33 @@ require 'warden/strategies/base'
|
|
11
11
|
|
12
12
|
module Warden
|
13
13
|
class NotAuthenticated < StandardError; end
|
14
|
+
|
15
|
+
module Test
|
16
|
+
autoload :WardenHelpers, 'warden/test/warden_helpers'
|
17
|
+
autoload :Helpers, 'warden/test/helpers'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Provides helper methods to warden for testing.
|
21
|
+
#
|
22
|
+
# To setup warden in test mode call the +test_mode!+ method on warden
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# Warden.test_mode!
|
26
|
+
#
|
27
|
+
# This will provide a number of methods.
|
28
|
+
# Warden.on_next_request(&blk) - captures a block which is yielded the warden proxy on the next request
|
29
|
+
# Warden.test_reset! - removes any captured blocks that would have been executed on the next request
|
30
|
+
#
|
31
|
+
# Warden.test_reset! should be called in after blocks for rspec, or teardown methods for Test::Unit
|
32
|
+
def self.test_mode!
|
33
|
+
unless Warden::Test::WardenHelpers === Warden
|
34
|
+
Warden.extend Warden::Test::WardenHelpers
|
35
|
+
Warden::Manager.on_request do |proxy|
|
36
|
+
while blk = Warden._on_next_request.shift
|
37
|
+
blk.call(proxy)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
true
|
42
|
+
end
|
14
43
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/warden/config_spec.rb
CHANGED
data/spec/warden/errors_spec.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Warden::Proxy::Errors do
|
5
|
-
|
5
|
+
|
6
6
|
before(:each) do
|
7
7
|
@errors = Warden::Proxy::Errors.new
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should report that it is empty on first creation" do
|
11
11
|
@errors.empty?.should == true
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should continue to report that it is empty even after being checked" do
|
15
15
|
@errors.on(:foo)
|
16
16
|
@errors.empty?.should == true
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "should add an error" do
|
20
20
|
@errors.add(:login, "Login or password incorrect")
|
21
21
|
@errors[:login].should == ["Login or password incorrect"]
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "should allow many errors to be added to the same field" do
|
25
25
|
@errors.add(:login, "bad 1")
|
26
26
|
@errors.add(:login, "bad 2")
|
27
27
|
@errors.on(:login).should == ["bad 1", "bad 2"]
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should give the full messages for an error" do
|
31
31
|
@errors.add(:login, "login wrong")
|
32
32
|
@errors.add(:password, "password wrong")
|
@@ -34,12 +34,12 @@ describe Warden::Proxy::Errors do
|
|
34
34
|
@errors.full_messages.should include(msg)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should return the error for a specific field / label" do
|
39
39
|
@errors.add(:login, "wrong")
|
40
40
|
@errors.on(:login).should == ["wrong"]
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should return nil for a specific field if it's not been set" do
|
44
44
|
@errors.on(:not_there).should be_nil
|
45
45
|
end
|
data/spec/warden/hooks_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe "standard authentication hooks" do
|
5
5
|
|
@@ -285,4 +285,49 @@ describe "standard authentication hooks" do
|
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
|
+
describe "on_request" do
|
289
|
+
before(:each) do
|
290
|
+
@old_on_request = RAM._on_request.dup
|
291
|
+
RAM = Warden::Manager unless defined?(RAM)
|
292
|
+
RAM._on_request.clear
|
293
|
+
end
|
294
|
+
|
295
|
+
after(:each) do
|
296
|
+
RAM._on_request.clear
|
297
|
+
RAM._on_request.replace(@old_on_request)
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should allow me to add an on_request hook" do
|
301
|
+
RAM.on_request{|proxy| "foo"}
|
302
|
+
RAM._on_request.should have(1).item
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should allow me to add multiple on_request hooks" do
|
306
|
+
RAM.on_request{|proxy| "foo"}
|
307
|
+
RAM.on_request{|proxy| "bar"}
|
308
|
+
RAM._on_request.should have(2).items
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should run each on_request hooks when initializing" do
|
312
|
+
RAM.on_request{|proxy| proxy.env['warden.spec.on_request.foo'] = "foo"}
|
313
|
+
RAM.on_request{|proxy| proxy.env['warden.spec.on_request.bar'] = "bar"}
|
314
|
+
app = lambda{|e| valid_response}
|
315
|
+
env = env_with_params
|
316
|
+
setup_rack(app).call(env)
|
317
|
+
env['warden.spec.on_request.foo'].should == "foo"
|
318
|
+
env['warden.spec.on_request.bar'].should == "bar"
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should run filters in the given order" do
|
322
|
+
RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 2}
|
323
|
+
RAM.on_request{|proxy| proxy.env['warden.spec.order'] << 3}
|
324
|
+
RAM.prepend_on_request{|proxy| proxy.env['warden.spec.order'] << 1}
|
325
|
+
app = lambda do |e|
|
326
|
+
valid_response
|
327
|
+
end
|
328
|
+
env = Rack::MockRequest.env_for("/", "warden.spec.order" => [])
|
329
|
+
setup_rack(app).call(env)
|
330
|
+
env['warden.spec.order'].should == [1,2,3]
|
331
|
+
end
|
332
|
+
end
|
288
333
|
end
|
data/spec/warden/manager_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Warden::Manager do
|
5
5
|
|
@@ -208,7 +208,7 @@ describe Warden::Manager do
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end # integrated strategies
|
211
|
-
|
211
|
+
|
212
212
|
it "should allow me to set a different default scope for warden" do
|
213
213
|
Rack::Builder.new do
|
214
214
|
use Warden::Manager, :default_scope => :default do |manager|
|
data/spec/warden/proxy_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Warden::SessionSerializer do
|
5
5
|
before(:each) do
|
@@ -12,7 +12,7 @@ describe Warden::SessionSerializer do
|
|
12
12
|
@session.store("user", :default)
|
13
13
|
@env['rack.session'].should == { "warden.user.default.key"=>"user" }
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "should check if a data is stored or not" do
|
17
17
|
@session.should_not be_stored(:default)
|
18
18
|
@session.store("user", :default)
|
@@ -41,7 +41,7 @@ describe Warden::SessionSerializer do
|
|
41
41
|
it "should delete information from store if user cannot be retrieved" do
|
42
42
|
@session.store("user", :default)
|
43
43
|
@env['rack.session'].should have_key("warden.user.default.key")
|
44
|
-
@session.instance_eval "def deserialize(key); nil; end"
|
44
|
+
@session.instance_eval "def deserialize(key); nil; end"
|
45
45
|
@session.fetch(:default)
|
46
46
|
@env['rack.session'].should_not have_key("warden.user.default.key")
|
47
47
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Warden::Strategies::Base do
|
5
5
|
|
@@ -7,7 +7,7 @@ describe Warden::Strategies::Base do
|
|
7
7
|
RAS = Warden::Strategies unless defined?(RAS)
|
8
8
|
Warden::Strategies.clear!
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
describe "headers" do
|
12
12
|
it "should have headers" do
|
13
13
|
Warden::Strategies.add(:foo) do
|
@@ -19,7 +19,7 @@ describe Warden::Strategies::Base do
|
|
19
19
|
strategy._run!
|
20
20
|
strategy.headers["foo"].should == "bar"
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it "should allow us to clear the headers" do
|
24
24
|
Warden::Strategies.add(:foo) do
|
25
25
|
def authenticate!
|
@@ -33,7 +33,7 @@ describe Warden::Strategies::Base do
|
|
33
33
|
strategy.headers.should be_empty
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should have a user object" do
|
38
38
|
RAS.add(:foobar) do
|
39
39
|
def authenticate!
|
@@ -65,7 +65,7 @@ describe Warden::Strategies::Base do
|
|
65
65
|
end
|
66
66
|
strategy = RAS[:foobar].new(env_with_params, :user)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "should allow you to set a message" do
|
70
70
|
RAS.add(:foobar) do
|
71
71
|
def authenticate!
|
@@ -76,7 +76,7 @@ describe Warden::Strategies::Base do
|
|
76
76
|
strategy._run!
|
77
77
|
strategy.message.should == "foo message"
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it "should provide access to the errors" do
|
81
81
|
RAS.add(:foobar) do
|
82
82
|
def authenticate!
|
@@ -89,7 +89,7 @@ describe Warden::Strategies::Base do
|
|
89
89
|
strategy._run!
|
90
90
|
strategy.errors.on(:foo).should == ["foo has an error"]
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
describe "halting" do
|
94
94
|
it "should allow you to halt a strategy" do
|
95
95
|
RAS.add(:foobar) do
|
@@ -101,7 +101,7 @@ describe Warden::Strategies::Base do
|
|
101
101
|
str._run!
|
102
102
|
str.should be_halted
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it "should not be halted if halt was not called" do
|
106
106
|
RAS.add(:foobar) do
|
107
107
|
def authenticate!
|
@@ -114,7 +114,7 @@ describe Warden::Strategies::Base do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
describe "pass" do
|
119
119
|
it "should allow you to pass" do
|
120
120
|
RAS.add(:foobar) do
|
@@ -128,7 +128,7 @@ describe Warden::Strategies::Base do
|
|
128
128
|
str.user.should be_nil
|
129
129
|
end
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
describe "redirect" do
|
133
133
|
it "should allow you to set a redirection" do
|
134
134
|
RAS.add(:foobar) do
|
@@ -140,7 +140,7 @@ describe Warden::Strategies::Base do
|
|
140
140
|
str._run!
|
141
141
|
str.user.should be_nil
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it "should mark the strategy as halted when redirecting" do
|
145
145
|
RAS.add(:foobar) do
|
146
146
|
def authenticate!
|
@@ -151,7 +151,7 @@ describe Warden::Strategies::Base do
|
|
151
151
|
str._run!
|
152
152
|
str.should be_halted
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
it "should escape redirected url parameters" do
|
156
156
|
RAS.add(:foobar) do
|
157
157
|
def authenticate!
|
@@ -162,7 +162,7 @@ describe Warden::Strategies::Base do
|
|
162
162
|
str._run!
|
163
163
|
str.headers["Location"].should == "/foo/bar?foo=bar"
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
it "should allow you to set a message" do
|
167
167
|
RAS.add(:foobar) do
|
168
168
|
def authenticate!
|
@@ -174,7 +174,7 @@ describe Warden::Strategies::Base do
|
|
174
174
|
str.headers["Location"].should == "/foo/bar?foo=bar"
|
175
175
|
str.message.should == "You are being redirected foo"
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
it "should set the action as :redirect" do
|
179
179
|
RAS.add(:foobar) do
|
180
180
|
def authenticate!
|
@@ -186,9 +186,9 @@ describe Warden::Strategies::Base do
|
|
186
186
|
str.result.should == :redirect
|
187
187
|
end
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
describe "failure" do
|
191
|
-
|
191
|
+
|
192
192
|
before(:each) do
|
193
193
|
RAS.add(:foobar) do
|
194
194
|
def authenticate!
|
@@ -197,28 +197,28 @@ describe Warden::Strategies::Base do
|
|
197
197
|
end
|
198
198
|
@str = RAS[:foobar].new(env_with_params)
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
it "should allow you to fail" do
|
202
202
|
@str._run!
|
203
203
|
@str.user.should be_nil
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
it "should halt the strategies when failing" do
|
207
207
|
@str._run!
|
208
208
|
@str.should be_halted
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
it "should allow you to set a message when failing" do
|
212
212
|
@str._run!
|
213
213
|
@str.message.should == "You are not cool enough"
|
214
214
|
end
|
215
|
-
|
215
|
+
|
216
216
|
it "should set the action as :failure" do
|
217
217
|
@str._run!
|
218
218
|
@str.result.should == :failure
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
describe "success" do
|
223
223
|
before(:each) do
|
224
224
|
RAS.add(:foobar) do
|
@@ -228,32 +228,32 @@ describe Warden::Strategies::Base do
|
|
228
228
|
end
|
229
229
|
@str = RAS[:foobar].new(env_with_params)
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
it "should allow you to succeed" do
|
233
233
|
@str._run!
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
it "should be authenticated after success" do
|
237
237
|
@str._run!
|
238
238
|
@str.user.should_not be_nil
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
it "should allow you to set a message when succeeding" do
|
242
242
|
@str._run!
|
243
243
|
@str.message.should == "Welcome to the club!"
|
244
244
|
end
|
245
|
-
|
245
|
+
|
246
246
|
it "should store the user" do
|
247
247
|
@str._run!
|
248
248
|
@str.user.should == "Foo User"
|
249
249
|
end
|
250
|
-
|
250
|
+
|
251
251
|
it "should set the action as :success" do
|
252
252
|
@str._run!
|
253
253
|
@str.result.should == :success
|
254
|
-
end
|
254
|
+
end
|
255
255
|
end
|
256
|
-
|
256
|
+
|
257
257
|
describe "custom response" do
|
258
258
|
before(:each) do
|
259
259
|
RAS.add(:foobar) do
|
@@ -264,19 +264,19 @@ describe Warden::Strategies::Base do
|
|
264
264
|
@str = RAS[:foobar].new(env_with_params)
|
265
265
|
@str._run!
|
266
266
|
end
|
267
|
-
|
267
|
+
|
268
268
|
it "should allow me to set a custom rack response" do
|
269
269
|
@str.user.should be_nil
|
270
270
|
end
|
271
|
-
|
271
|
+
|
272
272
|
it "should halt the strategy" do
|
273
273
|
@str.should be_halted
|
274
274
|
end
|
275
|
-
|
275
|
+
|
276
276
|
it "should provide access to the custom rack response" do
|
277
277
|
@str.custom_response.should == [521, {"foo" => "bar"}, ["BAD"]]
|
278
278
|
end
|
279
|
-
|
279
|
+
|
280
280
|
it "should set the action as :custom" do
|
281
281
|
@str._run!
|
282
282
|
@str.result.should == :custom
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Warden::Strategies do
|
5
5
|
it "should let me add a strategy via a block" do
|
@@ -10,14 +10,14 @@ describe Warden::Strategies do
|
|
10
10
|
end
|
11
11
|
Warden::Strategies[:strategy1].ancestors.should include(Warden::Strategies::Base)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should raise an error if I add a strategy via a block, that does not have an autheniticate! method" do
|
15
15
|
lambda do
|
16
16
|
Warden::Strategies.add(:strategy2) do
|
17
17
|
end
|
18
18
|
end.should raise_error
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should allow me to get access to a particular strategy" do
|
22
22
|
Warden::Strategies.add(:strategy3) do
|
23
23
|
def authenticate!; end
|
@@ -26,7 +26,7 @@ describe Warden::Strategies do
|
|
26
26
|
strategy.should_not be_nil
|
27
27
|
strategy.ancestors.should include(Warden::Strategies::Base)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should allow me to add a strategy with the required methods" do
|
31
31
|
class MyStrategy < Warden::Strategies::Base
|
32
32
|
def authenticate!; end
|
@@ -35,7 +35,7 @@ describe Warden::Strategies do
|
|
35
35
|
Warden::Strategies.add(:strategy4, MyStrategy)
|
36
36
|
end.should_not raise_error
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should not allow a strategy that does not have an authenticate! method" do
|
40
40
|
class MyOtherStrategy
|
41
41
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Warden::Test::Helpers do
|
5
|
+
include Warden::Test::Helpers
|
6
|
+
|
7
|
+
before{ $captures = [] }
|
8
|
+
after{ Warden.test_reset! }
|
9
|
+
|
10
|
+
it "should log me in as a user" do
|
11
|
+
user = "A User"
|
12
|
+
login_as user
|
13
|
+
app = lambda{|e|
|
14
|
+
$captures << :run
|
15
|
+
e['warden'].should be_authenticated
|
16
|
+
e['warden'].user.should == "A User"
|
17
|
+
valid_response
|
18
|
+
}
|
19
|
+
setup_rack(app).call(env_with_params)
|
20
|
+
$captures.should == [:run]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should log me in as a user of a given scope" do
|
24
|
+
user = {:some => "user"}
|
25
|
+
login_as user, :scope => :foo_scope
|
26
|
+
app = lambda{|e|
|
27
|
+
$captures << :run
|
28
|
+
w = e['warden']
|
29
|
+
w.should be_authenticated(:foo_scope)
|
30
|
+
w.user(:foo_scope).should == {:some => "user"}
|
31
|
+
}
|
32
|
+
setup_rack(app).call(env_with_params)
|
33
|
+
$captures.should == [:run]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should login multiple users with different scopes" do
|
37
|
+
user = "A user"
|
38
|
+
foo_user = "A foo user"
|
39
|
+
login_as user
|
40
|
+
login_as foo_user, :scope => :foo
|
41
|
+
app = lambda{|e|
|
42
|
+
$captures << :run
|
43
|
+
w = e['warden']
|
44
|
+
w.user.should == "A user"
|
45
|
+
w.user(:foo).should == "A foo user"
|
46
|
+
w.should be_authenticated
|
47
|
+
w.should be_authenticated(:foo)
|
48
|
+
}
|
49
|
+
setup_rack(app).call(env_with_params)
|
50
|
+
$captures.should == [:run]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should log out all users" do
|
54
|
+
user = "A user"
|
55
|
+
foo = "Foo"
|
56
|
+
login_as user
|
57
|
+
login_as foo, :scope => :foo
|
58
|
+
app = lambda{|e|
|
59
|
+
$captures << :run
|
60
|
+
w = e['warden']
|
61
|
+
w.user.should == "A user"
|
62
|
+
w.user(:foo).should == "Foo"
|
63
|
+
w.logout
|
64
|
+
w.user.should be_nil
|
65
|
+
w.user(:foo).should be_nil
|
66
|
+
w.should_not be_authenticated
|
67
|
+
w.should_not be_authenticated(:foo)
|
68
|
+
}
|
69
|
+
setup_rack(app).call(env_with_params)
|
70
|
+
$captures.should == [:run]
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should logout a specific user" do
|
74
|
+
user = "A User"
|
75
|
+
foo = "Foo"
|
76
|
+
login_as user
|
77
|
+
login_as foo, :scope => :foo
|
78
|
+
app = lambda{|e|
|
79
|
+
$captures << :run
|
80
|
+
w = e['warden']
|
81
|
+
w.logout :foo
|
82
|
+
w.user.should == "A User"
|
83
|
+
w.user(:foo).should be_nil
|
84
|
+
w.should_not be_authenticated(:foo)
|
85
|
+
}
|
86
|
+
setup_rack(app).call(env_with_params)
|
87
|
+
$captures.should == [:run]
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Warden::Test::WardenHelpers do
|
5
|
+
before :all do
|
6
|
+
Warden.test_mode!
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
$captures = []
|
11
|
+
@app = lambda{|e| valid_response }
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
Warden.test_reset!
|
16
|
+
end
|
17
|
+
|
18
|
+
it{ Warden.should respond_to(:test_mode!) }
|
19
|
+
it{ Warden.should respond_to(:on_next_request) }
|
20
|
+
it{ Warden.should respond_to(:test_reset!) }
|
21
|
+
|
22
|
+
it "should execute the on_next_request block on the next request" do
|
23
|
+
Warden.on_next_request do |warden|
|
24
|
+
$captures << warden
|
25
|
+
end
|
26
|
+
|
27
|
+
setup_rack(@app).call(env_with_params)
|
28
|
+
$captures.should have(1).item
|
29
|
+
$captures.first.should be_an_instance_of(Warden::Proxy)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should execute many on_next_request blocks on the next request" do
|
33
|
+
Warden.on_next_request{|w| $captures << :first }
|
34
|
+
Warden.on_next_request{|w| $captures << :second }
|
35
|
+
setup_rack(@app).call(env_with_params)
|
36
|
+
$captures.should have(2).items
|
37
|
+
$captures.should == [:first, :second]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not execute on_next_request blocks on subsequent requests" do
|
41
|
+
app = setup_rack(@app)
|
42
|
+
Warden.on_next_request{|w| $captures << :first }
|
43
|
+
app.call(env_with_params)
|
44
|
+
$captures.should == [:first]
|
45
|
+
$captures.clear
|
46
|
+
app.call(env_with_params)
|
47
|
+
$captures.should be_empty
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should allow me to set new_on_next_request items to execute in the same test" do
|
51
|
+
app = setup_rack(@app)
|
52
|
+
Warden.on_next_request{|w| $captures << :first }
|
53
|
+
app.call(env_with_params)
|
54
|
+
$captures.should == [:first]
|
55
|
+
Warden.on_next_request{|w| $captures << :second }
|
56
|
+
app.call(env_with_params)
|
57
|
+
$captures.should == [:first, :second]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should remove the on_next_request items when test is reset" do
|
61
|
+
app = setup_rack(@app)
|
62
|
+
Warden.on_next_request{|w| $captures << :first }
|
63
|
+
Warden.test_reset!
|
64
|
+
app.call(env_with_params)
|
65
|
+
$captures.should == []
|
66
|
+
end
|
67
|
+
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.5"
|
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-
|
12
|
+
s.date = %q{2010-03-01}
|
13
13
|
s.email = %q{has.sox@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -33,6 +33,8 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/warden/session_serializer.rb",
|
34
34
|
"lib/warden/strategies.rb",
|
35
35
|
"lib/warden/strategies/base.rb",
|
36
|
+
"lib/warden/test/helpers.rb",
|
37
|
+
"lib/warden/test/warden_helpers.rb",
|
36
38
|
"lib/warden/version.rb",
|
37
39
|
"script/destroy",
|
38
40
|
"script/generate",
|
@@ -52,6 +54,8 @@ Gem::Specification.new do |s|
|
|
52
54
|
"spec/warden/session_serializer_spec.rb",
|
53
55
|
"spec/warden/strategies/base_spec.rb",
|
54
56
|
"spec/warden/strategies_spec.rb",
|
57
|
+
"spec/warden/test/helpers_spec.rb",
|
58
|
+
"spec/warden/test/test_mode_spec.rb",
|
55
59
|
"spec/warden_spec.rb",
|
56
60
|
"warden.gemspec"
|
57
61
|
]
|
@@ -59,7 +63,7 @@ Gem::Specification.new do |s|
|
|
59
63
|
s.rdoc_options = ["--charset=UTF-8"]
|
60
64
|
s.require_paths = ["lib"]
|
61
65
|
s.rubyforge_project = %q{warden}
|
62
|
-
s.rubygems_version = %q{1.3.
|
66
|
+
s.rubygems_version = %q{1.3.6}
|
63
67
|
s.summary = %q{Rack middleware that provides authentication for rack applications}
|
64
68
|
s.test_files = [
|
65
69
|
"spec/helpers/request_helper.rb",
|
@@ -78,6 +82,8 @@ Gem::Specification.new do |s|
|
|
78
82
|
"spec/warden/session_serializer_spec.rb",
|
79
83
|
"spec/warden/strategies/base_spec.rb",
|
80
84
|
"spec/warden/strategies_spec.rb",
|
85
|
+
"spec/warden/test/helpers_spec.rb",
|
86
|
+
"spec/warden/test/test_mode_spec.rb",
|
81
87
|
"spec/warden_spec.rb"
|
82
88
|
]
|
83
89
|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warden
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 5
|
9
|
+
version: 0.9.5
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Daniel Neighman
|
@@ -9,29 +14,37 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-01 00:00:00 +11:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rack
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
23
31
|
version: 1.0.0
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: rspec
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 0
|
44
|
+
- 0
|
33
45
|
version: 1.0.0
|
34
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
35
48
|
description:
|
36
49
|
email: has.sox@gmail.com
|
37
50
|
executables: []
|
@@ -59,6 +72,8 @@ files:
|
|
59
72
|
- lib/warden/session_serializer.rb
|
60
73
|
- lib/warden/strategies.rb
|
61
74
|
- lib/warden/strategies/base.rb
|
75
|
+
- lib/warden/test/helpers.rb
|
76
|
+
- lib/warden/test/warden_helpers.rb
|
62
77
|
- lib/warden/version.rb
|
63
78
|
- script/destroy
|
64
79
|
- script/generate
|
@@ -78,6 +93,8 @@ files:
|
|
78
93
|
- spec/warden/session_serializer_spec.rb
|
79
94
|
- spec/warden/strategies/base_spec.rb
|
80
95
|
- spec/warden/strategies_spec.rb
|
96
|
+
- spec/warden/test/helpers_spec.rb
|
97
|
+
- spec/warden/test/test_mode_spec.rb
|
81
98
|
- spec/warden_spec.rb
|
82
99
|
- warden.gemspec
|
83
100
|
has_rdoc: true
|
@@ -93,18 +110,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
110
|
requirements:
|
94
111
|
- - ">="
|
95
112
|
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 0
|
96
115
|
version: "0"
|
97
|
-
version:
|
98
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
117
|
requirements:
|
100
118
|
- - ">="
|
101
119
|
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 0
|
102
122
|
version: "0"
|
103
|
-
version:
|
104
123
|
requirements: []
|
105
124
|
|
106
125
|
rubyforge_project: warden
|
107
|
-
rubygems_version: 1.3.
|
126
|
+
rubygems_version: 1.3.6
|
108
127
|
signing_key:
|
109
128
|
specification_version: 3
|
110
129
|
summary: Rack middleware that provides authentication for rack applications
|
@@ -125,4 +144,6 @@ test_files:
|
|
125
144
|
- spec/warden/session_serializer_spec.rb
|
126
145
|
- spec/warden/strategies/base_spec.rb
|
127
146
|
- spec/warden/strategies_spec.rb
|
147
|
+
- spec/warden/test/helpers_spec.rb
|
148
|
+
- spec/warden/test/test_mode_spec.rb
|
128
149
|
- spec/warden_spec.rb
|