def test_get_named_session_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) session.execute_script("document.cookie = 'foo=bar'") result = get_named_cookie(session, "foo") cookie = assert_success(result) assert isinstance(cookie, dict) # table for cookie conversion # https://w3c.github.io/webdriver/webdriver-spec.html#dfn-table-for-cookie-conversion assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "path" in cookie assert isinstance(cookie["path"], basestring) assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert "secure" in cookie assert isinstance(cookie["secure"], bool) assert "httpOnly" in cookie assert isinstance(cookie["httpOnly"], bool) if "expiry" in cookie: assert cookie.get("expiry") is None assert cookie["name"] == "foo" assert cookie["value"] == "bar"
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 = get_named_cookie(session, "foo") cookie = assert_success(result) assert isinstance(cookie, dict) 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
def test_add_non_session_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) a_year_from_now = int((datetime.utcnow() + timedelta(days=365)).strftime("%s")) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "expiry": a_year_from_now } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert isinstance(result.body["value"], dict) 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) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["expiry"] == a_year_from_now
def test_add_session_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) create_cookie_request = { "cookie": { "name": "hello", "value": "world" } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert isinstance(result.body["value"], dict) 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 cookie.get("expiry") is None assert cookie["name"] == "hello" assert cookie["value"] == "world"
def test_add_non_session_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) a_year_from_now = int((datetime.utcnow() + timedelta(days=365) - datetime.utcfromtimestamp(0)).total_seconds()) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "expiry": a_year_from_now } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert result.body["value"] is None 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) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["expiry"] == a_year_from_now
def test_duplicated_cookie(session, url, server_config): new_cookie = { "name": "hello", "value": "world", "domain": server_config["browser_host"], "path": "/", "http_only": False, "secure": False } session.url = url("/common/blank.html") clear_all_cookies(session) session.set_cookie(**new_cookie) session.url = inline(""" <script> document.cookie = '{name}=newworld; domain={domain}; path=/'; </script>""".format( name=new_cookie["name"], domain=server_config["browser_host"])) result = get_named_cookie(session, new_cookie["name"]) cookie = assert_success(result) assert isinstance(cookie, dict) assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert cookie["name"] == new_cookie["name"] assert cookie["value"] == "newworld"
def test_add_cookie_for_ip(session, url, server_config, configuration): new_cookie = { "name": "hello", "value": "world", "domain": "127.0.0.1", "path": "/", "httpOnly": False, "secure": False } session.url = "http://127.0.0.1:%s/common/blank.html" % (server_config["ports"]["http"][0]) clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == "127.0.0.1"
def test_duplicated_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "domain": "web-platform.test", "path": "/", "httpOnly": False, "secure": False } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert isinstance(result.body["value"], dict) session.url = inline("<script>document.cookie = 'hello=newworld; domain=web-platform.test; path=/';</script>") 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 cookie["name"] == "hello" assert cookie["value"] == "newworld"
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
def test_add_domain_cookie(session, url, server_config): new_cookie = { "name": "hello", "value": "world", "domain": server_config["browser_host"], "path": "/", "httpOnly": False, "secure": False } session.url = url("/common/blank.html") clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == server_config["browser_host"] or \ cookie["domain"] == ".%s" % server_config["browser_host"]
def test_add_cookie_for_ip(session, url, server_config, configuration): new_cookie = { "name": "hello", "value": "world", "domain": "127.0.0.1", "path": "/", "httpOnly": False, "secure": False } session.url = "http://127.0.0.1:%s/common/blank.html" % ( server_config["ports"]["http"][0]) clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == "127.0.0.1"
def test_add_session_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) create_cookie_request = {"cookie": {"name": "hello", "value": "world"}} result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert result.body["value"] is None 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) if "expiry" in cookie: assert cookie.get("expiry") is None assert cookie["name"] == "hello" assert cookie["value"] == "world"
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
def test_add_non_session_cookie(session, url): a_year_from_now = int( (datetime.utcnow() + timedelta(days=365) - datetime.utcfromtimestamp(0)).total_seconds()) new_cookie = { "name": "hello", "value": "world", "expiry": a_year_from_now } session.url = url("/common/blank.html") clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") 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) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["expiry"] == a_year_from_now
def test_add_session_cookie_with_leading_dot_character_in_domain(session, url, server_config): new_cookie = { "name": "hello", "value": "world", "domain": ".%s" % server_config["browser_host"] } session.url = url("/common/blank.html") clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == server_config["browser_host"] or \ cookie["domain"] == ".%s" % server_config["browser_host"]
def test_get_named_session_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) session.execute_script("document.cookie = 'foo=bar'") result = session.transport.send("GET", "session/%s/cookie/foo" % session.session_id) assert result.status == 200 assert isinstance(result.body["value"], dict) # table for cookie conversion # https://w3c.github.io/webdriver/webdriver-spec.html#dfn-table-for-cookie-conversion cookie = result.body["value"] assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "path" in cookie assert isinstance(cookie["path"], basestring) assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert "secure" in cookie assert isinstance(cookie["secure"], bool) assert "httpOnly" in cookie assert isinstance(cookie["httpOnly"], bool) assert "expiry" in cookie assert cookie.get("expiry") is None assert cookie["name"] == "foo" assert cookie["value"] == "bar"
def test_get_named_session_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) session.execute_script("document.cookie = 'foo=bar'") result = session.transport.send( "GET", "session/%s/cookie/foo" % session.session_id) assert result.status == 200 assert isinstance(result.body["value"], dict) # table for cookie conversion # https://w3c.github.io/webdriver/webdriver-spec.html#dfn-table-for-cookie-conversion cookie = result.body["value"] assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "path" in cookie assert isinstance(cookie["path"], basestring) assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert "secure" in cookie assert isinstance(cookie["secure"], bool) assert "httpOnly" in cookie assert isinstance(cookie["httpOnly"], bool) assert "expiry" in cookie assert cookie.get("expiry") is None assert cookie["name"] == "foo" assert cookie["value"] == "bar"
def test_add_session_cookie_with_leading_dot_character_in_domain( session, url, server_config): new_cookie = { "name": "hello", "value": "world", "domain": ".%s" % server_config["browser_host"] } session.url = url("/common/blank.html") clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) assert "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == server_config["browser_host"] or \ cookie["domain"] == ".%s" % server_config["browser_host"]
def test_add_session_cookie_with_leading_dot_character_in_domain(session, url, server_config): session.url = url("/common/blank.html") clear_all_cookies(session) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "domain": ".%s" % server_config["domains"][""] } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert result.body["value"] is None 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 "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == ".%s" % server_config["domains"][""] or cookie["domain"] == "%s" % server_config["domains"][""]
def test_null_response_value(session, url): new_cookie = { "name": "hello", "value": "world", } session.url = url("/common/blank.html") clear_all_cookies(session) response = add_cookie(session, new_cookie) value = assert_success(response) assert value is None
def test_add_session_cookie(session, url): new_cookie = {"name": "hello", "value": "world"} session.url = url("/common/blank.html") clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) if "expiry" in cookie: assert cookie.get("expiry") is None assert cookie["name"] == "hello" assert cookie["value"] == "world"
def test_add_cookie_for_ip(session, url, server_config, configuration): session.url = "http://127.0.0.1:%s/common/blank.html" % ( server_config["ports"]["http"][0]) clear_all_cookies(session) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "domain": "127.0.0.1", "path": "/", "httpOnly": False, "secure": False } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert result.body["value"] is None 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 "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == "127.0.0.1"
def test_add_domain_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "domain": "web-platform.test", "path": "/", "httpOnly": False, "secure": False } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert isinstance(result.body["value"], dict) 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 "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == ".web-platform.test"
def test_add_session_cookie(session, url): new_cookie = { "name": "hello", "value": "world" } session.url = url("/common/blank.html") clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") assert "name" in cookie assert isinstance(cookie["name"], basestring) assert "value" in cookie assert isinstance(cookie["value"], basestring) if "expiry" in cookie: assert cookie.get("expiry") is None assert cookie["name"] == "hello" assert cookie["value"] == "world"
def test_duplicated_cookie(session, url): session.url = url("/common/blank.html") clear_all_cookies(session) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "domain": "web-platform.test", "path": "/", "httpOnly": False, "secure": False } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert isinstance(result.body["value"], dict) session.url = inline( "<script>document.cookie = 'hello=newworld; domain=web-platform.test; path=/';</script>" ) 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 cookie["name"] == "hello" assert cookie["value"] == "newworld"
def test_add_non_session_cookie(session, url): a_year_from_now = int((datetime.utcnow() + timedelta(days=365) - datetime.utcfromtimestamp(0)).total_seconds()) new_cookie = {"name": "hello", "value": "world", "expiry": a_year_from_now} session.url = url("/common/blank.html") clear_all_cookies(session) result = add_cookie(session, new_cookie) assert_success(result) cookie = session.cookies("hello") 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) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["expiry"] == a_year_from_now
def test_add_cookie_for_ip(session, url, server_config, configuration): session.url = "http://127.0.0.1:%s/common/blank.html" % (server_config["ports"]["http"][0]) clear_all_cookies(session) create_cookie_request = { "cookie": { "name": "hello", "value": "world", "domain": "127.0.0.1", "path": "/", "httpOnly": False, "secure": False } } result = session.transport.send("POST", "session/%s/cookie" % session.session_id, create_cookie_request) assert result.status == 200 assert "value" in result.body assert result.body["value"] is None 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 "domain" in cookie assert isinstance(cookie["domain"], basestring) assert cookie["name"] == "hello" assert cookie["value"] == "world" assert cookie["domain"] == "127.0.0.1"