Browse files

bug #19234 : cookie path checking broken - Fixed.

  • Loading branch information...
1 parent 5e6ec3b commit 5a2f958c108d54c0bc44dcf7b470c5ff3c826682 @jmettraux jmettraux committed Apr 1, 2008
Showing with 34 additions and 8 deletions.
  1. +1 −0 CHANGELOG.txt
  2. +5 −3 lib/rufus/verbs/cookies.rb
  3. +28 −5 test/cookie0_test.rb
View
1 CHANGELOG.txt
@@ -4,6 +4,7 @@
== rufus-verbs - 0.9 released 2008/04/xx
+- bug #19234 : cookie path checking broken - Fixed.
- todo #19202 : EndPoint.cookies now readable
- bug #19201 : :params not respected when specified in request
- todo #19200 : added verbose mode (:v / :verbose)
View
8 lib/rufus/verbs/cookies.rb
@@ -108,7 +108,7 @@ def register_cookies (response, opts)
path = opts[:path]
cpath = c.path || "/"
- next unless cookie_acceptable?(opts, c)
+ next unless cookie_acceptable?(opts, response, c)
domain = c.domain || host
@@ -124,7 +124,7 @@ def register_cookies (response, opts)
# Checks if the cookie is acceptable in the context of
# the request that sent it.
#
- def cookie_acceptable? (opts, cookie)
+ def cookie_acceptable? (opts, response, cookie)
# reject if :
#
@@ -149,7 +149,9 @@ def cookie_acceptable? (opts, cookie)
return false if d != cdomain
end
- path = opts[:path]
+ #path = opts[:path]
+ path = response.request.path
+
cpath = cookie.path || "/"
return false if path[0..cpath.length-1] != cpath
View
33 test/cookie0_test.rb
@@ -65,32 +65,37 @@ def test_2
opts = { :host => 'rufus.rubyforge.org', :path => '/' }
c = TestCookie.new '.rubyforge.org', '/'
- assert cookie_acceptable?(opts, c)
+ r = TestResponse.new opts
+ assert cookie_acceptable?(opts, r, c)
# * The value for the Domain attribute contains no embedded dots
# or does not start with a dot.
opts = { :host => 'rufus.rubyforge.org', :path => '/' }
c = TestCookie.new 'rufus.rubyforge.org', '/'
- assert ! cookie_acceptable?(opts, c)
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
opts = { :host => 'rufus.rubyforge.org', :path => '/' }
c = TestCookie.new 'org', '/'
- assert ! cookie_acceptable?(opts, c)
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
# * The value for the Path attribute is not a prefix of the
# request-URI.
opts = { :host => 'rufus.rubyforge.org', :path => '/this' }
c = TestCookie.new '.rubyforge.org', '/that'
- assert ! cookie_acceptable?(opts, c)
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
# * The value for the request-host does not domain-match the
# Domain attribute.
opts = { :host => 'rufus.rubyforg.org', :path => '/' }
c = TestCookie.new '.rubyforge.org', '/'
- assert ! cookie_acceptable?(opts, c)
+ r = TestResponse.new opts
+ assert ! cookie_acceptable?(opts, r, c)
# * The request-host is a FQDN (not IP address) and has the form
# HD, where D is the value of the Domain attribute, and H is a
@@ -119,4 +124,22 @@ def initialize (domain=nil, path=nil, name='whatever')
@name = name
end
end
+
+ class TestResponse
+
+ def initialize (opts)
+
+ @path = opts[:path]
+ end
+
+ def request
+
+ r = Object.new
+ class << r
+ attr_accessor :path
+ end
+ r.path = @path
+ r
+ end
+ end
end

0 comments on commit 5a2f958

Please sign in to comment.