Commit 15e8b301 authored by Vincent Boisselle's avatar Vincent Boisselle Committed by Commit Bot

Moved API key to header.

Change-Id: Id425ec396cd9d1779138133e725dfcd0c2ef0f2c
Reviewed-on: https://chromium-review.googlesource.com/c/1354263Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Commit-Queue: Vincent Boisselle <vincb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612223}
parent e55033c9
...@@ -85,6 +85,8 @@ const net::BackoffEntry::Policy kAutofillBackoffPolicy = { ...@@ -85,6 +85,8 @@ const net::BackoffEntry::Policy kAutofillBackoffPolicy = {
const char kDefaultAutofillServerURL[] = const char kDefaultAutofillServerURL[] =
"https://clients1.google.com/tbproxy/af/"; "https://clients1.google.com/tbproxy/af/";
// Header for API key.
constexpr char kGoogApiKey[] = "X-Goog-Api-Key";
// Header to get base64 encoded serialized proto from API for safety. // Header to get base64 encoded serialized proto from API for safety.
constexpr char kGoogEncodeResponseIfExecutable[] = constexpr char kGoogEncodeResponseIfExecutable[] =
"X-Goog-Encode-Response-If-Executable"; "X-Goog-Encode-Response-If-Executable";
...@@ -612,9 +614,6 @@ AutofillDownloadManager::GetRequestURLAndMethodForApi( ...@@ -612,9 +614,6 @@ AutofillDownloadManager::GetRequestURLAndMethodForApi(
// Add the query parameter to set the response format to a serialized proto. // Add the query parameter to set the response format to a serialized proto.
url = net::AppendQueryParameter(url, "alt", "proto"); url = net::AppendQueryParameter(url, "alt", "proto");
// Add the API key query parameter.
if (!api_key_.empty())
url = net::AppendQueryParameter(url, "key", api_key_);
// Determine the HTTP method that should be used. // Determine the HTTP method that should be used.
std::string method = std::string method =
...@@ -654,6 +653,9 @@ bool AutofillDownloadManager::StartRequest(FormRequestData request_data) { ...@@ -654,6 +653,9 @@ bool AutofillDownloadManager::StartRequest(FormRequestData request_data) {
// Encode response serialized proto in base64 for safety. // Encode response serialized proto in base64 for safety.
resource_request->headers.SetHeader(kGoogEncodeResponseIfExecutable, resource_request->headers.SetHeader(kGoogEncodeResponseIfExecutable,
"base64"); "base64");
// Put API key in request's header if there is.
if (!api_key_.empty())
resource_request->headers.SetHeader(kGoogApiKey, api_key_);
} }
auto simple_loader = network::SimpleURLLoader::Create( auto simple_loader = network::SimpleURLLoader::Create(
......
...@@ -495,8 +495,12 @@ TEST_F(AutofillDownloadManagerTest, QueryAPITest) { ...@@ -495,8 +495,12 @@ TEST_F(AutofillDownloadManagerTest, QueryAPITest) {
const std::string expected_url = { const std::string expected_url = {
"https://clients1.google.com/v1/pages/" "https://clients1.google.com/v1/pages/"
"Chc2LjEuMTcxNS4xNDQyL2VuIChHR0xMKRIWEgkNeuFP4BIAGgASCQ2cTkrQEgAaAA==?" "Chc2LjEuMTcxNS4xNDQyL2VuIChHR0xMKRIWEgkNeuFP4BIAGgASCQ2cTkrQEgAaAA==?"
"alt=proto&key=dummykey"}; "alt=proto"};
EXPECT_THAT(request->request.url, expected_url); EXPECT_EQ(request->request.url, expected_url);
std::string api_key_header_value;
EXPECT_TRUE(request->request.headers.GetHeader("X-Goog-Api-Key",
&api_key_header_value));
EXPECT_EQ(api_key_header_value, "dummykey");
test_url_loader_factory_.SimulateResponseWithoutRemovingFromPendingList( test_url_loader_factory_.SimulateResponseWithoutRemovingFromPendingList(
request, "dummy response"); request, "dummy response");
...@@ -558,8 +562,12 @@ TEST_F(AutofillDownloadManagerTest, UploadToAPITest) { ...@@ -558,8 +562,12 @@ TEST_F(AutofillDownloadManagerTest, UploadToAPITest) {
// default one used by the download manager. Request upload data is in the // default one used by the download manager. Request upload data is in the
// payload when uploading. // payload when uploading.
const std::string expected_url = const std::string expected_url =
"https://clients1.google.com/v1/forms:vote?alt=proto&key=dummykey"; "https://clients1.google.com/v1/forms:vote?alt=proto";
EXPECT_THAT(request->request.url, expected_url); EXPECT_EQ(request->request.url, expected_url);
std::string api_key_header_value;
EXPECT_TRUE(request->request.headers.GetHeader("X-Goog-Api-Key",
&api_key_header_value));
EXPECT_EQ(api_key_header_value, "dummykey");
// Assert some of the fields within the uploaded proto to make sure it was // Assert some of the fields within the uploaded proto to make sure it was
// filled with something else than default data. // filled with something else than default data.
......
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