warden 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/warden/manager.rb +22 -20
- data/lib/warden/version.rb +1 -1
- data/spec/warden/manager_spec.rb +11 -0
- data/warden.gemspec +2 -2
- metadata +3 -3
data/lib/warden/manager.rb
CHANGED
@@ -37,14 +37,13 @@ module Warden
|
|
37
37
|
result ||= {}
|
38
38
|
case result
|
39
39
|
when Array
|
40
|
-
if result.first == 401
|
41
|
-
process_unauthenticated(
|
40
|
+
if result.first == 401 && !env['warden'].custom_failure?
|
41
|
+
process_unauthenticated(env)
|
42
42
|
else
|
43
43
|
result
|
44
44
|
end
|
45
45
|
when Hash
|
46
|
-
result
|
47
|
-
process_unauthenticated(result, env)
|
46
|
+
process_unauthenticated(env, result || {})
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
@@ -84,30 +83,33 @@ module Warden
|
|
84
83
|
# When a request is unauthentiated, here's where the processing occurs.
|
85
84
|
# It looks at the result of the proxy to see if it's been executed and what action to take.
|
86
85
|
# :api: private
|
87
|
-
def process_unauthenticated(
|
88
|
-
|
86
|
+
def process_unauthenticated(env, options={})
|
87
|
+
options[:action] ||= :unauthenticated
|
89
88
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
proxy = env['warden']
|
90
|
+
result = options[:result] || proxy.result
|
91
|
+
|
92
|
+
case result
|
93
|
+
when :redirect
|
94
|
+
body = proxy.message || "You are being redirected to #{proxy.headers['Location']}"
|
95
|
+
[proxy.status, proxy.headers, [body]]
|
96
|
+
when :custom
|
97
|
+
proxy.custom_response
|
98
|
+
else
|
99
|
+
call_failure_app(env, options)
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
100
103
|
# Calls the failure app.
|
101
104
|
# The before_failure hooks are run on each failure
|
102
105
|
# :api: private
|
103
|
-
def call_failure_app(env,
|
104
|
-
if
|
105
|
-
|
106
|
-
|
107
|
-
env["
|
108
|
-
env["warden.options"] = opts
|
106
|
+
def call_failure_app(env, options = {})
|
107
|
+
if config.failure_app
|
108
|
+
options.merge!(:attempted_path => ::Rack::Request.new(env).fullpath)
|
109
|
+
env["PATH_INFO"] = "/#{options[:action]}"
|
110
|
+
env["warden.options"] = options
|
109
111
|
|
110
|
-
_run_callbacks(:before_failure, env,
|
112
|
+
_run_callbacks(:before_failure, env, options)
|
111
113
|
config.failure_app.call(env).to_a
|
112
114
|
else
|
113
115
|
raise "No Failure App provided"
|
data/lib/warden/version.rb
CHANGED
data/spec/warden/manager_spec.rb
CHANGED
@@ -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
|
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.7"
|
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-11}
|
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
|
+
- 7
|
9
|
+
version: 0.9.7
|
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-11 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|