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

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: Unit tests passing, feedback applied. 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..c59888754e3ea9844aafa400c903c76baa50d4aa 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 kDataReductionProxyOrigin[] = "https://foo.com:443/";
+const char kDataReductionProxyFallback[] = "http://bar.com:80";
const char kDataReductionProxyAuth[] = "12345";
const char kProbeURLWithOKResponse[] = "http://ok.org/";
@@ -59,6 +63,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 +99,8 @@ void DataReductionProxySettingsTestBase::AddProxyToCommandLine() {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kSpdyProxyAuthOrigin, kDataReductionProxyOrigin);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kSpdyProxyAuthFallback, kDataReductionProxyFallback);
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kSpdyProxyAuthValue, kDataReductionProxyAuth);
}
@@ -134,8 +145,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 +235,46 @@ 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();
+ dump_proxies(proxies);
+ EXPECT_EQ(0u, proxies.size());
+ 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());
+ EXPECT_EQ(443u,proxies[0].port());
+ EXPECT_EQ("bar.com",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.
bengr 2013/10/22 17:49:30 :)
marq (ping after 24h) 2013/10/22 21:18:01 Ack :-)
+ 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 +292,43 @@ 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.
bengr 2013/10/22 17:49:30 align
marq (ping after 24h) 2013/10/22 21:18:01 Done.
+ {"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++) {
+ 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()));
+ }
+}
+
+// More tests:
bengr 2013/10/22 17:49:30 Why is this comment here?
marq (ping after 24h) 2013/10/22 21:18:01 To remind me to write more tests. It's gone now an
+// -> test auth cache is populated and responds to challenges
+// -> test GetTokenForAuthChellenge
+
+
TEST_F(DataReductionProxySettingsTest, TestResetDataReductionStatistics) {
int64 original_content_length;
int64 received_content_length;
@@ -417,3 +490,7 @@ TEST_F(DataReductionProxySettingsTest, TestBypassList) {
}
}
+TEST_F(DataReductionProxySettingsTest, TestAcceptableAuthTokens) {
+ AddProxyToCommandLine();
bengr 2013/10/22 17:49:30 ?
marq (ping after 24h) 2013/10/22 21:18:01 Now gone.
+}
+

Powered by Google App Engine
This is Rietveld 408576698