Fix and move some tests from test_http_cookie_jar.rb to test_http_cookie.rb.

This commit is contained in:
Akinori MUSHA 2012-10-22 02:38:08 +09:00
parent d2f31d90b5
commit a342680e4e
2 changed files with 43 additions and 27 deletions

View file

@ -465,6 +465,47 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal true, cookie.for_domain?
end
def cookie_values(options = {})
{
:name => 'Foo',
:value => 'Bar',
:path => '/',
:expires => Time.now + (10 * 86400),
:for_domain => true,
:domain => 'rubyforge.org',
:origin => 'http://rubyforge.org/'
}.merge(options)
end
def test_new_rejects_cookies_that_do_not_contain_an_embedded_dot
url = URI 'http://rubyforge.org/'
assert_raises(ArgumentError) {
tld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.org', :origin => url))
}
assert_raises(ArgumentError) {
single_dot_cookie = HTTP::Cookie.new(cookie_values(:domain => '.', :origin => url))
}
end
def test_fall_back_rules_for_local_domains
url = URI 'http://www.example.local'
assert_raises(ArgumentError) {
tld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.local', :origin => url))
}
sld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.example.local', :origin => url))
end
def test_new_rejects_cookies_with_ipv4_address_subdomain
url = URI 'http://192.168.0.1/'
assert_raises(ArgumentError) {
cookie = HTTP::Cookie.new(cookie_values(:domain => '.0.1', :origin => url))
}
end
def test_domain_nil
cookie = HTTP::Cookie.parse('a=b').first
assert_raises(RuntimeError) {

View file

@ -144,27 +144,11 @@ class TestHTTPCookieJar < Test::Unit::TestCase
}
end
def test_add_rejects_cookies_that_do_not_contain_an_embedded_dot
url = URI 'http://rubyforge.org/'
tld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.org'))
@jar.add(url, tld_cookie)
single_dot_cookie = HTTP::Cookie.new(cookie_values(:domain => '.'))
@jar.add(url, single_dot_cookie)
assert_equal(0, @jar.cookies(url).length)
end
def test_fall_back_rules_for_local_domains
url = URI 'http://www.example.local'
tld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.local'))
@jar.add(url, tld_cookie)
assert_equal(0, @jar.cookies(url).length)
sld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.example.local'))
@jar.add(url, sld_cookie)
sld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.example.local', :origin => url))
@jar.add(sld_cookie)
assert_equal(1, @jar.cookies(url).length)
end
@ -247,15 +231,6 @@ class TestHTTPCookieJar < Test::Unit::TestCase
assert_equal(1, @jar.cookies(url).length)
end
def test_cookie_for_ipv4_address_does_not_cause_subdomain_match
url = URI 'http://192.168.0.1/'
cookie = HTTP::Cookie.new(cookie_values(:domain => '.0.1'))
@jar.add(url, cookie)
assert_equal(0, @jar.cookies(url).length)
end
def test_cookie_for_ipv6_address_matches_the_exact_ipaddress
url = URI 'http://[fe80::0123:4567:89ab:cdef]/'