mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Rename HTTP::CookieJar#add! to HTTP::CookieJar#add removing the original #add.
This commit is contained in:
parent
a342680e4e
commit
95c702f99b
2 changed files with 80 additions and 91 deletions
|
|
@ -21,17 +21,8 @@ class HTTP::CookieJar
|
||||||
@jar = Marshal.load Marshal.dump other.jar
|
@jar = Marshal.load Marshal.dump other.jar
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a +cookie+ to the jar if it is considered acceptable from
|
|
||||||
# +uri+. Return nil if the cookie was not added, otherwise return
|
|
||||||
# the cookie added.
|
|
||||||
def add(uri, cookie)
|
|
||||||
return nil unless cookie.acceptable_from_uri?(uri)
|
|
||||||
add!(cookie)
|
|
||||||
cookie
|
|
||||||
end
|
|
||||||
|
|
||||||
# Add a +cookie+ to the jar and return self.
|
# Add a +cookie+ to the jar and return self.
|
||||||
def add!(cookie)
|
def add(cookie)
|
||||||
normal_domain = cookie.domain.downcase
|
normal_domain = cookie.domain.downcase
|
||||||
|
|
||||||
@jar[normal_domain] ||= {} unless @jar.has_key?(normal_domain)
|
@jar[normal_domain] ||= {} unless @jar.has_key?(normal_domain)
|
||||||
|
|
@ -41,7 +32,7 @@ class HTTP::CookieJar
|
||||||
|
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
alias << add!
|
alias << add
|
||||||
|
|
||||||
# Fetch the cookies that should be used for the URI object passed in.
|
# Fetch the cookies that should be used for the URI object passed in.
|
||||||
def cookies(url)
|
def cookies(url)
|
||||||
|
|
@ -179,7 +170,7 @@ class HTTP::CookieJar
|
||||||
c.expires = expires # Time the cookie expires.
|
c.expires = expires # Time the cookie expires.
|
||||||
c.version = 0 # Conforms to Netscape cookie spec.
|
c.version = 0 # Conforms to Netscape cookie spec.
|
||||||
|
|
||||||
add!(c)
|
add(c)
|
||||||
end
|
end
|
||||||
|
|
||||||
@jar
|
@jar
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
:path => '/',
|
:path => '/',
|
||||||
:expires => Time.now + (10 * 86400),
|
:expires => Time.now + (10 * 86400),
|
||||||
:for_domain => true,
|
:for_domain => true,
|
||||||
:domain => 'rubyforge.org'
|
:domain => 'rubyforge.org',
|
||||||
|
:origin => 'http://rubyforge.org/'
|
||||||
}.merge(options)
|
}.merge(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -28,8 +29,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
url = URI 'http://rubyforge.org/'
|
url = URI 'http://rubyforge.org/'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:path => '/onetwo')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:path => '/onetwo')))
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
assert_equal 2, @jar.cookies(URI('http://rubyforge.org/onetwo')).length
|
assert_equal 2, @jar.cookies(URI('http://rubyforge.org/onetwo')).length
|
||||||
|
|
@ -40,11 +41,10 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
@jar.add(url, HTTP::Cookie.new(
|
@jar.add(HTTP::Cookie.new(cookie_values(:domain => 'RuByForge.Org', :name => 'aaron')))
|
||||||
cookie_values(:domain => 'RuByForge.Org', :name => 'aaron')))
|
|
||||||
|
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_host_only
|
def test_host_only
|
||||||
url = URI.parse('http://rubyforge.org/')
|
url = URI.parse('http://rubyforge.org/')
|
||||||
|
|
||||||
@jar.add(url, HTTP::Cookie.new(
|
@jar.add(HTTP::Cookie.new(
|
||||||
cookie_values(:domain => 'rubyforge.org', :for_domain => false)))
|
cookie_values(:domain => 'rubyforge.org', :for_domain => false)))
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
@ -68,15 +68,15 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_empty_value
|
def test_empty_value
|
||||||
values = cookie_values(:value => "")
|
|
||||||
url = URI 'http://rubyforge.org/'
|
url = URI 'http://rubyforge.org/'
|
||||||
|
values = cookie_values(:value => "")
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(values)
|
cookie = HTTP::Cookie.new(values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
@jar.add url, HTTP::Cookie.new(values.merge(:domain => 'RuByForge.Org',
|
@jar.add HTTP::Cookie.new(values.merge(:domain => 'RuByForge.Org',
|
||||||
:name => 'aaron'))
|
:name => 'aaron'))
|
||||||
|
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
@ -90,11 +90,11 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Add the same cookie, and we should still only have one
|
# Add the same cookie, and we should still only have one
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values))
|
@jar.add(HTTP::Cookie.new(cookie_values))
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Make sure we can get the cookie from different paths
|
# Make sure we can get the cookie from different paths
|
||||||
|
|
@ -109,11 +109,11 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Add the same cookie, and we should still only have one
|
# Add the same cookie, and we should still only have one
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Make sure we can get the cookie from different paths
|
# Make sure we can get the cookie from different paths
|
||||||
|
|
@ -129,7 +129,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
cookies = [
|
cookies = [
|
||||||
{ :value => 'a', :path => '/', },
|
{ :value => 'a', :path => '/', },
|
||||||
{ :value => 'b', :path => '/abc/def/', :created_at => now - 1 },
|
{ :value => 'b', :path => '/abc/def/', :created_at => now - 1 },
|
||||||
{ :value => 'c', :path => '/abc/def/', :domain => 'www.rubyforge.org', :created_at => now },
|
{ :value => 'c', :path => '/abc/def/', :domain => 'www.rubyforge.org', :origin => 'http://www.rubyforge.org/abc/def/', :created_at => now },
|
||||||
{ :value => 'd', :path => '/abc/' },
|
{ :value => 'd', :path => '/abc/' },
|
||||||
].map { |attrs|
|
].map { |attrs|
|
||||||
HTTP::Cookie.new(cookie_values(attrs))
|
HTTP::Cookie.new(cookie_values(attrs))
|
||||||
|
|
@ -139,7 +139,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
|
|
||||||
cookies.permutation(cookies.size) { |shuffled|
|
cookies.permutation(cookies.size) { |shuffled|
|
||||||
@jar.clear
|
@jar.clear
|
||||||
shuffled.each { |cookie| @jar.add(url, cookie) }
|
shuffled.each { |cookie| @jar.add(cookie) }
|
||||||
assert_equal %w[b c d a], @jar.cookies(url).map { |cookie| cookie.value }
|
assert_equal %w[b c d a], @jar.cookies(url).map { |cookie| cookie.value }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -156,8 +156,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_add_makes_exception_for_localhost
|
def test_add_makes_exception_for_localhost
|
||||||
url = URI 'http://localhost'
|
url = URI 'http://localhost'
|
||||||
|
|
||||||
tld_cookie = HTTP::Cookie.new(cookie_values(:domain => 'localhost'))
|
tld_cookie = HTTP::Cookie.new(cookie_values(:domain => 'localhost', :origin => url))
|
||||||
@jar.add(url, tld_cookie)
|
@jar.add(tld_cookie)
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -165,8 +165,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_add_cookie_for_the_parent_domain
|
def test_add_cookie_for_the_parent_domain
|
||||||
url = URI 'http://x.foo.com'
|
url = URI 'http://x.foo.com'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(cookie_values(:domain => '.foo.com'))
|
cookie = HTTP::Cookie.new(cookie_values(:domain => '.foo.com', :origin => url))
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -174,8 +174,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_add_does_not_reject_cookies_from_a_nested_subdomain
|
def test_add_does_not_reject_cookies_from_a_nested_subdomain
|
||||||
url = URI 'http://y.x.foo.com'
|
url = URI 'http://y.x.foo.com'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(cookie_values(:domain => '.foo.com'))
|
cookie = HTTP::Cookie.new(cookie_values(:domain => '.foo.com', :origin => url))
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -184,7 +184,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
url = URI 'http://arubyforge.org/'
|
url = URI 'http://arubyforge.org/'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(cookie_values(:domain => 'rubyforge.org'))
|
cookie = HTTP::Cookie.new(cookie_values(:domain => 'rubyforge.org'))
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
|
|
||||||
assert_equal(0, @jar.cookies(url).length)
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -192,8 +192,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_cookie_without_leading_dot_matches_subdomains
|
def test_cookie_without_leading_dot_matches_subdomains
|
||||||
url = URI 'http://admin.rubyforge.org/'
|
url = URI 'http://admin.rubyforge.org/'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(cookie_values(:domain => 'rubyforge.org'))
|
cookie = HTTP::Cookie.new(cookie_values(:domain => 'rubyforge.org', :origin => url))
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -201,7 +201,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_cookies_with_leading_dot_match_subdomains
|
def test_cookies_with_leading_dot_match_subdomains
|
||||||
url = URI 'http://admin.rubyforge.org/'
|
url = URI 'http://admin.rubyforge.org/'
|
||||||
|
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:domain => '.rubyforge.org')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:domain => '.rubyforge.org', :origin => url)))
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -209,7 +209,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_cookies_with_leading_dot_match_parent_domains
|
def test_cookies_with_leading_dot_match_parent_domains
|
||||||
url = URI 'http://rubyforge.org/'
|
url = URI 'http://rubyforge.org/'
|
||||||
|
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:domain => '.rubyforge.org')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:domain => '.rubyforge.org', :origin => url)))
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -217,7 +217,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_cookies_with_leading_dot_match_parent_domains_exactly
|
def test_cookies_with_leading_dot_match_parent_domains_exactly
|
||||||
url = URI 'http://arubyforge.org/'
|
url = URI 'http://arubyforge.org/'
|
||||||
|
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:domain => '.rubyforge.org')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:domain => '.rubyforge.org')))
|
||||||
|
|
||||||
assert_equal(0, @jar.cookies(url).length)
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -225,8 +225,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_cookie_for_ipv4_address_matches_the_exact_ipaddress
|
def test_cookie_for_ipv4_address_matches_the_exact_ipaddress
|
||||||
url = URI 'http://192.168.0.1/'
|
url = URI 'http://192.168.0.1/'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(cookie_values(:domain => '192.168.0.1'))
|
cookie = HTTP::Cookie.new(cookie_values(:domain => '192.168.0.1', :origin => url))
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -234,8 +234,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_cookie_for_ipv6_address_matches_the_exact_ipaddress
|
def test_cookie_for_ipv6_address_matches_the_exact_ipaddress
|
||||||
url = URI 'http://[fe80::0123:4567:89ab:cdef]/'
|
url = URI 'http://[fe80::0123:4567:89ab:cdef]/'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(cookie_values(:domain => '[fe80::0123:4567:89ab:cdef]'))
|
cookie = HTTP::Cookie.new(cookie_values(:domain => '[fe80::0123:4567:89ab:cdef]', :origin => url))
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -243,8 +243,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_cookies_dot
|
def test_cookies_dot
|
||||||
url = URI 'http://www.host.example/'
|
url = URI 'http://www.host.example/'
|
||||||
|
|
||||||
@jar.add(url,
|
@jar.add(HTTP::Cookie.new(cookie_values(:domain => 'www.host.example', :origin => url)))
|
||||||
HTTP::Cookie.new(cookie_values(:domain => 'www.host.example')))
|
|
||||||
|
|
||||||
url = URI 'http://wwwxhost.example/'
|
url = URI 'http://wwwxhost.example/'
|
||||||
assert_equal(0, @jar.cookies(url).length)
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
|
|
@ -254,9 +253,9 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
url = URI 'http://rubyforge.org/'
|
url = URI 'http://rubyforge.org/'
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values(:origin => url))
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:name => 'Baz', :origin => url)))
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
||||||
@jar.clear
|
@jar.clear
|
||||||
|
|
@ -268,14 +267,15 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
url = URI 'http://rubyforge.org/'
|
url = URI 'http://rubyforge.org/'
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values(:origin => url))
|
||||||
s_cookie = HTTP::Cookie.new(cookie_values(:name => 'Bar',
|
s_cookie = HTTP::Cookie.new(cookie_values(:name => 'Bar',
|
||||||
:expires => nil,
|
:expires => nil,
|
||||||
:session => true))
|
:session => true,
|
||||||
|
:origin => url))
|
||||||
|
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
@jar.add(url, s_cookie)
|
@jar.add(s_cookie)
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:name => 'Baz', :for_domain => false)))
|
@jar.add(HTTP::Cookie.new(cookie_values(:name => 'Baz', :for_domain => false, :origin => url)))
|
||||||
|
|
||||||
assert_equal(3, @jar.cookies(url).length)
|
assert_equal(3, @jar.cookies(url).length)
|
||||||
|
|
||||||
|
|
@ -305,9 +305,9 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
:expires => nil,
|
:expires => nil,
|
||||||
:session => true))
|
:session => true))
|
||||||
|
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
@jar.add(url, s_cookie)
|
@jar.add(s_cookie)
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
||||||
|
|
||||||
assert_equal(3, @jar.cookies(url).length)
|
assert_equal(3, @jar.cookies(url).length)
|
||||||
|
|
||||||
|
|
@ -332,9 +332,9 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
:expires => nil,
|
:expires => nil,
|
||||||
:session => true))
|
:session => true))
|
||||||
|
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
@jar.add(url, s_cookie)
|
@jar.add(s_cookie)
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
||||||
|
|
||||||
assert_equal(3, @jar.cookies(url).length)
|
assert_equal(3, @jar.cookies(url).length)
|
||||||
|
|
||||||
|
|
@ -354,24 +354,22 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Add a second cookie
|
# Add a second cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Make sure we can get the cookie from different paths
|
# Make sure we can get the cookie from different paths
|
||||||
assert_equal(2, @jar.cookies(URI('http://rubyforge.org/login')).length)
|
assert_equal(2, @jar.cookies(URI('http://rubyforge.org/login')).length)
|
||||||
|
|
||||||
# Expire the first cookie
|
# Expire the first cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(
|
@jar.add(HTTP::Cookie.new(cookie_values(:expires => Time.now - (10 * 86400))))
|
||||||
cookie_values(:expires => Time.now - (10 * 86400))))
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Expire the second cookie
|
# Expire the second cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(
|
@jar.add(HTTP::Cookie.new(cookie_values( :name => 'Baz', :expires => Time.now - (10 * 86400))))
|
||||||
cookie_values( :name => 'Baz', :expires => Time.now - (10 * 86400))))
|
|
||||||
assert_equal(0, @jar.cookies(url).length)
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -381,23 +379,22 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(values)
|
cookie = HTTP::Cookie.new(values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Add a second cookie
|
# Add a second cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(values.merge(:name => 'Baz')))
|
@jar.add(HTTP::Cookie.new(values.merge(:name => 'Baz')))
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Make sure we can get the cookie from different paths
|
# Make sure we can get the cookie from different paths
|
||||||
assert_equal(2, @jar.cookies(URI('http://rubyforge.org/login')).length)
|
assert_equal(2, @jar.cookies(URI('http://rubyforge.org/login')).length)
|
||||||
|
|
||||||
# Expire the first cookie
|
# Expire the first cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(values.merge(:expires => Time.now - (10 * 86400))))
|
@jar.add(HTTP::Cookie.new(values.merge(:expires => Time.now - (10 * 86400))))
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Expire the second cookie
|
# Expire the second cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(
|
@jar.add(HTTP::Cookie.new(values.merge(:name => 'Baz', :expires => Time.now - (10 * 86400))))
|
||||||
values.merge(:name => 'Baz', :expires => Time.now - (10 * 86400))))
|
|
||||||
assert_equal(0, @jar.cookies(url).length)
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
|
|
||||||
# When given a URI with a blank path, CookieJar#cookies should return
|
# When given a URI with a blank path, CookieJar#cookies should return
|
||||||
|
|
@ -406,22 +403,21 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
assert_equal '', url.path
|
assert_equal '', url.path
|
||||||
assert_equal(0, @jar.cookies(url).length)
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
# Now add a cookie with the path set to '/':
|
# Now add a cookie with the path set to '/':
|
||||||
@jar.add(url, HTTP::Cookie.new(values.merge( :name => 'has_root_path',
|
@jar.add(HTTP::Cookie.new(values.merge(:name => 'has_root_path', :path => '/')))
|
||||||
:path => '/')))
|
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_paths
|
def test_paths
|
||||||
values = cookie_values(:path => "/login", :expires => nil)
|
|
||||||
url = URI 'http://rubyforge.org/login'
|
url = URI 'http://rubyforge.org/login'
|
||||||
|
values = cookie_values(:path => "/login", :expires => nil, :origin => url)
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(values)
|
cookie = HTTP::Cookie.new(values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Add a second cookie
|
# Add a second cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(values.merge( :name => 'Baz' )))
|
@jar.add(HTTP::Cookie.new(values.merge( :name => 'Baz' )))
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Make sure we don't get the cookie in a different path
|
# Make sure we don't get the cookie in a different path
|
||||||
|
|
@ -429,11 +425,11 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
assert_equal(0, @jar.cookies(URI('http://rubyforge.org/')).length)
|
assert_equal(0, @jar.cookies(URI('http://rubyforge.org/')).length)
|
||||||
|
|
||||||
# Expire the first cookie
|
# Expire the first cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(values.merge( :expires => Time.now - (10 * 86400))))
|
@jar.add(HTTP::Cookie.new(values.merge( :expires => Time.now - (10 * 86400))))
|
||||||
assert_equal(1, @jar.cookies(url).length)
|
assert_equal(1, @jar.cookies(url).length)
|
||||||
|
|
||||||
# Expire the second cookie
|
# Expire the second cookie
|
||||||
@jar.add(url, HTTP::Cookie.new(values.merge( :name => 'Baz',
|
@jar.add(HTTP::Cookie.new(values.merge( :name => 'Baz',
|
||||||
:expires => Time.now - (10 * 86400))))
|
:expires => Time.now - (10 * 86400))))
|
||||||
assert_equal(0, @jar.cookies(url).length)
|
assert_equal(0, @jar.cookies(url).length)
|
||||||
end
|
end
|
||||||
|
|
@ -443,8 +439,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
|
|
||||||
# Add one cookie with an expiration date in the future
|
# Add one cookie with an expiration date in the future
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
@jar.add(HTTP::Cookie.new(cookie_values(:name => 'Baz')))
|
||||||
assert_equal(2, @jar.cookies(url).length)
|
assert_equal(2, @jar.cookies(url).length)
|
||||||
|
|
||||||
in_tmpdir do
|
in_tmpdir do
|
||||||
|
|
@ -460,7 +456,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
def test_save_and_read_cookiestxt_with_session_cookies
|
def test_save_and_read_cookiestxt_with_session_cookies
|
||||||
url = URI 'http://rubyforge.org/'
|
url = URI 'http://rubyforge.org/'
|
||||||
|
|
||||||
@jar.add(url, HTTP::Cookie.new(cookie_values(:expires => nil)))
|
@jar.add(HTTP::Cookie.new(cookie_values(:expires => nil)))
|
||||||
|
|
||||||
in_tmpdir do
|
in_tmpdir do
|
||||||
@jar.save_as("cookies.txt", :cookiestxt)
|
@jar.save_as("cookies.txt", :cookiestxt)
|
||||||
|
|
@ -479,7 +475,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
@jar.jar['rubyforge.org'] = {}
|
@jar.jar['rubyforge.org'] = {}
|
||||||
|
|
||||||
|
|
||||||
@jar.add url, HTTP::Cookie.new(cookie_values)
|
@jar.add HTTP::Cookie.new(cookie_values)
|
||||||
|
|
||||||
# HACK no asertion
|
# HACK no asertion
|
||||||
end
|
end
|
||||||
|
|
@ -491,11 +487,11 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
url = URI 'https://rubyforge.org/login'
|
url = URI 'https://rubyforge.org/login'
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(values)
|
cookie = HTTP::Cookie.new(values)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(1, @jar.cookies(url).length, "did not handle SSL cookie")
|
assert_equal(1, @jar.cookies(url).length, "did not handle SSL cookie")
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new(values_ssl)
|
cookie = HTTP::Cookie.new(values_ssl)
|
||||||
@jar.add(url, cookie)
|
@jar.add(cookie)
|
||||||
assert_equal(2, @jar.cookies(url).length, "did not handle SSL cookie with :443")
|
assert_equal(2, @jar.cookies(url).length, "did not handle SSL cookie with :443")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -503,13 +499,15 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
nurl = URI 'http://rubyforge.org/login'
|
nurl = URI 'http://rubyforge.org/login'
|
||||||
surl = URI 'https://rubyforge.org/login'
|
surl = URI 'https://rubyforge.org/login'
|
||||||
|
|
||||||
ncookie = HTTP::Cookie.new(cookie_values(:name => 'Foo1'))
|
nncookie = HTTP::Cookie.new(cookie_values(:name => 'Foo1', :origin => nurl))
|
||||||
scookie = HTTP::Cookie.new(cookie_values(:name => 'Foo2', :secure => true))
|
sncookie = HTTP::Cookie.new(cookie_values(:name => 'Foo1', :origin => surl))
|
||||||
|
nscookie = HTTP::Cookie.new(cookie_values(:name => 'Foo2', :secure => true, :origin => nurl))
|
||||||
|
sscookie = HTTP::Cookie.new(cookie_values(:name => 'Foo2', :secure => true, :origin => surl))
|
||||||
|
|
||||||
@jar.add(nurl, ncookie)
|
@jar.add(nncookie)
|
||||||
@jar.add(nurl, scookie)
|
@jar.add(sncookie)
|
||||||
@jar.add(surl, ncookie)
|
@jar.add(nscookie)
|
||||||
@jar.add(surl, scookie)
|
@jar.add(sscookie)
|
||||||
|
|
||||||
assert_equal('Foo1', @jar.cookies(nurl).map { |c| c.name }.sort.join(' ') )
|
assert_equal('Foo1', @jar.cookies(nurl).map { |c| c.name }.sort.join(' ') )
|
||||||
assert_equal('Foo1 Foo2', @jar.cookies(surl).map { |c| c.name }.sort.join(' ') )
|
assert_equal('Foo1 Foo2', @jar.cookies(surl).map { |c| c.name }.sort.join(' ') )
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue