test/test_http_cookie.rb in http-cookie-1.0.0.pre9 vs test/test_http_cookie.rb in http-cookie-1.0.0.pre10

- old
+ new

@@ -100,11 +100,10 @@ uri = URI.parse 'http://example' assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie| assert_equal 'quoted', cookie.name assert_equal 'value', cookie.value - assert_equal 'comment is "comment"', cookie.comment }.size end def test_parse_weird_cookie cookie = 'n/a, ASPSESSIONIDCSRRQDQR=FBLDGHPBNDJCPCGNCPAENELB; path=/' @@ -124,18 +123,23 @@ }.size end def test_parse_bad_version bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Version=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;' - url = URI.parse('http://localhost/') - assert_equal 0, HTTP::Cookie.parse(bad_cookie, url).size + url = URI.parse('http://192.168.6.196/') + # The version attribute is obsolete and simply ignored + cookies = HTTP::Cookie.parse(bad_cookie, url) + assert_equal 1, cookies.size end def test_parse_bad_max_age - bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;' - url = URI.parse('http://localhost/') - assert_equal 0, HTTP::Cookie.parse(bad_cookie, url).size + bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=forever; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;' + url = URI.parse('http://192.168.6.196/') + # A bad max-age is simply ignored + cookies = HTTP::Cookie.parse(bad_cookie, url) + assert_equal 1, cookies.size + assert_equal nil, cookies.first.max_age end def test_parse_date_fail url = URI.parse('http://localhost/') @@ -578,9 +582,31 @@ assert_equal false, cookie.expired? assert_equal true, cookie.expired?(cookie.expires + 1) assert_equal false, cookie.expired?(cookie.expires - 1) cookie.expire! assert_equal true, cookie.expired? + end + + def test_max_age= + cookie = HTTP::Cookie.new(cookie_values) + + assert_raises(ArgumentError) { + cookie.max_age = "+1" + } + assert_raises(ArgumentError) { + cookie.max_age = "1.5" + } + assert_raises(ArgumentError) { + cookie.max_age = "1 day" + } + assert_raises(TypeError) { + cookie.max_age = [1] + } + cookie.max_age = "12" + assert_equal 12, cookie.max_age + + cookie.max_age = -3 + assert_equal -3, cookie.max_age end def test_session cookie = HTTP::Cookie.new(cookie_values)