Skip to content

Commit

Permalink
Bugfix for Cookies with multiple paths (#197)
Browse files Browse the repository at this point in the history
* Bugfix for Cookies with multiple paths

closes #16

* Fixed spec names
  • Loading branch information
kylewelsby authored and perlun committed Aug 3, 2017
1 parent 49c27b5 commit 0047c07
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rack/test/cookie_jar.rb
Expand Up @@ -53,7 +53,7 @@ def http_only?

# :api: private
def path
@options['path'].strip || '/'
([*@options['path']].first.split(',').first || '/').strip
end

# :api: private
Expand Down
27 changes: 26 additions & 1 deletion spec/rack/test/cookie_spec.rb
Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rack/test/uploaded_file_spec.rb
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions spec/rack/test_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0047c07

Please sign in to comment.