warden 0.5.1 → 0.5.2

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/History.rdoc CHANGED
@@ -1,3 +1,15 @@
1
+ * enhancements
2
+ * authenticated? always try to serialize the user from session (josevalim)
3
+ * stored_in_session? checks if user information is stored in session, without serializing (josevalim)
4
+ * 401 behaves exactly like throw :warden (staugaard)
5
+
6
+ === Version 0.5.1 / 2009-10-25
7
+ * enhancements
8
+ * Adds yeilding to authenticated? and unauthenticated? methods (hassox)
9
+ * Adds an option to silence missing strategies (josevalim)
10
+ * Add an option to authenticate(!) to prevent storage of a user into the session (hassox)
11
+ * allow custom :action to be thrown (josevalim)
12
+
1
13
  === Version 0.4.0 / 2009-10-12
2
14
 
3
15
  * enhancements
data/README.textile CHANGED
@@ -6,4 +6,6 @@ I'm going to try and keep a list of all the contributors to this project. If I'
6
6
 
7
7
  * Daniel Neighman (hassox)
8
8
  * Mick Staugaard (staugaard)
9
-
9
+ * José Valim (josevalim)
10
+ * Carlo Santoniodasilva (carlosantoniodasilva)
11
+ * Justin Smestad (jsmestad)
data/Rakefile CHANGED
@@ -14,6 +14,8 @@ begin
14
14
  gem.rubyforge_project = "warden"
15
15
  gem.add_dependency "rack", ">= 1.0.0"
16
16
  end
17
+
18
+ Jeweler::GemcutterTasks.new
17
19
  rescue LoadError
18
20
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
21
  end
@@ -54,7 +54,7 @@ module Warden
54
54
  if result.first != 401
55
55
  return result
56
56
  else
57
- call_failure_app(env, :original_response => result)
57
+ process_unauthenticated({:original_response => result, :action => :unauthenticated}, env)
58
58
  end
59
59
  when Hash
60
60
  result[:action] ||= :unauthenticated
data/lib/warden/proxy.rb CHANGED
@@ -36,11 +36,12 @@ module Warden
36
36
  # env['warden'].authenticated?(:admin)
37
37
  # :api: public
38
38
  def authenticated?(scope = :default)
39
- result = !raw_session["warden.user.#{scope}.key"].nil? || !!user(scope)
39
+ result = user(scope) || false
40
40
  yield if block_given? && result
41
41
  result
42
- end # authenticated?
42
+ end
43
43
 
44
+ # Same API as authenticated, but returns false when authenticated.
44
45
  def unauthenticated?(scope = :default)
45
46
  result = !authenticated?(scope)
46
47
  yield if block_given? && result
@@ -77,6 +78,18 @@ module Warden
77
78
  user(scope)
78
79
  end
79
80
 
81
+ # Checks if the given scope is stored in session. Different from authenticated?, this method
82
+ # does not serialize values from session.
83
+ #
84
+ # Example
85
+ # env['warden'].set_user(@user)
86
+ # env['warden'].stored_in_session? #=> true
87
+ #
88
+ # :api: public
89
+ def stored_in_session?(scope = :default)
90
+ !!raw_session["warden.user.#{scope}.key"]
91
+ end
92
+
80
93
  # Manually set the user into the session and auth proxy
81
94
  #
82
95
  # Parameters:
@@ -113,10 +126,10 @@ module Warden
113
126
  #
114
127
  # Example
115
128
  # # default scope
116
- # env['warden'].data[:foo] = "bar"
129
+ # env['warden'].session[:foo] = "bar"
117
130
  #
118
131
  # # :sudo scope
119
- # env['warden'].data(:sudo)[:foo] = "bar"
132
+ # env['warden'].session(:sudo)[:foo] = "bar"
120
133
  #
121
134
  # :api: public
122
135
  def session(scope = :default)
@@ -163,7 +176,7 @@ module Warden
163
176
  # proxy methods through to the winning strategy
164
177
  # :api: private
165
178
  def result # :nodoc:
166
- winning_strategy.nil? ? nil : winning_strategy.result
179
+ winning_strategy.nil? ? nil : winning_strategy.result
167
180
  end
168
181
 
169
182
  # Proxy through to the authentication strategy to find out the message that was generated.
@@ -1,3 +1,3 @@
1
1
  module Warden
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -176,9 +176,49 @@ describe Warden::Proxy do
176
176
  env['warden'].user(:bar).should == 'bar user'
177
177
  env['warden'].user.should be_nil
178
178
  end
179
+
180
+ it "should not be authenticated if scope cannot be retrieved from session" do
181
+ begin
182
+ Warden::Manager.serialize_from_session { |k| nil }
183
+ app = lambda do |env|
184
+ env['rack.session']['warden.user.foo_scope.key'] = "a foo user"
185
+ env['warden'].authenticated?(:foo_scope)
186
+ valid_response
187
+ end
188
+ env = env_with_params
189
+ setup_rack(app).call(env)
190
+ env['warden'].user(:foo_scope).should be_nil
191
+ ensure
192
+ Warden::Manager.serialize_from_session { |k| k }
193
+ end
194
+ end
179
195
  end
180
196
  end # describe "authentication"
181
197
 
198
+ describe "stored in session" do
199
+ before(:each) do
200
+ @env['rack.session'] ||= {}
201
+ @env['rack.session']['warden.user.default.key'] = "User"
202
+ end
203
+
204
+ it "returns true if user key is stored in session" do
205
+ app = lambda do |env|
206
+ env['warden'].stored_in_session?.should be_true
207
+ valid_response
208
+ end
209
+ setup_rack(app).call(@env)
210
+ end
211
+
212
+ it "returns false if user key is not stored in session" do
213
+ @env['rack.session'].delete("warden.user.default.key")
214
+ app = lambda do |env|
215
+ env['warden'].stored_in_session?.should be_false
216
+ valid_response
217
+ end
218
+ setup_rack(app).call(@env)
219
+ end
220
+ end
221
+
182
222
  describe "set user" do
183
223
  it "should store the user into the session" do
184
224
  env = env_with_params("/")
@@ -309,7 +349,6 @@ describe Warden::Proxy do
309
349
  it "should clear the session data when logging out" do
310
350
  @env['rack.session'].should_not be_nil
311
351
  app = lambda do |e|
312
- # debugger
313
352
  e['warden'].user.should_not be_nil
314
353
  e['warden'].session[:foo] = :bar
315
354
  e['warden'].logout
data/warden.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{warden}
8
- s.version = "0.5.1"
8
+ s.version = "0.5.2"
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-10-24}
12
+ s.date = %q{2009-11-09}
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.5.1
4
+ version: 0.5.2
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-10-24 00:00:00 +11:00
12
+ date: 2009-11-09 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency