Commit 12a31fdc authored by megjablon's avatar megjablon Committed by Commit bot

Chrome-Proxy will now have three directives relevant to versioning:

"b=" -- the build number
"p=" -- the patch number
"c=" -- the client type (current values are "ios", "android", and "webview")

Currently, b and p only make sense for chrome types and are only being implemented for ios and android.

BUG=409934

Review URL: https://codereview.chromium.org/530153002

Cr-Commit-Position: refs/heads/master@{#293591}
parent e05135fb
......@@ -650,7 +650,7 @@ void IOThread::InitAsync() {
globals_->data_reduction_proxy_auth_request_handler.reset(
new data_reduction_proxy::DataReductionProxyAuthRequestHandler(
DataReductionProxyChromeSettings::GetClient(),
DataReductionProxyChromeSettings::GetBuildAndPatchNumber(),
chrome::VersionInfo().Version(),
globals_->data_reduction_proxy_params.get(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
// This is the same as in ProfileImplIOData except that we do not collect
......
......@@ -6,13 +6,11 @@
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_split.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_version_info.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
......@@ -53,16 +51,6 @@ void DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial(
data_reduction_proxy_enabled ? "true" : "false");
}
// static
std::string DataReductionProxyChromeSettings::GetBuildAndPatchNumber() {
chrome::VersionInfo version_info;
std::vector<std::string> version_parts;
base::SplitString(version_info.Version(), '.', &version_parts);
if (version_parts.size() != 4)
return "";
return version_parts[2] + version_parts[3];
}
// static
std::string DataReductionProxyChromeSettings::GetClient() {
#if defined(OS_ANDROID)
......
......@@ -46,11 +46,6 @@ class DataReductionProxyChromeSettings
PrefService* local_state_prefs,
net::URLRequestContextGetter* request_context);
// Using the chrome::VersionInfo version, returns the build and patch portion
// of the string delimited by a period. If the chrome::VersionInfo version
// isn't of the form xx.xx.xx.xx returns an empty string.
static std::string GetBuildAndPatchNumber();
// Gets the client type for the data reduction proxy.
static std::string GetClient();
......
......@@ -31,6 +31,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/domain_reliability/monitor.h"
......@@ -433,7 +434,7 @@ void ProfileImplIOData::InitializeInternal(
data_reduction_proxy_auth_request_handler_.reset(
new data_reduction_proxy::DataReductionProxyAuthRequestHandler(
DataReductionProxyChromeSettings::GetClient(),
DataReductionProxyChromeSettings::GetBuildAndPatchNumber(),
chrome::VersionInfo().Version(),
data_reduction_proxy_params_.get(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
data_reduction_proxy_usage_stats_.reset(
......
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
......@@ -25,7 +26,7 @@ namespace data_reduction_proxy {
// The empty version for the authentication protocol. Currently used by
// Android webview.
#if defined(OS_ANDROID)
const char kAndroidWebViewProtocolVersion[] = "0";
const char kAndroidWebViewProtocolVersion[] = "";
#endif
// The clients supported by the data reduction proxy.
......@@ -48,10 +49,22 @@ DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler(
: data_reduction_proxy_params_(params),
network_task_runner_(network_task_runner) {
client_ = client;
version_ = version;
GetChromiumBuildAndPatch(version, &build_number_, &patch_number_);
Init();
}
void DataReductionProxyAuthRequestHandler::GetChromiumBuildAndPatch(
const std::string& version,
std::string* build,
std::string* patch) {
std::vector<std::string> version_parts;
base::SplitString(version, '.', &version_parts);
if (version_parts.size() != 4)
return;
*build = version_parts[2];
*patch = version_parts[3];
}
void DataReductionProxyAuthRequestHandler::Init() {
InitAuthenticationOnUI(GetDefaultKey());
}
......@@ -112,7 +125,9 @@ void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader(
header_value += ", ";
}
header_value +=
"ps=" + session_ + ", sid=" + credentials_ + ", v=" + version_;
"ps=" + session_ + ", sid=" + credentials_;
if (!build_number_.empty() && !patch_number_.empty())
header_value += ", b=" + build_number_ + ", p=" + patch_number_;
if (!client_.empty())
header_value += ", c=" + client_;
headers->SetHeader(kChromeProxyHeader, header_value);
......
......@@ -38,6 +38,12 @@ class DataReductionProxyAuthRequestHandler {
public:
static bool IsKeySetOnCommandLine();
// Constructs a DataReductionProxyAuthRequestHandler object with the given
// client, version, params, and network task runner. The Chromium |version| is
// expected to be of the form "xx.xx.xx.xx". If it isn't of this form,
// |build_number_| and |patch_number_| are set to empty strings and not
// included in the header. http://crbug.com/410127 will change this so that
// the version is retrieved inside this constructor.
DataReductionProxyAuthRequestHandler(
const std::string& client,
const std::string& version,
......@@ -79,9 +85,17 @@ class DataReductionProxyAuthRequestHandler {
private:
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
Authorization);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
AuthorizationBogusVersion);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
AuthHashForSalt);
// Returns the build and patch numbers of |version|. If |version| isn't of the
// form xx.xx.xx.xx build and patch are not modified.
void GetChromiumBuildAndPatch(const std::string& version,
std::string* build,
std::string* patch);
// Stores the supplied key and sets up credentials suitable for authenticating
// with the data reduction proxy.
void InitAuthentication(const std::string& key);
......@@ -102,7 +116,8 @@ class DataReductionProxyAuthRequestHandler {
// Name of the client and version of the data reduction proxy protocol to use.
// Both live on the IO thread.
std::string client_;
std::string version_;
std::string build_number_;
std::string patch_number_;
// The last time the session was updated. Used to ensure that a session is
// never used for more than twenty-four hours.
......
......@@ -31,7 +31,10 @@ const char kOtherProxy[] = "testproxy:17";
#else
const char kClient[] = "";
#endif
const char kVersion[] = "0";
const char kVersion[] = "0.1.2.3";
const char kExpectedBuild[] = "2";
const char kExpectedPatch[] = "3";
const char kBogusVersion[] = "0.0";
const char kTestKey[] = "test-key";
const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768";
const char kExpectedSession[] = "0-1633771873-1633771873-1633771873";
......@@ -42,24 +45,33 @@ const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873";
#if defined(OS_ANDROID)
const char kExpectedHeader2[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, v=0, c=android";
"sid=c911fdb402f578787562cf7f00eda972, b=2, p=3, c=android";
const char kExpectedHeader3[] =
"ps=86401-1633771873-1633771873-1633771873, "
"sid=d7c1c34ef6b90303b01c48a6c1db6419, v=0, c=android";
"sid=d7c1c34ef6b90303b01c48a6c1db6419, b=2, p=3, c=android";
const char kExpectedHeader4[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, c=android";
#elif defined(OS_IOS)
const char kExpectedHeader2[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, v=0, c=ios";
"sid=c911fdb402f578787562cf7f00eda972, b=2, p=3, c=ios";
const char kExpectedHeader3[] =
"ps=86401-1633771873-1633771873-1633771873, "
"sid=d7c1c34ef6b90303b01c48a6c1db6419, v=0, c=ios";
"sid=d7c1c34ef6b90303b01c48a6c1db6419, b=2, p=3, c=ios";
const char kExpectedHeader4[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, c=ios";
#else
const char kExpectedHeader2[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972, v=0";
"sid=c911fdb402f578787562cf7f00eda972, b=2, p=3";
const char kExpectedHeader3[] =
"ps=86401-1633771873-1633771873-1633771873, "
"sid=d7c1c34ef6b90303b01c48a6c1db6419, v=0";
"sid=d7c1c34ef6b90303b01c48a6c1db6419, b=2, p=3";
const char kExpectedHeader4[] =
"ps=0-1633771873-1633771873-1633771873, "
"sid=c911fdb402f578787562cf7f00eda972";
#endif
const char kDataReductionProxyKey[] = "12345";
......@@ -131,7 +143,8 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) {
auth_handler.Init();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(auth_handler.client_, kClient);
EXPECT_EQ(kVersion, auth_handler.version_);
EXPECT_EQ(kExpectedBuild, auth_handler.build_number_);
EXPECT_EQ(kExpectedPatch, auth_handler.patch_number_);
EXPECT_EQ(auth_handler.key_, kTestKey);
EXPECT_EQ(kExpectedCredentials, auth_handler.credentials_);
EXPECT_EQ(kExpectedSession, auth_handler.session_);
......@@ -143,7 +156,6 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) {
EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_);
EXPECT_EQ(kExpectedSession2, auth_handler.session_);
// Don't write headers if the proxy is invalid.
net::HttpRequestHeaders headers;
auth_handler.MaybeAddRequestHeader(NULL, net::ProxyServer(), &headers);
......@@ -199,6 +211,43 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) {
EXPECT_EQ(kExpectedHeader3, header_value3);
}
TEST_F(DataReductionProxyAuthRequestHandlerTest, AuthorizationBogusVersion) {
scoped_ptr<TestDataReductionProxyParams> params;
params.reset(
new TestDataReductionProxyParams(
DataReductionProxyParams::kAllowed |
DataReductionProxyParams::kFallbackAllowed |
DataReductionProxyParams::kPromoAllowed,
TestDataReductionProxyParams::HAS_EVERYTHING &
~TestDataReductionProxyParams::HAS_DEV_ORIGIN));
TestDataReductionProxyAuthRequestHandler auth_handler(kClient,
kBogusVersion,
params.get(),
loop_proxy_);
EXPECT_TRUE(auth_handler.build_number_.empty());
EXPECT_TRUE(auth_handler.patch_number_.empty());
// Now set a key.
auth_handler.SetKeyOnUI(kTestKey2);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(kTestKey2, auth_handler.key_);
EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_);
EXPECT_EQ(kExpectedSession2, auth_handler.session_);
net::HttpRequestHeaders headers;
// Write headers with a valid data reduction proxy;
auth_handler.MaybeAddRequestHeader(
NULL,
net::ProxyServer::FromURI(
net::HostPortPair::FromURL(GURL(params->DefaultOrigin())).ToString(),
net::ProxyServer::SCHEME_HTTP),
&headers);
EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
std::string header_value;
headers.GetHeader(kChromeProxyHeader, &header_value);
EXPECT_EQ(kExpectedHeader4, header_value);
}
TEST_F(DataReductionProxyAuthRequestHandlerTest, AuthHashForSalt) {
std::string salt = "8675309"; // Jenny's number to test the hash generator.
std::string salted_key = salt + kDataReductionProxyKey + salt;
......
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