Commit 118865f3 authored by Tricia Crichton's avatar Tricia Crichton Committed by Commit Bot

[ChromeDriver] Add sameSite parameter for Cookies

Add sameSite to AddCookie command, but do not include in DevTools parameters if not set by user.
Add sameSite to GetCookie commands.

Bug: chromedriver:3264
Change-Id: Iefb02e131804bdf7235bdb98b5ebf38e7a886cfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1955793
Commit-Queue: Tricia Crichton <triciac@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722581}
parent 53d9ee59
...@@ -160,6 +160,7 @@ Status StubWebView::AddCookie(const std::string& name, ...@@ -160,6 +160,7 @@ Status StubWebView::AddCookie(const std::string& name,
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
const std::string& path, const std::string& path,
const std::string& sameSite,
bool secure, bool secure,
bool httpOnly, bool httpOnly,
double expiry) { double expiry) {
......
...@@ -85,6 +85,7 @@ class StubWebView : public WebView { ...@@ -85,6 +85,7 @@ class StubWebView : public WebView {
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
const std::string& path, const std::string& path,
const std::string& sameSite,
bool secure, bool secure,
bool httpOnly, bool httpOnly,
double expiry) override; double expiry) override;
......
...@@ -176,6 +176,7 @@ class WebView { ...@@ -176,6 +176,7 @@ class WebView {
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
const std::string& path, const std::string& path,
const std::string& sameSite,
bool secure, bool secure,
bool httpOnly, bool httpOnly,
double expiry) = 0; double expiry) = 0;
......
...@@ -753,6 +753,7 @@ Status WebViewImpl::AddCookie(const std::string& name, ...@@ -753,6 +753,7 @@ Status WebViewImpl::AddCookie(const std::string& name,
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
const std::string& path, const std::string& path,
const std::string& sameSite,
bool secure, bool secure,
bool httpOnly, bool httpOnly,
double expiry) { double expiry) {
...@@ -764,6 +765,8 @@ Status WebViewImpl::AddCookie(const std::string& name, ...@@ -764,6 +765,8 @@ Status WebViewImpl::AddCookie(const std::string& name,
params.SetString("path", path); params.SetString("path", path);
params.SetBoolean("secure", secure); params.SetBoolean("secure", secure);
params.SetBoolean("httpOnly", httpOnly); params.SetBoolean("httpOnly", httpOnly);
if (!sameSite.empty())
params.SetString("sameSite", sameSite);
if (expiry >= 0) if (expiry >= 0)
params.SetDouble("expires", expiry); params.SetDouble("expires", expiry);
......
...@@ -127,6 +127,7 @@ class WebViewImpl : public WebView { ...@@ -127,6 +127,7 @@ class WebViewImpl : public WebView {
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
const std::string& path, const std::string& path,
const std::string& sameSite,
bool secure, bool secure,
bool httpOnly, bool httpOnly,
double expiry) override; double expiry) override;
......
...@@ -398,3 +398,19 @@ TEST(CreateChild, IsPendingNavigation_NoErrors) { ...@@ -398,3 +398,19 @@ TEST(CreateChild, IsPendingNavigation_NoErrors) {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
child_view->IsPendingNavigation("1234", &timeout, &result)); child_view->IsPendingNavigation("1234", &timeout, &result));
} }
TEST(ManageCookies, AddCookie_SameSiteTrue) {
std::unique_ptr<FakeDevToolsClient> client_uptr =
std::make_unique<FakeDevToolsClient>();
FakeDevToolsClient* client_ptr = client_uptr.get();
BrowserInfo browser_info;
WebViewImpl view(client_ptr->GetId(), true, nullptr, &browser_info,
std::move(client_uptr), nullptr, PageLoadStrategy::kEager);
std::string samesite = "Strict";
base::DictionaryValue dict;
dict.SetBoolean("success", true);
client_ptr->set_result(dict);
Status status = view.AddCookie("utest", "chrome://version", "value", "domain",
"path", samesite, true, true, 123456789);
ASSERT_EQ(kOk, status.code());
}
...@@ -207,17 +207,26 @@ struct Cookie { ...@@ -207,17 +207,26 @@ struct Cookie {
const std::string& value, const std::string& value,
const std::string& domain, const std::string& domain,
const std::string& path, const std::string& path,
const std::string& samesite,
double expiry, double expiry,
bool http_only, bool http_only,
bool secure, bool secure,
bool session) bool session)
: name(name), value(value), domain(domain), path(path), expiry(expiry), : name(name),
http_only(http_only), secure(secure), session(session) {} value(value),
domain(domain),
path(path),
samesite(samesite),
expiry(expiry),
http_only(http_only),
secure(secure),
session(session) {}
std::string name; std::string name;
std::string value; std::string value;
std::string domain; std::string domain;
std::string path; std::string path;
std::string samesite;
double expiry; double expiry;
bool http_only; bool http_only;
bool secure; bool secure;
...@@ -237,6 +246,8 @@ std::unique_ptr<base::DictionaryValue> CreateDictionaryFrom( ...@@ -237,6 +246,8 @@ std::unique_ptr<base::DictionaryValue> CreateDictionaryFrom(
dict->SetDouble("expiry", cookie.expiry); dict->SetDouble("expiry", cookie.expiry);
dict->SetBoolean("httpOnly", cookie.http_only); dict->SetBoolean("httpOnly", cookie.http_only);
dict->SetBoolean("secure", cookie.secure); dict->SetBoolean("secure", cookie.secure);
if (!cookie.samesite.empty())
dict->SetString("sameSite", cookie.samesite);
return dict; return dict;
} }
...@@ -264,6 +275,8 @@ Status GetVisibleCookies(WebView* web_view, ...@@ -264,6 +275,8 @@ Status GetVisibleCookies(WebView* web_view,
cookie_dict->GetString("domain", &domain); cookie_dict->GetString("domain", &domain);
std::string path; std::string path;
cookie_dict->GetString("path", &path); cookie_dict->GetString("path", &path);
std::string samesite = "";
GetOptionalString(cookie_dict, "sameSite", &samesite);
double expiry = 0; double expiry = 0;
cookie_dict->GetDouble("expires", &expiry); cookie_dict->GetDouble("expires", &expiry);
if (expiry > 1e12) if (expiry > 1e12)
...@@ -275,8 +288,8 @@ Status GetVisibleCookies(WebView* web_view, ...@@ -275,8 +288,8 @@ Status GetVisibleCookies(WebView* web_view,
bool secure = false; bool secure = false;
cookie_dict->GetBoolean("secure", &secure); cookie_dict->GetBoolean("secure", &secure);
cookies_tmp.push_back( cookies_tmp.push_back(Cookie(name, value, domain, path, samesite, expiry,
Cookie(name, value, domain, path, expiry, http_only, secure, session)); http_only, secure, session));
} }
cookies->swap(cookies_tmp); cookies->swap(cookies_tmp);
return Status(kOk); return Status(kOk);
...@@ -1875,6 +1888,12 @@ Status ExecuteAddCookie(Session* session, ...@@ -1875,6 +1888,12 @@ Status ExecuteAddCookie(Session* session,
std::string path("/"); std::string path("/");
if (!GetOptionalString(cookie, "path", &path)) if (!GetOptionalString(cookie, "path", &path))
return Status(kInvalidArgument, "invalid 'path'"); return Status(kInvalidArgument, "invalid 'path'");
std::string samesite("");
if (!GetOptionalString(cookie, "sameSite", &samesite))
return Status(kInvalidArgument, "invalid 'sameSite'");
if (!samesite.empty() && samesite != "Strict" && samesite != "Lax" &&
samesite != "None")
return Status(kInvalidArgument, "invalid 'sameSite'");
bool secure = false; bool secure = false;
if (!GetOptionalBool(cookie, "secure", &secure)) if (!GetOptionalBool(cookie, "secure", &secure))
return Status(kInvalidArgument, "invalid 'secure'"); return Status(kInvalidArgument, "invalid 'secure'");
...@@ -1901,8 +1920,8 @@ Status ExecuteAddCookie(Session* session, ...@@ -1901,8 +1920,8 @@ Status ExecuteAddCookie(Session* session,
expiry = (base::Time::Now() - base::Time::UnixEpoch()).InSeconds() + expiry = (base::Time::Now() - base::Time::UnixEpoch()).InSeconds() +
kDefaultCookieExpiryTime; kDefaultCookieExpiryTime;
} }
return web_view->AddCookie(name, url, cookie_value, domain, path, return web_view->AddCookie(name, url, cookie_value, domain, path, samesite,
secure, httpOnly, expiry); secure, httpOnly, expiry);
} }
Status ExecuteDeleteCookie(Session* session, Status ExecuteDeleteCookie(Session* session,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment