Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for #warden_cookies #34

Closed
wants to merge 7 commits into from

2 participants

@punkrats

As described in #20 and mentioned in my mail to hassox, #warden_cookies did not show up in the response. Now they do. :)

@josevalim
Collaborator

Shouldn't warden cookies just be a pointer to rack cookies? I am at first -1 on Warden implementing its own cookies serialization (even though it uses just rack methods, it doesn't seem warden's responsibilities).

@punkrats

That's a good point. I just implemented the feature how it was intended by the author, because it's rather convenient. But yes, you could easily call
Rack::Utils.set_cookie_header!(env['warden'].headers, 'something', {:value => 'else'}) directly in a warden strategy.

If you don't want to use this patch, please close it. And please remove the #warden_cookies method because it's not working and thus quite distracting.

@josevalim josevalim closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2011
  1. @punkrats

    Remove Gemfile.lock

    punkrats authored
  2. @punkrats

    Ignore .bundle

    punkrats authored
  3. @punkrats
  4. @punkrats

    Fix for Ruby 1.9.3

    punkrats authored
  5. @punkrats

    Cleanup whitespace

    punkrats authored
  6. @punkrats
  7. @punkrats

    Damn... it's late

    punkrats authored
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -1,5 +1,7 @@
.DS_Store
pkg
+Gemfile.lock
+.bundle
.*~
*.gem
View
32 Gemfile.lock
@@ -1,32 +0,0 @@
-PATH
- remote: .
- specs:
- warden (1.0.7)
- rack (>= 1.0)
-
-GEM
- remote: http://rubygems.org/
- specs:
- diff-lcs (1.1.2)
- rack (1.3.0)
- rack-test (0.6.0)
- rack (>= 1.0)
- rake (0.8.7)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- rack (= 1.3)
- rack-test
- rake
- rspec (~> 2)
- warden!
View
12 lib/warden/manager.rb
@@ -45,6 +45,8 @@ def call(env) # :nodoc:
end
when Hash
process_unauthenticated(env, result)
+ end.tap do |response|
+ set_warden_cookies(env, response[1]) if response
end
end
@@ -123,5 +125,15 @@ def call_failure_app(env, options = {})
raise "No Failure App provided"
end
end # call_failure_app
+
+ # Sets headers for cookies in env['warden.cookies'].
+ def set_warden_cookies(env, headers)
+ cookies = env['warden.cookies']
+ if cookies and cookies.any?
+ cookies.each do |key, value|
+ Rack::Utils.set_cookie_header!(headers, key, value)
+ end
+ end
+ end # set_warden_cookies
end
end # Warden
View
2  lib/warden/version.rb
@@ -1,4 +1,4 @@
# encoding: utf-8
module Warden
- VERSION = "1.1.0".freeze
+ VERSION = '1.1.0'
end
View
2  spec/helpers/request_helper.rb
@@ -15,7 +15,7 @@ def setup_rack(app = nil, opts = {}, &block)
opts[:failure_app] ||= failure_app
opts[:default_strategies] ||= [:password]
opts[:default_serializers] ||= [:session]
- blk = opts[:configurator] || lambda{}
+ blk = opts[:configurator] || proc{}
Rack::Builder.new do
use opts[:session] || Warden::Spec::Helpers::Session
View
45 spec/warden/manager_spec.rb
@@ -132,7 +132,7 @@ def call(env)
action = nil
failure = lambda do |env|
- action = env['PATH_INFO']
+ action = env['PATH_INFO']
[401, {}, ['fail']]
end
@@ -219,6 +219,17 @@ def authenticate!
result[1]["Location"].should == "/foo/bar?foo=bar"
result[1]["Content-Type"].should == "text/plain"
end
+
+ it 'should set warden_cookies' do
+ RAS.add(:foobar) do
+ def authenticate!
+ warden_cookies[:something] = {:value => 'else'}
+ redirect!('/foo/bar')
+ end
+ end
+ result = @app.call(env_with_params)
+ result[1]['Set-Cookie'].should eq('something=else')
+ end
end
describe "failing" do
@@ -265,6 +276,16 @@ def authenticate!
result[2].should == ["You Fail!"]
end
+ it 'should set warden_cookies' do
+ RAS.add(:foobar) do
+ def authenticate!
+ warden_cookies[:something] = {:value => 'else'}
+ fail!
+ end
+ end
+ result = @app.call(env_with_params)
+ result[1]['Set-Cookie'].should eq('something=else')
+ end
end # failing
describe "custom rack response" do
@@ -279,6 +300,17 @@ def authenticate!
result[1]["Custom-Header"].should == "foo"
result[2].should == ["Custom Stuff"]
end
+
+ it 'should set warden_cookies' do
+ RAS.add(:foobar) do
+ def authenticate!
+ warden_cookies[:something] = {:value => 'else'}
+ custom!([523, {}, ['bar']])
+ end
+ end
+ result = @app.call(env_with_params)
+ result[1]['Set-Cookie'].should eq('something=else')
+ end
end
describe "success" do
@@ -293,6 +325,17 @@ def authenticate!
result[0].should == 200
result[2].should == ["Foo Is A Winna"]
end
+
+ it 'should set warden_cookies' do
+ RAS.add(:foobar) do
+ def authenticate!
+ warden_cookies[:something] = {:value => 'else'}
+ success!('A User')
+ end
+ end
+ result = @app.call(env_with_params)
+ result[1]['Set-Cookie'].should eq('something=else')
+ end
end
end # integrated strategies
Something went wrong with that request. Please try again.