warden 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,14 +40,13 @@ module Warden
40
40
  result ||= {}
41
41
  case result
42
42
  when Array
43
- if result.first == 401
44
- process_unauthenticated({:original_response => result, :action => :unauthenticated}, env)
43
+ if result.first == 401 && !env['warden'].custom_failure?
44
+ process_unauthenticated(env)
45
45
  else
46
46
  result
47
47
  end
48
48
  when Hash
49
- result[:action] ||= :unauthenticated
50
- process_unauthenticated(result, env)
49
+ process_unauthenticated(env, result || {})
51
50
  end
52
51
  end
53
52
 
@@ -87,30 +86,33 @@ module Warden
87
86
  # When a request is unauthentiated, here's where the processing occurs.
88
87
  # It looks at the result of the proxy to see if it's been executed and what action to take.
89
88
  # :api: private
90
- def process_unauthenticated(result, env)
91
- action = result[:result] || env['warden'].result
92
-
93
- case action
94
- when :redirect
95
- [env['warden'].status, env['warden'].headers, [env['warden'].message || "You are being redirected to #{env['warden'].headers['Location']}"]]
96
- when :custom
97
- env['warden'].custom_response
98
- else
99
- call_failure_app(env, result)
89
+ def process_unauthenticated(env, options={})
90
+ options[:action] ||= :unauthenticated
91
+
92
+ proxy = env['warden']
93
+ result = options[:result] || proxy.result
94
+
95
+ case result
96
+ when :redirect
97
+ body = proxy.message || "You are being redirected to #{proxy.headers['Location']}"
98
+ [proxy.status, proxy.headers, [body]]
99
+ when :custom
100
+ proxy.custom_response
101
+ else
102
+ call_failure_app(env, options)
100
103
  end
101
104
  end
102
105
 
103
106
  # Calls the failure app.
104
107
  # The before_failure hooks are run on each failure
105
108
  # :api: private
106
- def call_failure_app(env, opts = {})
107
- if env['warden'].custom_failure?
108
- opts[:original_response]
109
- elsif config.failure_app
110
- env["PATH_INFO"] = "/#{opts[:action]}"
111
- env["warden.options"] = opts
112
-
113
- _run_callbacks(:before_failure, env, opts)
109
+ def call_failure_app(env, options = {})
110
+ if config.failure_app
111
+ options.merge!(:attempted_path => ::Rack::Request.new(env).fullpath)
112
+ env["PATH_INFO"] = "/#{options[:action]}"
113
+ env["warden.options"] = options
114
+
115
+ _run_callbacks(:before_failure, env, options)
114
116
  config.failure_app.call(env).to_a
115
117
  else
116
118
  raise "No Failure App provided"
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Warden
3
- VERSION = "0.10.0".freeze
3
+ VERSION = "0.10.1".freeze
4
4
  end
@@ -69,6 +69,17 @@ describe Warden::Manager do
69
69
  result.first.should == 401
70
70
  result.last.should == ["You Fail!"]
71
71
  end
72
+
73
+ it "should set the attempted url in warden.options hash" do
74
+ env = env_with_params("/access/path", {})
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
+ result.first.should == 401
81
+ env["warden.options"][:attempted_path].should == "/access/path"
82
+ end
72
83
  end # failure
73
84
 
74
85
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{warden}
8
- s.version = "0.10.0"
8
+ s.version = "0.10.1"
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-22}
12
+ s.date = %q{2010-03-23}
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
  - 10
8
- - 0
9
- version: 0.10.0
8
+ - 1
9
+ version: 0.10.1
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-22 00:00:00 +11:00
17
+ date: 2010-03-23 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency