Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Unified Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest.cc

Issue 30883003: Simple fallback implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patched
Patch Set: Further tests, applied feedback. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..19fffb6ac7be2871a9707f11cecafaa049932b9e 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,16 @@
#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/http/http_auth.h"
+#include "net/http/http_auth_cache.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 kDataReductionProxyOrigin[] = "https://foo.com:443/";
+const char kDataReductionProxyFallback[] = "http://bar.com:80";
const char kDataReductionProxyAuth[] = "12345";
const char kProbeURLWithOKResponse[] = "http://ok.org/";
@@ -59,6 +65,11 @@ class TestDataReductionProxySettings
return local_state_prefs_;
}
+ virtual std::string GetDefaultProxyHost() OVERRIDE { return std::string(); }
+ virtual std::string GetDefaultFallbackProxyHost() OVERRIDE {
+ return std::string();
+ }
+
void set_probe_result(const std::string& test_url,
const std::string& response,
bool success) {
@@ -90,6 +101,8 @@ void DataReductionProxySettingsTestBase::AddProxyToCommandLine() {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kSpdyProxyAuthOrigin, kDataReductionProxyOrigin);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kSpdyProxyAuthFallback, kDataReductionProxyFallback);
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kSpdyProxyAuthValue, kDataReductionProxyAuth);
}
@@ -134,8 +147,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 {
@@ -215,6 +230,29 @@ class DataReductionProxySettingsTest:
scoped_ptr<TestDataReductionProxySettings> settings_;
};
+TEST_F(DataReductionProxySettingsTest, TestAuthenticationInit) {
+ AddProxyToCommandLine();
+ net::HttpAuthCache cache;
+ settings_->InitDataReductionAuthentication(&cache);
+ DataReductionProxySettings::DataReductionProxyList proxies =
+ settings_->GetDataReductionProxies();
+ for (DataReductionProxySettings::DataReductionProxyList::iterator it =
+ proxies.begin();
bengr 2013/10/22 21:44:22 indent +3, i think.
marq (ping after 24h) 2013/10/23 12:23:20 Done.
+ it != proxies.end(); ++it) {
+ //GURL server = (*it).GetOrigin();
+ net::HttpAuthCache::Entry* entry =
+ cache.LookupByPath(*it, std::string());
+ EXPECT_TRUE(entry != NULL);
+ EXPECT_EQ(net::HttpAuth::AUTH_SCHEME_SPDYPROXY, entry->scheme());
+ EXPECT_EQ("SpdyProxy", entry->auth_challenge().substr(0,9));
+ }
+ GURL bad_server = GURL("https://bad.proxy.com/");
+ net::HttpAuthCache::Entry* entry =
+ cache.LookupByPath(bad_server, std::string());
+ EXPECT_TRUE(entry == NULL);
+
bengr 2013/10/22 21:44:22 Remove blank line.
marq (ping after 24h) 2013/10/23 12:23:20 Done.
+}
+
TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) {
AddProxyToCommandLine();
// SetUp() adds the origin to the command line, which should be returned here.
@@ -222,23 +260,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.com",proxies[0].host());
bengr 2013/10/22 21:44:22 Here and in the three lines below, add a space aft
marq (ping after 24h) 2013/10/23 12:23:20 Done.
+ EXPECT_EQ(443,proxies[0].EffectiveIntPort());
+ EXPECT_EQ("bar.com",proxies[1].host());
+ EXPECT_EQ(80,proxies[1].EffectiveIntPort());
+}
+
+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 +315,63 @@ TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
EXPECT_TRUE(settings_->IsDataReductionProxyManaged());
}
+TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) {
+ AddProxyToCommandLine();
+ typedef struct {
+ std::string host;
+ std::string realm;
+ bool expected_to_succeed;
+ } challenge_test;
+
+ challenge_test tests[] = {
+ {"foo.com:443", "", false}, // 0. No realm.
+ {"foo.com:443", "xxx", false}, // 1. Wrong realm.
+ {"foo.com:443", "spdyproxy", false}, // 2. Case matters.
+ {"foo.com:443", "SpdyProxy", true}, // 3. OK.
+ {"foo.com:443", "SpdyProxy1234567", true}, // 4. OK
+ {"bar.com:80", "SpdyProxy1234567", true}, // 5. OK.
+ {"foo.com:443", "SpdyProxyxxx", true}, // 6. OK
+ {"", "SpdyProxy1234567", false}, // 7. No challenger.
+ {"xxx.net:443", "SpdyProxy1234567", false}, // 8. Wrong host.
+ {"foo.com", "SpdyProxy1234567", false}, // 9. No port.
+ {"foo.com:80", "SpdyProxy1234567", false}, // 10.Wrong port.
+ {"bar.com:81", "SpdyProxy1234567", false}, // 11.Wrong port.
+ };
+
+ for (int i = 0; i <= 11; i++) {
bengr 2013/10/22 21:44:22 ++i
marq (ping after 24h) 2013/10/23 12:23:20 Done.
+ scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo);
+ auth_info->challenger = net::HostPortPair::FromString(tests[i].host);
+ auth_info->realm = tests[i].realm;
+ EXPECT_EQ(tests[i].expected_to_succeed,
+ settings_->IsAcceptableAuthChallenge(auth_info.get()));
+ }
+}
+
+TEST_F(DataReductionProxySettingsTest, TestChallengeTokens) {
+ AddProxyToCommandLine();
+ typedef struct {
+ std::string realm;
+ bool expected_empty_token;
+ } token_test;
+
+ token_test tests[] = {
+ {"", true}, // 0. No realm.
+ {"xxx", true}, // 1. realm too short.
+ {"spdyproxy", true}, // 2. no salt.
+ {"SpdyProxyxxx", true}, // 3. Salt not an int.
+ {"SpdyProxy1234567", false},// 4. OK
bengr 2013/10/22 21:44:22 Shift the comments all +1
marq (ping after 24h) 2013/10/23 12:23:20 Done.
+ };
+
+ for (int i = 0; i <= 4; i++) {
bengr 2013/10/22 21:44:22 ++i
marq (ping after 24h) 2013/10/23 12:23:20 Done.
+ scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo);
+ auth_info->challenger =
+ net::HostPortPair::FromString(kDataReductionProxyOrigin);
+ auth_info->realm = tests[i].realm;
+ base::string16 token = settings_->GetTokenForAuthChallenge(auth_info.get());
+ EXPECT_EQ(tests[i].expected_empty_token, token.empty());
+ }
+}
+
TEST_F(DataReductionProxySettingsTest, TestResetDataReductionStatistics) {
int64 original_content_length;
int64 received_content_length;
@@ -416,4 +532,3 @@ TEST_F(DataReductionProxySettingsTest, TestBypassList) {
EXPECT_EQ(expected[i++], *it);
}
}
-

Powered by Google App Engine
This is Rietveld 408576698