From e010e8f30eb564346cb92314a13f4c9b8ec5a679 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Thu, 18 Oct 2012 18:46:42 +0900 Subject: [PATCH] Add tests for valid_for_uri?. --- test/test_http_cookie.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index 94d412d..fa7c53b 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -515,5 +515,43 @@ class TestHTTPCookie < Test::Unit::TestCase cookie.origin = URI.parse('http://example.org/') } end + + def test_valid_for_uri? + cookie = HTTP::Cookie.parse('a=b', :origin => URI('http://example.com/dir/file.html')).first + assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir/test.html')) + assert_equal true, cookie.valid_for_uri?(URI('http://example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html')) + + cookie = HTTP::Cookie.parse('a=b; path=/dir2/', :origin => URI('http://example.com/dir/file.html')).first + assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir/test.html')) + assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html')) + assert_equal true, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html')) + + cookie = HTTP::Cookie.parse('a=b; domain=example.com; path=/dir2/', :origin => URI('http://example.com/dir/file.html')).first + assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir/test.html')) + assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html')) + assert_equal true, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html')) + assert_equal true, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html')) + assert_equal true, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html')) + + cookie = HTTP::Cookie.parse('a=b; secure', :origin => URI('https://example.com/dir/file.html')).first + assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html')) + assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html')) + end end