From c5252649c87b725028ffc86bf61313eae9d9b5f5 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Thu, 28 Mar 2013 00:34:49 +0900 Subject: [PATCH] Add some tests that fail to spot bugs. --- test/test_http_cookie.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index 40df7a3..944ca2f 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -177,6 +177,22 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal '.example.com', cookie.dot_domain end + def test_parse_public_suffix + cookie_str = 'a=b; domain=com' + + cookie = HTTP::Cookie.parse(cookie_str).first + assert_equal('com', cookie.domain) + assert_equal(false, cookie.for_domain?) + + cookie.origin = 'http://com/' + assert_equal('com', cookie.domain) + assert_equal(false, cookie.for_domain?) + + assert_raises(ArgumentError) { + cookie.origin = 'http://example.com/' + } + end + def test_parse_domain_none url = URI.parse('http://example.com/') @@ -664,6 +680,17 @@ class TestHTTPCookie < Test::Unit::TestCase } end + def test_acceptable_from_uri? + cookie = HTTP::Cookie.new(cookie_values( + :domain => 'uk', + :for_domain => true, + :origin => nil)) + assert_equal true, cookie.for_domain? + assert_equal true, cookie.acceptable_from_uri?('http://uk/') + assert_equal true, cookie.for_domain? # bug: acceptable_from_uri? changed it to false + assert_equal false, cookie.acceptable_from_uri?('http://foo.uk/') + end + def test_valid_for_uri? { HTTP::Cookie.parse('a1=b',