Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Using default address 127.0.0.1 leads to cookies problems when using Capybara.server_host #503

Closed
woto opened this issue Jun 7, 2014 · 5 comments

Comments

@woto
Copy link

woto commented Jun 7, 2014

Hi, sorry for bad English. Not sure that this is a bug, in my project i'm using

Capybara.server_port = 3000
Capybara.server_host = 'localhost'

next i wanted to set cookie

page.driver.set_cookie "auth_token", "8e9beU3E20YWHmF1RBSwFa"

i found that this doesn't work.
Next I found the problem. Because of different hosts.

poltergeist-c3d41c7652c4/lib/capybara/poltergeist/driver.rb @ line 218 Capybara::Poltergeist::Driver#set_cookie:

Capybara.app_host || "127.0.0.1"

After changing server_host from 'localhost' to '127.0.0.1' all works fine.

@yaauie
Copy link
Contributor

yaauie commented Jun 7, 2014

It looks like Capybara supports both server_host and app_host attributes, and the documentation is nor clear about the difference between the two.

Can you try setting both to localhost to see if it behaves as you expect?

@woto
Copy link
Author

woto commented Jun 13, 2014

Hi, sorry for late.

I tried

Capybara.app_host = "http://localhost:3000"
Capybara.always_include_port = true
Capybara.default_host = "http://localhost:3000"
#Capybara.default_host
Capybara.server_port = 3000
Capybara.server_host = "localhost"

in different combinations, but didn't found solution. I'll try later when will have some more free time.

@route
Copy link
Contributor

route commented Jun 17, 2014

I suppose it's related to #217

@Jamedjo
Copy link

Jamedjo commented Mar 18, 2015

I'm having similar issues in that using app_host or default_host prevents cookies from being set/retrieved.

Resetting them to 127.0.0.1 before the test works:

Capybara.default_host = 'http://127.0.0.1'
Capybara.app_host = 'http://127.0.0.1'
page.driver.set_cookie('my_cookie_name', 'cookiemonster', domain: '127.0.0.1')

Where as setting a subdomain doesn't work:

Capybara.default_host = 'http://ourdomain.com'
Capybara.app_host = 'http://ourdomain.com'
page.driver.set_cookie('my_cookie_name', 'cookiemonster', domain: 'ourdomain.com')

@twalpole
Copy link
Contributor

This seems to be a combination of 2 issues - one is #217 which is a phantomjs issue with cookie setting and not yet sure whether we can do anything about that. The second is that the host you're visiting and the host you're setting cookies for have to match. Capybara.server_host is the ip/host that capybara attempts to bind the server to when it's running an app, Capybara.app_host is the url that gets prepended to paths passed to visit and is mainly designed for use when testing external sites. Capybara.default_host is used by the racktest driver (but will be overridden by app_host if set). I'm closing this since the one part of this issue is a configuration problem and not an issue in poltergeist and the other is a duplicate of issue #217

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants