Summary: | Web Automation: cookies returned by automation should have expiry time in seconds | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Carlos Garcia Campos <cgarcia> | ||||
Component: | WebDriver | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Normal | CC: | bburg, webkit-bug-importer | ||||
Priority: | P2 | Keywords: | InRadar | ||||
Version: | WebKit Nightly Build | ||||||
Hardware: | Unspecified | ||||||
OS: | Unspecified | ||||||
Attachments: |
|
Created attachment 332655 [details]
Patch
Comment on attachment 332655 [details]
Patch
r=me
Oops, we did document this as the unit of measure, but messed up:
{ "name": "expires", "type": "number", "description": "Cookie expiration in seconds since the UNIX epoch." },
Committed r227891: <https://trac.webkit.org/changeset/227891> |
When creating a WebCore::Cookie from a WebDriver object we convert the given expiry time to milliseconds, but when creating a WebDriver object from a WebCore::Cookie we are keeping the milliseconds. We should convert to seconds for consistency, so that the WebDriver always handles seconds. This fixes imported/w3c/webdriver/tests/cookies/get_named_cookie.py::test_get_named_cookie ___________________________________________________________________________________ test_get_named_cookie ____________________________________________________________________________________ session = <webdriver.client.Session object at 0x7fa1cc7a5550>, url = <function url at 0x7fa1cc80ea28> def test_get_named_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) # same formatting as Date.toUTCString() in javascript utc_string_format = "%a, %d %b %Y %H:%M:%S" a_year_from_now = (datetime.utcnow() + timedelta(days=365)).strftime(utc_string_format) session.execute_script("document.cookie = 'foo=bar;expires=%s'" % a_year_from_now) result = session.transport.send("GET", "session/%s/cookie" % session.session_id) assert result.status == 200 assert "value" in result.body assert isinstance(result.body["value"], list) assert len(result.body["value"]) == 1 assert isinstance(result.body["value"][0], dict) cookie = result.body["value"][0] assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "expiry" in cookie assert isinstance(cookie["expiry"], (int, long)) assert cookie["name"] == "foo" assert cookie["value"] == "bar" # convert from seconds since epoch > assert datetime.utcfromtimestamp(cookie["expiry"]).strftime(utc_string_format) == a_year_from_now E AssertionError: assert 'Thu, 13 Jun 1918 11:59:04' == 'Wed, 30 Jan 2019 13:52:05' E - Thu, 13 Jun 1918 11:59:04 E + Wed, 30 Jan 2019 13:52:05 a_year_from_now = 'Wed, 30 Jan 2019 13:52:05' cookie = {'domain': 'localhost', 'expiry': -1626868856, 'httpOnly': False, 'name': 'foo', ...} result = <Responsetatus=200 body={"value": [{"domain": "localhost", "name": "foo", "val...expiry": -1626868856, "path": "/common", "httpOnly": false, "secure": false}]}> session = <webdriver.client.Session object at 0x7fa1cc7a5550> url = <function url at 0x7fa1cc80ea28> utc_string_format = '%a, %d %b %Y %H:%M:%S' WebDriverTests/imported/w3c/webdriver/tests/cookies/get_named_cookie.py:62: AssertionError