warden 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1,2 @@
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
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.1
@@ -47,7 +47,7 @@ module Warden
47
47
  if result.first != 401
48
48
  return result
49
49
  else
50
- call_failure_app(env)
50
+ call_failure_app(env, :original_response => result)
51
51
  end
52
52
  when Hash
53
53
  if (result[:action] ||= :unauthenticated) == :unauthenticated
@@ -122,13 +122,17 @@ module Warden
122
122
  # The before_failure hooks are run on each failure
123
123
  # :api: private
124
124
  def call_failure_app(env, opts = {})
125
- env["PATH_INFO"] = "/#{opts[:action]}"
126
- env["warden.options"] = opts
125
+ if env['warden'].custom_failure?
126
+ opts[:original_response]
127
+ else
128
+ env["PATH_INFO"] = "/#{opts[:action]}"
129
+ env["warden.options"] = opts
127
130
 
128
- # Call the before failure callbacks
129
- Warden::Manager._before_failure.each{|hook| hook.call(env,opts)}
131
+ # Call the before failure callbacks
132
+ Warden::Manager._before_failure.each{|hook| hook.call(env,opts)}
130
133
 
131
- @failure_app.call(env).to_a
134
+ @failure_app.call(env).to_a
135
+ end
132
136
  end # call_failure_app
133
137
  end
134
138
  end # Warden
@@ -14,7 +14,7 @@ module Warden
14
14
  alias_method :_session, :session
15
15
 
16
16
  # :api: private
17
- def_delegators :winning_strategy, :headers, :message, :_status, :custom_response
17
+ def_delegators :winning_strategy, :headers, :_status, :custom_response
18
18
 
19
19
  def initialize(env, config = {}) # :nodoc:
20
20
  @env = env
@@ -155,6 +155,25 @@ module Warden
155
155
  winning_strategy.nil? ? nil : winning_strategy.result
156
156
  end
157
157
 
158
+ # Proxy through to the authentication strategy to find out the message that was generated.
159
+ # :api: public
160
+ def message
161
+ winning_strategy.nil? ? "" : winning_strategy.message
162
+ end
163
+
164
+ # Provides a way to return a 401 without warden defering to the failure app
165
+ # The result is a direct passthrough of your own response
166
+ # :api: public
167
+ def custom_failure!
168
+ @custom_failure = true
169
+ end
170
+
171
+ # Check to see if the custom failur flag has been set
172
+ # :api: public
173
+ def custom_failure?
174
+ !!@custom_failure
175
+ end
176
+
158
177
  private
159
178
  # :api: private
160
179
  def _perform_authentication(*args)
@@ -13,7 +13,7 @@ module Warden::Spec
13
13
  def setup_rack(app = nil, opts = {}, &block)
14
14
  app ||= block if block_given?
15
15
  # opts[:default_strategies] ||= [:password]
16
- # opts[:failure_app] ||= failure_app
16
+ opts[:failure_app] ||= Warden::Spec::Helpers::FAILURE_APP
17
17
  Rack::Builder.new do
18
18
  use Warden::Spec::Helpers::Session
19
19
  use Warden::Manager, opts do |manager|
@@ -23,7 +23,7 @@ describe Warden::Manager do
23
23
  if e['warden'].authenticated?
24
24
  [200,{'Content-Type' => 'text/plain'},"OK"]
25
25
  else
26
- [401,{'Content-Type' => 'text/plain'},"You Fail"]
26
+ [401,{'Content-Type' => 'text/plain'},"Fail From The App"]
27
27
  end
28
28
  end
29
29
  @env = Rack::MockRequest.
@@ -125,6 +125,27 @@ describe Warden::Manager do
125
125
  result[2].should == ["You Fail!"]
126
126
  env['PATH_INFO'].should == "/unauthenticated"
127
127
  end
128
+
129
+ it "should allow you to customize the response" do
130
+ app = lambda do |e|
131
+ e['warden'].custom_failure!
132
+ [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
133
+ end
134
+ env = env_with_params
135
+ result = setup_rack(app).call(env)
136
+ result[0].should == 401
137
+ result[2].should == ["Fail From The App"]
138
+ end
139
+
140
+ it "should render the failure application for a 401 if no custom_failure flag is set" do
141
+ app = lambda do |e|
142
+ [401,{'Content-Type' => 'text/plain'},["Fail From The App"]]
143
+ end
144
+ result = setup_rack(app).call(env_with_params)
145
+ result[0].should == 401
146
+ result[2].should == ["You Fail!"]
147
+ end
148
+
128
149
  end # failing
129
150
 
130
151
  describe "custom rack response" do
@@ -153,6 +174,7 @@ describe Warden::Manager do
153
174
  result[0].should == 200
154
175
  result[2].should == ["Foo Is A Winna"]
155
176
  end
156
- end
177
+ end
157
178
  end # integrated strategies
179
+
158
180
  end
@@ -251,7 +251,7 @@ describe Warden::Proxy do
251
251
  @env['warden'].user.should be_nil
252
252
 
253
253
  end
254
- require 'ruby-debug'
254
+
255
255
  it "should clear the session data when logging out" do
256
256
  @env['rack.session'].should_not be_nil
257
257
  app = lambda do |e|
@@ -265,6 +265,28 @@ describe Warden::Proxy do
265
265
  end
266
266
  end
267
267
 
268
+ describe "messages" do
269
+
270
+ it "should allow access to the failure message" do
271
+ failure = lambda do |e|
272
+ [401, {"Content-Type" => "text/plain"}, [e['warden'].message]]
273
+ end
274
+ app = lambda do |e|
275
+ e['warden'].authenticate! :failz
276
+ end
277
+ result = setup_rack(app, :failure_app => failure).call(env_with_params)
278
+ result.last.should == ["The Fails Strategy Has Failed You"]
279
+ end
280
+
281
+ it "should not die when accessing a message from a source where no authentication has occured" do
282
+ app = lambda do |e|
283
+ [200, {"Content-Type" => "text/plain"}, [e['warden'].message]]
284
+ end
285
+ result = setup_rack(app).call(env_with_params)
286
+ result[2].should == [""]
287
+ end
288
+ end
289
+
268
290
  describe "when all strategies are not valid?" do
269
291
  it "should return false for authenticated when there are no valid? strategies" do
270
292
  @env['rack.session'] = {}
@@ -293,4 +315,6 @@ describe Warden::Proxy do
293
315
 
294
316
  end
295
317
 
318
+
319
+
296
320
  end
@@ -3,7 +3,7 @@ Warden::Strategies.add(:failz) do
3
3
  def authenticate!
4
4
  request.env['warden.spec.strategies'] ||= []
5
5
  request.env['warden.spec.strategies'] << :failz
6
- fail!("You Fail!")
6
+ fail!("The Fails Strategy Has Failed You")
7
7
  end
8
8
 
9
9
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{warden}
5
- s.version = "0.2.3"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Daniel Neighman"]
9
- s.date = %q{2009-07-08}
9
+ s.date = %q{2009-08-10}
10
10
  s.email = %q{has.sox@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
50
50
  s.rdoc_options = ["--charset=UTF-8"]
51
51
  s.require_paths = ["lib"]
52
52
  s.rubyforge_project = %q{warden}
53
- s.rubygems_version = %q{1.3.3}
53
+ s.rubygems_version = %q{1.3.4}
54
54
  s.summary = %q{Rack middleware that provides authentication for rack applications}
55
55
  s.test_files = [
56
56
  "spec/helpers/request_helper.rb",
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.2.3
4
+ version: 0.3.1
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-07-08 00:00:00 +10:00
12
+ date: 2009-08-10 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements: []
89
89
 
90
90
  rubyforge_project: warden
91
- rubygems_version: 1.3.3
91
+ rubygems_version: 1.3.4
92
92
  signing_key:
93
93
  specification_version: 3
94
94
  summary: Rack middleware that provides authentication for rack applications