| Index: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.cc
|
| diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.cc
|
| index 9a96db8cea2ebc4674dc3e1176bbf1a6f82245b6..aa581081e1090a0593b0840d3203de32ab8b6563 100644
|
| --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.cc
|
| +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.cc
|
| @@ -5,11 +5,13 @@
|
| #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.h"
|
|
|
| #include "base/command_line.h"
|
| +#include "base/md5.h"
|
| #include "base/metrics/field_trial.h"
|
| #include "base/prefs/pref_registry_simple.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/prefs/testing_pref_service.h"
|
| #include "base/strings/string_number_conversions.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h"
|
| #include "chrome/browser/prefs/proxy_prefs.h"
|
| #include "chrome/browser/prefs/scoped_user_pref_update.h"
|
| @@ -17,12 +19,14 @@
|
| #include "chrome/common/metrics/variations/variations_util.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "components/variations/entropy_provider.h"
|
| +#include "net/base/auth.h"
|
| +#include "net/base/host_port_pair.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| const char kDataReductionProxyOrigin[] = "https://foo:443/";
|
| -const char kDataReductionProxyOriginHostPort[] = "foo:443";
|
| +const char kDataReductionProxyFallback[] = "http://bar:80";
|
| const char kDataReductionProxyAuth[] = "12345";
|
|
|
| const char kProbeURLWithOKResponse[] = "http://ok.org/";
|
| @@ -90,6 +94,8 @@ void DataReductionProxySettingsTestBase::AddProxyToCommandLine() {
|
| CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| switches::kSpdyProxyAuthOrigin, kDataReductionProxyOrigin);
|
| CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| + switches::kSpdyProxyAuthFallback, kDataReductionProxyFallback);
|
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| switches::kSpdyProxyAuthValue, kDataReductionProxyAuth);
|
| }
|
|
|
| @@ -134,8 +140,10 @@ void DataReductionProxySettingsTestBase::CheckProxyPref(
|
| void DataReductionProxySettingsTestBase::CheckProxyConfigs(
|
| bool expected_enabled) {
|
| if (expected_enabled) {
|
| + std::string main_proxy = kDataReductionProxyOrigin;
|
| + std::string fallback_proxy = kDataReductionProxyFallback;
|
| std::string servers =
|
| - "http=" + Settings()->GetDataReductionProxyOrigin() + ",direct://;";
|
| + "http=" + main_proxy + "," + fallback_proxy + ",direct://;";
|
| CheckProxyPref(servers,
|
| ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS));
|
| } else {
|
| @@ -222,23 +230,44 @@ TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) {
|
| EXPECT_EQ(kDataReductionProxyOrigin, result);
|
| }
|
|
|
| -TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyAuth) {
|
| +TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) {
|
| + DataReductionProxySettings::DataReductionProxyList proxies =
|
| + settings_->GetDataReductionProxies();
|
| + EXPECT_TRUE(proxies.empty());
|
| +
|
| + // Adding just the fallback on the command line shouldn't add a proxy.
|
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| + switches::kSpdyProxyAuthFallback, kDataReductionProxyFallback);
|
| + proxies = settings_->GetDataReductionProxies();
|
| + EXPECT_TRUE(proxies.empty());
|
| +
|
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| + switches::kSpdyProxyAuthOrigin, kDataReductionProxyOrigin);
|
| + proxies = settings_->GetDataReductionProxies();
|
| + EXPECT_EQ(2u, proxies.size());
|
| +
|
| + EXPECT_EQ("foo",proxies[0].host());
|
| + EXPECT_EQ(443u,proxies[0].port());
|
| + EXPECT_EQ("bar",proxies[1].host());
|
| + EXPECT_EQ(80u,proxies[1].port());
|
| +}
|
| +
|
| +TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) {
|
| AddProxyToCommandLine();
|
| - // SetUp() adds the auth string to the command line, which should be returned
|
| - // here.
|
| - std::string result = settings_->GetDataReductionProxyAuth();
|
| - EXPECT_EQ(kDataReductionProxyAuth, result);
|
| + std::string salt = "8675309"; // Jenny's number to test the hash generator.
|
| + std::string salted_key = salt + kDataReductionProxyAuth + salt;
|
| + base::string16 expected_hash = UTF8ToUTF16(base::MD5String(salted_key));
|
| + EXPECT_EQ(expected_hash, settings_->AuthHashForSalt(8675309));
|
| }
|
|
|
| -// Test that the auth value set by preprocessor directive is not returned
|
| +// Test that the auth key set by preprocessor directive is not used
|
| // when an origin is set via a switch. This test only does anything useful in
|
| // Chrome builds.
|
| TEST_F(DataReductionProxySettingsTest,
|
| - TestGetDataReductionProxyAuthWithOriginSetViaSwitch) {
|
| + TestAuthHashGenerationWithOriginSetViaSwitch) {
|
| CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| switches::kSpdyProxyAuthOrigin, kDataReductionProxyOrigin);
|
| - std::string result = settings_->GetDataReductionProxyAuth();
|
| - EXPECT_EQ("", result);
|
| + EXPECT_EQ(base::string16(), settings_->AuthHashForSalt(8675309));
|
| }
|
|
|
| TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
|
| @@ -256,6 +285,38 @@ TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
|
| EXPECT_TRUE(settings_->IsDataReductionProxyManaged());
|
| }
|
|
|
| +TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) {
|
| + typedef struct {
|
| + std::string host;
|
| + std::string realm;
|
| + bool expected_to_succeed;
|
| + } challenge_test;
|
| +
|
| + challenge_test tests[] = {
|
| + {"foo:443", "", false}, // 0. No realm.
|
| + {"foo:443", "xxx", false}, // 1. Wrong realm.
|
| + {"foo:443", "spdyproxy", false}, // 2. Case matters.
|
| + {"foo:443", "SpdyProxy", true}, // 3. OK.
|
| + {"foo:443", "SpdyProxy1234567", true}, // 4. OK
|
| + {"bar:80", "SpdyProxy1234567", true}, // 5. OK.
|
| + {"foo:443", "SpdyProxyxxx", true}, // 6. OK
|
| + {"", "SpdyProxy1234567", false}, // 7. No challenger.
|
| + {"xxx:443", "SpdyProxy1234567", false}, // 8. Wrong host.
|
| + {"foo", "SpdyProxy1234567", false}, // 9. No port.
|
| + {"foo:80", "SpdyProxy1234567", false}, // 10.Wrong port.
|
| + {"bar:81", "SpdyProxy1234567", false}, // 11.Wrong port.
|
| + };
|
| +
|
| +
|
| + for (int i = 0; i <= 11; i++) {
|
| + scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo);
|
| + auth_info->challenger = net::HostPortPair::FromURL(GURL(tests[i].host));
|
| + auth_info->realm = tests[i].realm;
|
| + EXPECT_EQ(tests[i].expected_to_succeed,
|
| + settings_->IsAcceptableAuthChallenge(auth_info.get()));
|
| + }
|
| +}
|
| +
|
| TEST_F(DataReductionProxySettingsTest, TestResetDataReductionStatistics) {
|
| int64 original_content_length;
|
| int64 received_content_length;
|
| @@ -417,3 +478,7 @@ TEST_F(DataReductionProxySettingsTest, TestBypassList) {
|
| }
|
| }
|
|
|
| +TEST_F(DataReductionProxySettingsTest, TestAcceptableAuthTokens) {
|
| + AddProxyToCommandLine();
|
| +}
|
| +
|
|
|