Skip to content

Commit

Permalink
bug #19234 : cookie path checking broken - Fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Apr 1, 2008
1 parent 5e6ec3b commit 5a2f958
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


== rufus-verbs - 0.9 released 2008/04/xx == rufus-verbs - 0.9 released 2008/04/xx


- bug #19234 : cookie path checking broken - Fixed.
- todo #19202 : EndPoint.cookies now readable - todo #19202 : EndPoint.cookies now readable
- bug #19201 : :params not respected when specified in request - bug #19201 : :params not respected when specified in request
- todo #19200 : added verbose mode (:v / :verbose) - todo #19200 : added verbose mode (:v / :verbose)
Expand Down
8 changes: 5 additions & 3 deletions lib/rufus/verbs/cookies.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def register_cookies (response, opts)
path = opts[:path] path = opts[:path]
cpath = c.path || "/" cpath = c.path || "/"


next unless cookie_acceptable?(opts, c) next unless cookie_acceptable?(opts, response, c)


domain = c.domain || host domain = c.domain || host


Expand All @@ -124,7 +124,7 @@ def register_cookies (response, opts)
# Checks if the cookie is acceptable in the context of # Checks if the cookie is acceptable in the context of
# the request that sent it. # the request that sent it.
# #
def cookie_acceptable? (opts, cookie) def cookie_acceptable? (opts, response, cookie)


# reject if : # reject if :
# #
Expand All @@ -149,7 +149,9 @@ def cookie_acceptable? (opts, cookie)
return false if d != cdomain return false if d != cdomain
end end


path = opts[:path] #path = opts[:path]
path = response.request.path

cpath = cookie.path || "/" cpath = cookie.path || "/"


return false if path[0..cpath.length-1] != cpath return false if path[0..cpath.length-1] != cpath
Expand Down
33 changes: 28 additions & 5 deletions test/cookie0_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,32 +65,37 @@ def test_2


opts = { :host => 'rufus.rubyforge.org', :path => '/' } opts = { :host => 'rufus.rubyforge.org', :path => '/' }
c = TestCookie.new '.rubyforge.org', '/' 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 # * The value for the Domain attribute contains no embedded dots
# or does not start with a dot. # or does not start with a dot.


opts = { :host => 'rufus.rubyforge.org', :path => '/' } opts = { :host => 'rufus.rubyforge.org', :path => '/' }
c = TestCookie.new 'rufus.rubyforge.org', '/' 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 => '/' } opts = { :host => 'rufus.rubyforge.org', :path => '/' }
c = TestCookie.new 'org', '/' 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 # * The value for the Path attribute is not a prefix of the
# request-URI. # request-URI.


opts = { :host => 'rufus.rubyforge.org', :path => '/this' } opts = { :host => 'rufus.rubyforge.org', :path => '/this' }
c = TestCookie.new '.rubyforge.org', '/that' 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 # * The value for the request-host does not domain-match the
# Domain attribute. # Domain attribute.


opts = { :host => 'rufus.rubyforg.org', :path => '/' } opts = { :host => 'rufus.rubyforg.org', :path => '/' }
c = TestCookie.new '.rubyforge.org', '/' 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 # * 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 # HD, where D is the value of the Domain attribute, and H is a
Expand Down Expand Up @@ -119,4 +124,22 @@ def initialize (domain=nil, path=nil, name='whatever')
@name = name @name = name
end end
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 end

0 comments on commit 5a2f958

Please sign in to comment.