Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
remove warnings about ==
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Jan 31, 2014
1 parent b07c538 commit aa1f319
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 73 deletions.
44 changes: 22 additions & 22 deletions spec/cookie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,41 @@
end
it "should give back the input names and values" do
cookie = Cookie.from_set_cookie 'http://localhost/', 'foo=bar'
cookie.name.should == 'foo'
cookie.value.should == 'bar'
cookie.name.should eq 'foo'
cookie.value.should eq 'bar'
end
it "should normalize domain names" do
cookie = Cookie.from_set_cookie 'http://localhost/', 'foo=Bar;domain=LoCaLHoSt.local'
cookie.domain.should == '.localhost.local'
cookie.domain.should eq '.localhost.local'
end
it "should accept non-normalized .local" do
cookie = Cookie.from_set_cookie 'http://localhost/', 'foo=bar;domain=.local'
cookie.domain.should == '.local'
cookie.domain.should eq '.local'
end
it "should accept secure cookies" do
cookie = Cookie.from_set_cookie 'https://www.google.com/a/blah', 'GALX=RgmSftjnbPM;Path=/a/;Secure'
cookie.name.should == 'GALX'
cookie.name.should eq 'GALX'
cookie.secure.should be_true
end
end
describe "#from_set_cookie2" do
it "should give back the input names and values" do
cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo=bar;Version=1'
cookie.name.should == 'foo'
cookie.value.should == 'bar'
cookie.name.should eq 'foo'
cookie.value.should eq 'bar'
end
it "should normalize domain names" do
cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo=Bar;domain=LoCaLHoSt.local;Version=1'
cookie.domain.should == '.localhost.local'
cookie.domain.should eq '.localhost.local'
end
it "should accept non-normalized .local" do
cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo=bar;domain=.local;Version=1'
cookie.domain.should == '.local'
cookie.domain.should eq '.local'
end
it "should accept secure cookies" do
cookie = Cookie.from_set_cookie2 'https://www.google.com/a/blah', 'GALX=RgmSftjnbPM;Path="/a/";Secure;Version=1'
cookie.name.should == 'GALX'
cookie.path.should == '/a/'
cookie.name.should eq 'GALX'
cookie.path.should eq '/a/'
cookie.secure.should be_true
end
it "should fail on unquoted paths" do
Expand All @@ -72,13 +72,13 @@
end
it "should accept quoted values" do
cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo="bar";Version=1'
cookie.name.should == 'foo'
cookie.value.should == '"bar"'
cookie.name.should eq 'foo'
cookie.value.should eq '"bar"'
end
it "should accept poorly chosen names" do
cookie = Cookie.from_set_cookie2 'http://localhost/', 'Version=mine;Version=1'
cookie.name.should == 'Version'
cookie.value.should == 'mine'
cookie.name.should eq 'Version'
cookie.value.should eq 'mine'
end
it "should accept quoted parameter values" do
Cookie.from_set_cookie2 'http://localhost/', 'foo=bar;Version="1"'
Expand Down Expand Up @@ -117,25 +117,25 @@
describe '#to_s' do
it "should handle a simple cookie" do
cookie = Cookie.from_set_cookie 'http://localhost/', 'f=b'
cookie.to_s.should == 'f=b'
cookie.to_s(1).should == '$Version=0;f=b;$Path="/"'
cookie.to_s.should eq 'f=b'
cookie.to_s(1).should eq '$Version=0;f=b;$Path="/"'
end
it "should report an explicit domain" do
cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;Version=1;Domain=.local'
cookie.to_s(1).should == '$Version=1;f=b;$Path="/";$Domain=.local'
cookie.to_s(1).should eq '$Version=1;f=b;$Path="/";$Domain=.local'
end
it "should return specified ports" do
cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;Version=1;Port="80,443"'
cookie.to_s(1).should == '$Version=1;f=b;$Path="/";$Port="80,443"'
cookie.to_s(1).should eq '$Version=1;f=b;$Path="/";$Port="80,443"'
end
it "should handle specified paths" do
cookie = Cookie.from_set_cookie 'http://localhost/bar/', 'f=b;path=/bar/'
cookie.to_s.should == 'f=b'
cookie.to_s(1).should == '$Version=0;f=b;$Path="/bar/"'
cookie.to_s.should eq 'f=b'
cookie.to_s(1).should eq '$Version=0;f=b;$Path="/bar/"'
end
it "should omit $Version header when asked" do
cookie = Cookie.from_set_cookie 'http://localhost/', 'f=b'
cookie.to_s(1,false).should == 'f=b;$Path="/"'
cookie.to_s(1,false).should eq 'f=b;$Path="/"'
end
end
describe '#should_send?' do
Expand Down
81 changes: 38 additions & 43 deletions spec/cookie_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,119 +85,114 @@
end
describe '#cookie_base_path' do
it "should leave '/' alone" do
CookieValidation.cookie_base_path('/').should == '/'
CookieValidation.cookie_base_path('/').should eq '/'
end
it "should strip off everything after the last '/'" do
CookieValidation.cookie_base_path('/foo/bar/baz').should == '/foo/bar/'
CookieValidation.cookie_base_path('/foo/bar/baz').should eq '/foo/bar/'
end
it "should handle query parameters and fragments with slashes" do
CookieValidation.cookie_base_path('/foo/bar?query=a/b/c#fragment/b/c').should == '/foo/'
CookieValidation.cookie_base_path('/foo/bar?query=a/b/c#fragment/b/c').should eq '/foo/'
end
it "should handle URI objects" do
CookieValidation.cookie_base_path(URI.parse('http://www.foo.com/bar/')).should == '/bar/'
CookieValidation.cookie_base_path(URI.parse('http://www.foo.com/bar/')).should eq '/bar/'
end
it "should preserve case" do
CookieValidation.cookie_base_path("/BaR/").should == '/BaR/'
CookieValidation.cookie_base_path("/BaR/").should eq '/BaR/'
end
end
describe '#determine_cookie_path' do
it "should use the requested path when none is specified for the cookie" do
CookieValidation.determine_cookie_path('http://foo.com/', nil).should == '/'
CookieValidation.determine_cookie_path('http://foo.com/bar/baz', '').should == '/bar/'
CookieValidation.determine_cookie_path('http://foo.com/', nil).should eq '/'
CookieValidation.determine_cookie_path('http://foo.com/bar/baz', '').should eq '/bar/'
end
it "should handle URI objects" do
CookieValidation.determine_cookie_path(URI.parse('http://foo.com/bar/'), '').should == '/bar/'
CookieValidation.determine_cookie_path(URI.parse('http://foo.com/bar/'), '').should eq '/bar/'
end
it "should handle Cookie objects" do
cookie = Cookie.from_set_cookie('http://foo.com/', "name=value;path=/")
CookieValidation.determine_cookie_path('http://foo.com/', cookie).should == '/'
CookieValidation.determine_cookie_path('http://foo.com/', cookie).should eq '/'
end
it "should ignore the request when a path is specified" do
CookieValidation.determine_cookie_path('http://foo.com/ignorable/path', '/path/').should == '/path/'
CookieValidation.determine_cookie_path('http://foo.com/ignorable/path', '/path/').should eq '/path/'
end
end
describe '#compute_search_domains' do
it "should handle subdomains" do
CookieValidation.compute_search_domains('http://www.auth.foo.com/').should ==
['www.auth.foo.com', '.www.auth.foo.com', '.auth.foo.com']
CookieValidation.compute_search_domains('http://www.auth.foo.com/').should eq ['www.auth.foo.com', '.www.auth.foo.com', '.auth.foo.com']
end
it "should handle root domains" do
CookieValidation.compute_search_domains('http://foo.com/').should ==
['foo.com', '.foo.com']
CookieValidation.compute_search_domains('http://foo.com/').should eq ['foo.com', '.foo.com']
end
it "should handle hexadecimal TLDs" do
CookieValidation.compute_search_domains('http://tiny.cc/').should ==
['tiny.cc', '.tiny.cc']
CookieValidation.compute_search_domains('http://tiny.cc/').should eq ['tiny.cc', '.tiny.cc']
end
it "should handle IP addresses" do
CookieValidation.compute_search_domains('http://127.0.0.1/').should ==
['127.0.0.1']
CookieValidation.compute_search_domains('http://127.0.0.1/').should eq ['127.0.0.1']
end
it "should handle local addresses" do
CookieValidation.compute_search_domains('http://zero/').should ==
['zero.local', '.zero.local', '.local']
CookieValidation.compute_search_domains('http://zero/').should eq ['zero.local', '.zero.local', '.local']
end
end
describe '#determine_cookie_domain' do
it "should add a dot to the front of domains" do
CookieValidation.determine_cookie_domain('http://foo.com/', 'foo.com').should == '.foo.com'
CookieValidation.determine_cookie_domain('http://foo.com/', 'foo.com').should eq '.foo.com'
end
it "should not add a second dot if one present" do
CookieValidation.determine_cookie_domain('http://foo.com/', '.foo.com').should == '.foo.com'
CookieValidation.determine_cookie_domain('http://foo.com/', '.foo.com').should eq '.foo.com'
end
it "should handle Cookie objects" do
c = Cookie.from_set_cookie('http://foo.com/', "foo=bar;domain=foo.com")
CookieValidation.determine_cookie_domain('http://foo.com/', c).should == '.foo.com'
CookieValidation.determine_cookie_domain('http://foo.com/', c).should eq '.foo.com'
end
it "should handle URI objects" do
CookieValidation.determine_cookie_domain(URI.parse('http://foo.com/'), '.foo.com').should == '.foo.com'
CookieValidation.determine_cookie_domain(URI.parse('http://foo.com/'), '.foo.com').should eq '.foo.com'
end
it "should use an exact hostname when no domain specified" do
CookieValidation.determine_cookie_domain('http://foo.com/', '').should == 'foo.com'
CookieValidation.determine_cookie_domain('http://foo.com/', '').should eq 'foo.com'
end
it "should leave IPv4 addresses alone" do
CookieValidation.determine_cookie_domain('http://127.0.0.1/', '127.0.0.1').should == '127.0.0.1'
CookieValidation.determine_cookie_domain('http://127.0.0.1/', '127.0.0.1').should eq '127.0.0.1'
end
it "should leave IPv6 addresses alone" do
['2001:db8:85a3::8a2e:370:7334', '::ffff:192.0.2.128'].each do |value|
CookieValidation.determine_cookie_domain("http://[#{value}]/", value).should == value
CookieValidation.determine_cookie_domain("http://[#{value}]/", value).should eq value
end
end
end
describe "#effective_host" do
it "should leave proper domains the same" do
['google.com', 'www.google.com', 'google.com.'].each do |value|
CookieValidation.effective_host(value).should == value
CookieValidation.effective_host(value).should eq value
end
end
it "should handle a URI object" do
CookieValidation.effective_host(URI.parse('http://example.com/')).should == 'example.com'
CookieValidation.effective_host(URI.parse('http://example.com/')).should eq 'example.com'
end
it "should add a local suffix on unqualified hosts" do
CookieValidation.effective_host('localhost').should == 'localhost.local'
CookieValidation.effective_host('localhost').should eq 'localhost.local'
end
it "should leave IPv4 addresses alone" do
CookieValidation.effective_host('127.0.0.1').should == '127.0.0.1'
CookieValidation.effective_host('127.0.0.1').should eq '127.0.0.1'
end
it "should leave IPv6 addresses alone" do
['2001:db8:85a3::8a2e:370:7334', ':ffff:192.0.2.128'].each do |value|
CookieValidation.effective_host(value).should == value
CookieValidation.effective_host(value).should eq value
end
end
it "should lowercase addresses" do
CookieValidation.effective_host('FOO.COM').should == 'foo.com'
CookieValidation.effective_host('FOO.COM').should eq 'foo.com'
end
end
describe '#match_domains' do
it "should handle exact matches" do
CookieValidation.domains_match('localhost.local', 'localhost.local').should == 'localhost.local'
CookieValidation.domains_match('foo.com', 'foo.com').should == 'foo.com'
CookieValidation.domains_match('127.0.0.1', '127.0.0.1').should == '127.0.0.1'
CookieValidation.domains_match('::ffff:192.0.2.128', '::ffff:192.0.2.128').should == '::ffff:192.0.2.128'
CookieValidation.domains_match('localhost.local', 'localhost.local').should eq 'localhost.local'
CookieValidation.domains_match('foo.com', 'foo.com').should eq 'foo.com'
CookieValidation.domains_match('127.0.0.1', '127.0.0.1').should eq '127.0.0.1'
CookieValidation.domains_match('::ffff:192.0.2.128', '::ffff:192.0.2.128').should eq '::ffff:192.0.2.128'
end
it "should handle matching a superdomain" do
CookieValidation.domains_match('.foo.com', 'auth.foo.com').should == '.foo.com'
CookieValidation.domains_match('.y.z.foo.com', 'x.y.z.foo.com').should == '.y.z.foo.com'
CookieValidation.domains_match('.foo.com', 'auth.foo.com').should eq '.foo.com'
CookieValidation.domains_match('.y.z.foo.com', 'x.y.z.foo.com').should eq '.y.z.foo.com'
end
it "should not match superdomains, or illegal domains" do
CookieValidation.domains_match('.z.foo.com', 'x.y.z.foo.com').should be_nil
Expand All @@ -210,22 +205,22 @@
describe '#hostname_reach' do
it "should find the next highest subdomain" do
{'www.google.com' => 'google.com', 'auth.corp.companyx.com' => 'corp.companyx.com'}.each do |entry|
CookieValidation.hostname_reach(entry[0]).should == entry[1]
CookieValidation.hostname_reach(entry[0]).should eq entry[1]
end
end
it "should handle domains with suffixed dots" do
CookieValidation.hostname_reach('www.google.com.').should == 'google.com.'
CookieValidation.hostname_reach('www.google.com.').should eq 'google.com.'
end
it "should return nil for a root domain" do
CookieValidation.hostname_reach('github.com').should be_nil
end
it "should return 'local' for a local domain" do
['foo.local', 'foo.local.'].each do |hostname|
CookieValidation.hostname_reach(hostname).should == 'local'
CookieValidation.hostname_reach(hostname).should eq 'local'
end
end
it "should handle mixed-case '.local'" do
CookieValidation.hostname_reach('foo.LOCAL').should == 'local'
CookieValidation.hostname_reach('foo.LOCAL').should eq 'local'
end
it "should return nil for an IPv4 address" do
CookieValidation.hostname_reach('127.0.0.1').should be_nil
Expand Down
16 changes: 8 additions & 8 deletions spec/jar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
it "should let me read back a multiple cookies from 1 header" do
jar = Jar.new
jar.set_cookie 'http://foo.com/', 'my_cookie=123456; Domain=foo.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/, other_cookie=helloworld; Domain=foo.com; expires=Thu, 31 Dec 2037 23:59:59 GMT, last_cookie=098765'
jar.get_cookie_header('http://foo.com/').should == 'last_cookie=098765;my_cookie=123456;other_cookie=helloworld'
jar.get_cookie_header('http://foo.com/').should eq 'last_cookie=098765;my_cookie=123456;other_cookie=helloworld'
end
it "should return cookies longest path first" do
jar = Jar.new
Expand All @@ -45,10 +45,10 @@
jar.set_cookie uri, 'd=bar;path=/a/'
cookies = jar.get_cookies(uri)
cookies.should have(4).items
cookies[0].name.should == 'b'
cookies[1].name.should == 'a'
cookies[2].name.should == 'c'
cookies[3].name.should == 'd'
cookies[0].name.should eq 'b'
cookies[1].name.should eq 'a'
cookies[2].name.should eq 'c'
cookies[3].name.should eq 'd'
end
it "should not return expired cookies" do
jar = Jar.new
Expand All @@ -65,7 +65,7 @@
jar.set_cookie uri, 'a=bar'
jar.set_cookie uri, 'b=baz;path=/a/b/c/d'
cookie_headers = jar.get_cookie_header uri
cookie_headers.should == "b=baz;a=bar"
cookie_headers.should eq "b=baz;a=bar"
end
it "should handle a version 1 cookie" do
jar = Jar.new
Expand All @@ -74,7 +74,7 @@
jar.set_cookie uri, 'b=baz;path=/a/b/c/d'
jar.set_cookie2 uri, 'c=baz;Version=1;path="/"'
cookie_headers = jar.get_cookie_header uri
cookie_headers.should == '$Version=0;b=baz;$Path="/a/b/c/d";a=bar;$Path="/a/b/c/",$Version=1;c=baz;$Path="/"'
cookie_headers.should eq '$Version=0;b=baz;$Path="/a/b/c/d";a=bar;$Path="/a/b/c/",$Version=1;c=baz;$Path="/"'
end
end
describe '.add_cookie' do
Expand Down Expand Up @@ -183,7 +183,7 @@
# and has the version 1 cookie
cookies.find do |cookie|
cookie.name == 'foo'
end.version.should == 1
end.version.should eq 1
end
it "should silently drop invalid cookies" do
jar = Jar.new
Expand Down

0 comments on commit aa1f319

Please sign in to comment.