Bug 182293 - Web Automation: cookies returned by automation should have expiry time in seconds
Summary: Web Automation: cookies returned by automation should have expiry time in sec...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebDriver (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-01-30 08:18 PST by Carlos Garcia Campos
Modified: 2018-01-31 01:10 PST (History)
2 users (show)

See Also:


Attachments
Patch (1.82 KB, patch)
2018-01-30 08:20 PST, Carlos Garcia Campos
bburg: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2018-01-30 08:18:08 PST
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
Comment 1 Carlos Garcia Campos 2018-01-30 08:20:14 PST
Created attachment 332655 [details]
Patch
Comment 2 BJ Burg 2018-01-30 09:27:41 PST
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." },
Comment 3 Carlos Garcia Campos 2018-01-31 01:09:53 PST
Committed r227891: <https://trac.webkit.org/changeset/227891>
Comment 4 Radar WebKit Bug Importer 2018-01-31 01:10:49 PST
<rdar://problem/37061229>