Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for Cookies with multiple paths #197

Merged
merged 2 commits into from
Aug 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rack/test/cookie_jar.rb
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ def http_only?

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

# :api: private
27 changes: 26 additions & 1 deletion spec/rack/test/cookie_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one still has the typo + misleading name. it 'properly uses a single path being defined' or something is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this. Thanks for pointing it out.


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
2 changes: 1 addition & 1 deletion spec/rack/test/uploaded_file_spec.rb
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions spec/rack/test_spec.rb
Original file line number Diff line number Diff line change
@@ -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