warden 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  .DS_Store
2
2
  pkg
3
- .*~
3
+ .*~
4
+
5
+ *.gem
data/lib/warden/config.rb CHANGED
@@ -65,7 +65,7 @@ module Warden
65
65
  scope = opts[:scope] || :_all
66
66
 
67
67
  hash[scope] = strategies.flatten unless strategies.empty?
68
- hash[scope] || hash[:_all] || []
68
+ hash[scope] || hash[:_all]
69
69
  end
70
70
 
71
71
  # A short hand way to set up a particular scope
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'warden/hooks'
3
3
  require 'warden/config'
4
+ require 'warden/manager_deprecation'
4
5
 
5
6
  module Warden
6
7
  # The middleware for Rack Authentication
@@ -9,6 +10,7 @@ module Warden
9
10
  # the rack environment hash
10
11
  class Manager
11
12
  extend Warden::Hooks
13
+ extend Warden::ManagerDeprecation
12
14
 
13
15
  attr_accessor :config
14
16
 
@@ -28,7 +30,7 @@ module Warden
28
30
  # If this is downstream from another warden instance, don't do anything.
29
31
  # :api: private
30
32
  def call(env) # :nodoc:
31
- return @app.call(env) if env['warden'] && env['warden'].manager != self
33
+ return @app.call(env) unless env['warden'].nil? || env['warden'].manager == self
32
34
 
33
35
  env['warden'] = Proxy.new(env, self)
34
36
  result = catch(:warden) do
@@ -85,7 +87,7 @@ module Warden
85
87
  # It looks at the result of the proxy to see if it's been executed and what action to take.
86
88
  # :api: private
87
89
  def process_unauthenticated(env, options={})
88
- options[:action] ||= :unauthenticated
90
+ options[:action] ||= "unauthenticated"
89
91
 
90
92
  proxy = env['warden']
91
93
  result = options[:result] || proxy.result
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ module Warden
3
+ module ManagerDeprecation
4
+ class Dummy
5
+ def update(type, &block)
6
+ if type == :session
7
+ warn "[DEPRECATION] warden.serializers.update(:session) is deprecated. " <<
8
+ "Please use Warden::Manager.serialize_from_session and Warden::Manager.serialize_into_session"
9
+ Warden::SessionSerializer.class_eval(&block)
10
+ else
11
+ method_missing(update)
12
+ end
13
+ end
14
+
15
+ def method_missing(method, *args)
16
+ warn "[DEPRECATION] warden.serializers.#{method} is deprecated."
17
+ nil
18
+ end
19
+ end
20
+
21
+ # Read the default scope from Warden
22
+ def default_scope
23
+ warn "[DEPRECATION] Warden::Manager.default_scope is deprecated. It's now accessible in the Warden::Manager instance."
24
+ end
25
+
26
+ # Set the default scope for Warden.
27
+ def default_scope=(scope)
28
+ warn "[DEPRECATION] Warden::Manager.default_scope= is deprecated. Please set it in the Warden::Manager instance."
29
+ end
30
+
31
+ def serializers
32
+ warn "[DEPRECATION] warden.serializers is deprecated since Warden::Serializers were merged into Warden::Strategies."
33
+ Dummy.new
34
+ end
35
+ end
36
+ end
data/lib/warden/proxy.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # encoding: utf-8
2
+ require 'warden/proxy_deprecation'
2
3
 
3
4
  module Warden
4
5
  class UserNotSet < RuntimeError; end
5
6
 
6
7
  class Proxy
8
+ include ProxyDeprecation
7
9
  # An accessor to the winning strategy
8
10
  # :api: private
9
11
  attr_accessor :winning_strategy
@@ -267,14 +269,13 @@ module Warden
267
269
  def _retrieve_scope_and_opts(args) #:nodoc:
268
270
  opts = args.last.is_a?(Hash) ? args.pop : {}
269
271
  scope = opts[:scope] || @config.default_scope
272
+ opts = (config[:scope_defaults][scope] || {}).merge(opts)
270
273
  [scope, opts]
271
274
  end
272
275
 
273
276
  # Run the strategies for a given scope
274
277
  def _run_strategies_for(scope, args) #:nodoc:
275
278
  self.winning_strategy = @winning_strategies[scope]
276
- return if winning_strategy && winning_strategy.halted?
277
-
278
279
  strategies = args.empty? ? default_strategies(:scope => scope) : args
279
280
 
280
281
  strategies.each do |name|
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ module Warden
3
+ # Sets up a place for deprecation of methods from the main proxy
4
+ module ProxyDeprecation
5
+ def default_strategies=(*strategies)
6
+ warn "[DEPRECATION] warden.default_strategies= is deprecated. Instead use warden.default_strategies(*strategies) with an optional :scope => :scope)"
7
+ strategies.push(:scope => @config.default_scope)
8
+ default_strategies(*strategies)
9
+ end
10
+ end
11
+ end
@@ -16,6 +16,7 @@ module Warden
16
16
  # @api public
17
17
  def login_as(user, opts = {})
18
18
  Warden.on_next_request do |proxy|
19
+ opts[:event] ||= :authentication
19
20
  proxy.set_user(user, opts)
20
21
  end
21
22
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Warden
3
- VERSION = "0.10.3".freeze
3
+ VERSION = "0.10.4".freeze
4
4
  end
@@ -220,6 +220,18 @@ describe Warden::Proxy do
220
220
  setup_rack(app).call(env)
221
221
  end
222
222
 
223
+ it "should store the last winning strategy per scope" do
224
+ env = env_with_params("/")
225
+ app = lambda do |env|
226
+ env['warden'].authenticate(:failz)
227
+ env['warden'].should_not be_authenticated
228
+ env['warden'].authenticate(:failz)
229
+ env['warden'].winning_strategy.message.should == "The Fails Strategy Has Failed You"
230
+ valid_response
231
+ end
232
+ setup_rack(app).call(env)
233
+ end
234
+
223
235
  it "should run strategies for a given scope several times if cache is cleaned" do
224
236
  env = env_with_params("/")
225
237
  app = lambda do |env|
@@ -256,19 +268,6 @@ describe Warden::Proxy do
256
268
  end
257
269
  setup_rack(app).call(env)
258
270
  end
259
-
260
- it "should not run strategies until cache is cleaned if latest winning strategy halted" do
261
- env = env_with_params("/")
262
- app = lambda do |env|
263
- env['warden'].authenticate(:failz)
264
- env['warden'].should_not be_authenticated
265
- env['warden'].authenticate(:pass)
266
- env['warden'].winning_strategy.message.should == "The Fails Strategy Has Failed You"
267
- valid_response
268
- end
269
- setup_rack(app).call(env)
270
- end
271
-
272
271
  end
273
272
 
274
273
  describe "set user" do
@@ -774,6 +773,27 @@ describe "dynamic default_strategies" do
774
773
  end
775
774
 
776
775
  describe "default scope options" do
776
+
777
+ it "should allow me to set a default action for a given scope" do
778
+ $captures = []
779
+ builder = Rack::Builder.new do
780
+ use Warden::Manager do |config|
781
+ config.scope_defaults :foo, :strategies => [:two], :action => "some_bad_action"
782
+ config.failure_app = Warden::Spec::Helpers::FAILURE_APP
783
+ end
784
+
785
+ run(lambda do |e|
786
+ e['warden'].authenticate!(:scope => :foo)
787
+ end)
788
+ end
789
+
790
+ env = env_with_params("/foo")
791
+ env["rack.session"] = {}
792
+ builder.to_app.call(env)
793
+ request = Rack::Request.new(env)
794
+ request.path.should == "/some_bad_action"
795
+ end
796
+
777
797
  it "should allow me to set store, false on a given scope" do
778
798
  $captures = []
779
799
  builder = Rack::Builder.new do
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.10.3"
8
+ s.version = "0.10.4"
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-04-01}
12
+ s.date = %q{2010-05-14}
13
13
  s.email = %q{has.sox@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -27,8 +27,10 @@ Gem::Specification.new do |s|
27
27
  "lib/warden/errors.rb",
28
28
  "lib/warden/hooks.rb",
29
29
  "lib/warden/manager.rb",
30
+ "lib/warden/manager_deprecation.rb",
30
31
  "lib/warden/mixins/common.rb",
31
32
  "lib/warden/proxy.rb",
33
+ "lib/warden/proxy_deprecation.rb",
32
34
  "lib/warden/session_serializer.rb",
33
35
  "lib/warden/strategies.rb",
34
36
  "lib/warden/strategies/base.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 10
8
- - 3
9
- version: 0.10.3
8
+ - 4
9
+ version: 0.10.4
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-04-01 00:00:00 +02:00
17
+ date: 2010-05-14 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,8 +66,10 @@ files:
66
66
  - lib/warden/errors.rb
67
67
  - lib/warden/hooks.rb
68
68
  - lib/warden/manager.rb
69
+ - lib/warden/manager_deprecation.rb
69
70
  - lib/warden/mixins/common.rb
70
71
  - lib/warden/proxy.rb
72
+ - lib/warden/proxy_deprecation.rb
71
73
  - lib/warden/session_serializer.rb
72
74
  - lib/warden/strategies.rb
73
75
  - lib/warden/strategies/base.rb