warden 0.3.2 → 0.4.0
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/README.textile +8 -1
- data/VERSION +1 -1
- data/lib/warden/authentication/strategy_base.rb +6 -5
- data/lib/warden/proxy.rb +6 -11
- data/spec/warden/manager_spec.rb +24 -0
- data/spec/warden/proxy_spec.rb +11 -0
- data/spec/warden/strategies/pass.rb +1 -1
- data/spec/warden/strategy_base_spec.rb +10 -1
- data/warden.gemspec +2 -2
- metadata +2 -2
data/README.textile
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
-
Please see the "Warden Wiki":http://wiki.github.com/hassox/warden for overview documentation.
|
1
|
+
Please see the "Warden Wiki":http://wiki.github.com/hassox/warden for overview documentation.
|
2
|
+
|
3
|
+
h2. Contributors
|
4
|
+
|
5
|
+
I'm going to try and keep a list of all the contributors to this project. If I've missed your name please just let me know and I'll update it.
|
6
|
+
|
7
|
+
* Daniel Neighman (hassox)
|
8
|
+
* Mick Staugaard (staugaard)
|
2
9
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -14,14 +14,14 @@ module Warden
|
|
14
14
|
|
15
15
|
# Accessor for the rack env
|
16
16
|
# :api: public
|
17
|
-
attr_reader :env
|
17
|
+
attr_reader :env, :scope
|
18
18
|
include ::Warden::Mixins::Common
|
19
19
|
|
20
20
|
# :api: private
|
21
|
-
def initialize(env, config
|
22
|
-
@config = config
|
21
|
+
def initialize(env, scope=nil, config={}) # :nodoc:
|
22
|
+
@scope, @config = scope, config
|
23
23
|
@env, @_status, @headers = env, nil, {}
|
24
|
-
@halted = false
|
24
|
+
@halted = false
|
25
25
|
end
|
26
26
|
|
27
27
|
# The method that is called from above. This method calls the underlying authetniate! method
|
@@ -104,7 +104,8 @@ module Warden
|
|
104
104
|
@_status = opts[:permanent] ? 301 : 302
|
105
105
|
headers["Location"] = url
|
106
106
|
headers["Location"] << "?" << Rack::Utils.build_query(params) unless params.empty?
|
107
|
-
|
107
|
+
headers["Content-Type"] = opts[:content_type] || 'text/plain'
|
108
|
+
|
108
109
|
@message = opts[:message].nil? ? "You are being redirected to #{headers["Location"]}" : opts[:message]
|
109
110
|
|
110
111
|
@result = :redirect
|
data/lib/warden/proxy.rb
CHANGED
@@ -52,8 +52,7 @@ module Warden
|
|
52
52
|
# env['auth'].authenticate(:password, :basic, :scope => :sudo)
|
53
53
|
# :api: public
|
54
54
|
def authenticate(*args)
|
55
|
-
scope =
|
56
|
-
_perform_authentication(*args)
|
55
|
+
scope, opts = _perform_authentication(*args)
|
57
56
|
user(scope)
|
58
57
|
end
|
59
58
|
|
@@ -65,9 +64,7 @@ module Warden
|
|
65
64
|
#
|
66
65
|
# :api: public
|
67
66
|
def authenticate!(*args)
|
68
|
-
opts =
|
69
|
-
scope = scope_from_args(args)
|
70
|
-
_perform_authentication(*args)
|
67
|
+
scope, opts = _perform_authentication(*args)
|
71
68
|
throw(:warden, opts.merge(:action => :unauthenticated)) if !user(scope)
|
72
69
|
user(scope)
|
73
70
|
end
|
@@ -181,22 +178,20 @@ module Warden
|
|
181
178
|
opts = opts_from_args(args)
|
182
179
|
|
183
180
|
# Look for an existing user in the session for this scope
|
184
|
-
if the_user = user(scope)
|
185
|
-
return the_user
|
186
|
-
end
|
181
|
+
return scope, opts if the_user = user(scope)
|
187
182
|
|
188
183
|
# If there was no user in the session. See if we can get one from the request
|
189
184
|
strategies = args.empty? ? @strategies : args
|
190
185
|
raise "No Strategies Found" if strategies.empty? || !(strategies - Warden::Strategies._strategies.keys).empty?
|
186
|
+
|
191
187
|
strategies.each do |s|
|
192
|
-
strategy = Warden::Strategies[s].new(@env, @conf)
|
188
|
+
strategy = Warden::Strategies[s].new(@env, scope, @conf)
|
193
189
|
self.winning_strategy = strategy
|
194
190
|
next unless strategy.valid?
|
195
191
|
strategy._run!
|
196
192
|
break if strategy.halted?
|
197
193
|
end
|
198
194
|
|
199
|
-
|
200
195
|
if winning_strategy && winning_strategy.user
|
201
196
|
set_user(winning_strategy.user, opts)
|
202
197
|
|
@@ -204,7 +199,7 @@ module Warden
|
|
204
199
|
Warden::Manager._after_authentication.each{|hook| hook.call(winning_strategy.user, self, opts)}
|
205
200
|
end
|
206
201
|
|
207
|
-
|
202
|
+
[scope, opts]
|
208
203
|
end
|
209
204
|
|
210
205
|
# :api: private
|
data/spec/warden/manager_spec.rb
CHANGED
@@ -110,6 +110,30 @@ describe Warden::Manager do
|
|
110
110
|
result = @app.call(env_with_params)
|
111
111
|
result[0].should == 301
|
112
112
|
end
|
113
|
+
|
114
|
+
it "should redirect with a content type" do
|
115
|
+
RAS.add(:foobar) do
|
116
|
+
def authenticate!
|
117
|
+
redirect!("/foo/bar", {:foo => "bar"}, :content_type => "text/xml")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
result = @app.call(env_with_params)
|
121
|
+
result[0].should == 302
|
122
|
+
result[1]["Location"].should == "/foo/bar?foo=bar"
|
123
|
+
result[1]["Content-Type"].should == "text/xml"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should redirect with a default content type" do
|
127
|
+
RAS.add(:foobar) do
|
128
|
+
def authenticate!
|
129
|
+
redirect!("/foo/bar", {:foo => "bar"})
|
130
|
+
end
|
131
|
+
end
|
132
|
+
result = @app.call(env_with_params)
|
133
|
+
result[0].should == 302
|
134
|
+
result[1]["Location"].should == "/foo/bar?foo=bar"
|
135
|
+
result[1]["Content-Type"].should == "text/plain"
|
136
|
+
end
|
113
137
|
end
|
114
138
|
|
115
139
|
describe "failing" do
|
data/spec/warden/proxy_spec.rb
CHANGED
@@ -90,6 +90,17 @@ describe Warden::Proxy do
|
|
90
90
|
setup_rack(app).call(env)
|
91
91
|
end
|
92
92
|
|
93
|
+
it "should properly sent the scope to the strategy" do
|
94
|
+
env = env_with_params("/")
|
95
|
+
app = lambda do |env|
|
96
|
+
env['warden'].authenticate!(:pass, :scope => :failz)
|
97
|
+
env['warden'].should_not be_authenticated
|
98
|
+
env['warden.spec.strategies'].should == [:pass]
|
99
|
+
valid_response
|
100
|
+
end
|
101
|
+
setup_rack(app).call(env)
|
102
|
+
end
|
103
|
+
|
93
104
|
it "should try multiple authentication strategies" do
|
94
105
|
env = env_with_params("/")
|
95
106
|
app = lambda do |env|
|
@@ -44,6 +44,15 @@ describe Warden::Strategies::Base do
|
|
44
44
|
strategy.user.should == "foo"
|
45
45
|
end
|
46
46
|
|
47
|
+
it "should set the scope" do
|
48
|
+
RAS.add(:foobar) do
|
49
|
+
def authenticate!
|
50
|
+
self.scope.should == :user
|
51
|
+
end
|
52
|
+
end
|
53
|
+
strategy = RAS[:foobar].new(env_with_params, :user)
|
54
|
+
end
|
55
|
+
|
47
56
|
it "should allow you to set a message" do
|
48
57
|
RAS.add(:foobar) do
|
49
58
|
def authenticate!
|
@@ -256,4 +265,4 @@ describe Warden::Strategies::Base do
|
|
256
265
|
end
|
257
266
|
end
|
258
267
|
|
259
|
-
end
|
268
|
+
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.
|
8
|
+
s.version = "0.4.0"
|
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{2009-
|
12
|
+
s.date = %q{2009-10-12}
|
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.
|
4
|
+
version: 0.4.0
|
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: 2009-
|
12
|
+
date: 2009-10-12 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|