From 0047c07b492fd373d3eec25142653c5121e87071 Mon Sep 17 00:00:00 2001 From: Kyle Welsby Date: Thu, 3 Aug 2017 07:13:50 +0100 Subject: [PATCH] Bugfix for Cookies with multiple paths (#197) * Bugfix for Cookies with multiple paths closes #16 * Fixed spec names --- lib/rack/test/cookie_jar.rb | 2 +- spec/rack/test/cookie_spec.rb | 27 ++++++++++++++++++++++++++- spec/rack/test/uploaded_file_spec.rb | 2 +- spec/rack/test_spec.rb | 8 ++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/rack/test/cookie_jar.rb b/lib/rack/test/cookie_jar.rb index fed13f14..b12d82e0 100644 --- a/lib/rack/test/cookie_jar.rb +++ b/lib/rack/test/cookie_jar.rb @@ -53,7 +53,7 @@ def http_only? # :api: private def path - @options['path'].strip || '/' + ([*@options['path']].first.split(',').first || '/').strip end # :api: private diff --git a/spec/rack/test/cookie_spec.rb b/spec/rack/test/cookie_spec.rb index 6b35c25a..9dd538cb 100644 --- a/spec/rack/test/cookie_spec.rb +++ b/spec/rack/test/cookie_spec.rb @@ -28,6 +28,31 @@ expect(last_request.cookies).to eq({}) end + it 'uses the first "path" when multiple paths are defined' do + cookie_string = [ + '/', + 'csrf_id=ABC123', + 'path=/, _github_ses=ABC123', + 'path=/', + 'expires=Wed, 01 Jan 2020 08:00:00 GMT', + 'HttpOnly' + ].join('; ') + cookie = Rack::Test::Cookie.new(cookie_string) + expect(cookie.path).to eq('/') + end + + it 'uses the single "path" when only one path is defined' do + cookie_string = [ + '/', + 'csrf_id=ABC123', + 'path=/', + 'expires=Wed, 01 Jan 2020 08:00:00 GMT', + 'HttpOnly' + ].join('; ') + cookie = Rack::Test::Cookie.new(cookie_string) + expect(cookie.path).to eq('/') + end + it 'escapes cookie values' do jar = Rack::Test::CookieJar.new jar['value'] = 'foo;abc' @@ -45,7 +70,7 @@ it 'allow symbol access' do jar = Rack::Test::CookieJar.new jar['value'] = 'foo;abc' - jar[:value].should == 'foo;abc' + expect(jar[:value]).to eq('foo;abc') end it "doesn't send cookies with the wrong domain" do diff --git a/spec/rack/test/uploaded_file_spec.rb b/spec/rack/test/uploaded_file_spec.rb index 7428f745..e6e138cb 100644 --- a/spec/rack/test/uploaded_file_spec.rb +++ b/spec/rack/test/uploaded_file_spec.rb @@ -56,7 +56,7 @@ def test_file_path it 'sets the specified filename' do subject.call - uploaded_file.original_filename.should == original_filename + expect(uploaded_file.original_filename).to eq(original_filename) end end diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb index 245b4cfe..01c6c366 100644 --- a/spec/rack/test_spec.rb +++ b/spec/rack/test_spec.rb @@ -129,7 +129,7 @@ it 'does not rewrite a GET query string when :params is empty' do request '/foo?a=1&b=2&c=3&e=4&d=5', params: {} - last_request.query_string.should == 'a=1&b=2&c=3&e=4&d=5' + expect(last_request.query_string).to eq('a=1&b=2&c=3&e=4&d=5') end it 'does not overwrite multiple query string keys' do @@ -391,9 +391,9 @@ def close it 'keeps the original method' do post '/redirect?status=307', foo: 'bar' follow_redirect! - last_response.body.should include 'post' - last_response.body.should include 'foo' - last_response.body.should include 'bar' + expect(last_response.body).to include('post') + expect(last_response.body).to include('foo') + expect(last_response.body).to include('bar') end end end