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

Side by Side Diff: net/base/sdch_manager_unittest.cc

Issue 329373002: Avoid advertising SDCH over HTTPS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments. Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/sdch_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits.h> 5 #include <limits.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 11 matching lines...) Expand all
22 //------------------------------------------------------------------------------ 22 //------------------------------------------------------------------------------
23 23
24 class SdchManagerTest : public testing::Test { 24 class SdchManagerTest : public testing::Test {
25 protected: 25 protected:
26 SdchManagerTest() 26 SdchManagerTest()
27 : sdch_manager_(new SdchManager) { 27 : sdch_manager_(new SdchManager) {
28 } 28 }
29 29
30 SdchManager* sdch_manager() { return sdch_manager_.get(); } 30 SdchManager* sdch_manager() { return sdch_manager_.get(); }
31 31
32 // Reset globals back to default state.
33 virtual void TearDown() {
34 SdchManager::EnableSdchSupport(true);
35 SdchManager::EnableSecureSchemeSupport(false);
36 }
37
32 private: 38 private:
33 scoped_ptr<SdchManager> sdch_manager_; 39 scoped_ptr<SdchManager> sdch_manager_;
34 }; 40 };
35 41
36 //------------------------------------------------------------------------------ 42 //------------------------------------------------------------------------------
37 static std::string NewSdchDictionary(const std::string& domain) { 43 static std::string NewSdchDictionary(const std::string& domain) {
38 std::string dictionary; 44 std::string dictionary;
39 if (!domain.empty()) { 45 if (!domain.empty()) {
40 dictionary.append("Domain: "); 46 dictionary.append("Domain: ");
41 dictionary.append(domain); 47 dictionary.append(domain);
42 dictionary.append("\n"); 48 dictionary.append("\n");
43 } 49 }
44 dictionary.append("\n"); 50 dictionary.append("\n");
45 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1); 51 dictionary.append(kTestVcdiffDictionary, sizeof(kTestVcdiffDictionary) - 1);
46 return dictionary; 52 return dictionary;
47 } 53 }
48 54
49 TEST_F(SdchManagerTest, DomainSupported) { 55 TEST_F(SdchManagerTest, DomainSupported) {
50 GURL google_url("http://www.google.com"); 56 GURL google_url("http://www.google.com");
51 57
52 net::SdchManager::EnableSdchSupport(false); 58 SdchManager::EnableSdchSupport(false);
53 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url)); 59 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url));
54 net::SdchManager::EnableSdchSupport(true); 60 SdchManager::EnableSdchSupport(true);
55 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); 61 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
56 } 62 }
57 63
58 TEST_F(SdchManagerTest, DomainBlacklisting) { 64 TEST_F(SdchManagerTest, DomainBlacklisting) {
59 GURL test_url("http://www.test.com"); 65 GURL test_url("http://www.test.com");
60 GURL google_url("http://www.google.com"); 66 GURL google_url("http://www.google.com");
61 67
62 sdch_manager()->BlacklistDomain(test_url); 68 sdch_manager()->BlacklistDomain(test_url);
63 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url)); 69 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url));
64 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url)); 70 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 sdch_manager()->GetAvailDictionaryList( 171 sdch_manager()->GetAvailDictionaryList(
166 GURL("https://" + dictionary_domain + "/test"), 172 GURL("https://" + dictionary_domain + "/test"),
167 &dictionary_list); 173 &dictionary_list);
168 EXPECT_TRUE(dictionary_list.empty()); 174 EXPECT_TRUE(dictionary_list.empty());
169 } 175 }
170 176
171 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { 177 TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
172 std::string dictionary_domain("x.y.z.google.com"); 178 std::string dictionary_domain("x.y.z.google.com");
173 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 179 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
174 180
175 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, 181 EXPECT_FALSE(sdch_manager()->AddSdchDictionary(
176 GURL("https://" + dictionary_domain))); 182 dictionary_text, GURL("https://" + dictionary_domain)));
183 SdchManager::EnableSecureSchemeSupport(true);
184 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(
185 dictionary_text, GURL("https://" + dictionary_domain)));
177 186
178 GURL target_url("https://" + dictionary_domain + "/test"); 187 GURL target_url("https://" + dictionary_domain + "/test");
179 std::string dictionary_list; 188 std::string dictionary_list;
180 // HTTPS target URL should advertise dictionary if secure scheme support is 189 // HTTPS target URL should advertise dictionary if secure scheme support is
181 // enabled. 190 // enabled.
182 sdch_manager()->EnableSecureSchemeSupport(true);
183 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 191 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
184 EXPECT_FALSE(dictionary_list.empty()); 192 EXPECT_FALSE(dictionary_list.empty());
185 193
186 // Dictionary should be available. 194 // Dictionary should be available.
187 SdchManager::Dictionary* dictionary = NULL; 195 SdchManager::Dictionary* dictionary = NULL;
188 std::string client_hash; 196 std::string client_hash;
189 std::string server_hash; 197 std::string server_hash;
190 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 198 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
191 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 199 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
192 EXPECT_TRUE(dictionary != NULL); 200 EXPECT_TRUE(dictionary != NULL);
193 } 201 }
194 202
195 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) { 203 TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
196 std::string dictionary_domain("x.y.z.google.com"); 204 std::string dictionary_domain("x.y.z.google.com");
197 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); 205 std::string dictionary_text(NewSdchDictionary(dictionary_domain));
198 206
199 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text, 207 EXPECT_TRUE(sdch_manager()->AddSdchDictionary(dictionary_text,
200 GURL("http://" + dictionary_domain))); 208 GURL("http://" + dictionary_domain)));
201 209
202 GURL target_url("https://" + dictionary_domain + "/test"); 210 GURL target_url("https://" + dictionary_domain + "/test");
203 std::string dictionary_list; 211 std::string dictionary_list;
204 // HTTPS target URL should not advertise dictionary acquired over HTTP even if 212 // HTTPS target URL should not advertise dictionary acquired over HTTP even if
205 // secure scheme support is enabled. 213 // secure scheme support is enabled.
206 sdch_manager()->EnableSecureSchemeSupport(true); 214 SdchManager::EnableSecureSchemeSupport(true);
207 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list); 215 sdch_manager()->GetAvailDictionaryList(target_url, &dictionary_list);
208 EXPECT_TRUE(dictionary_list.empty()); 216 EXPECT_TRUE(dictionary_list.empty());
209 217
210 SdchManager::Dictionary* dictionary = NULL; 218 SdchManager::Dictionary* dictionary = NULL;
211 std::string client_hash; 219 std::string client_hash;
212 std::string server_hash; 220 std::string server_hash;
213 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash); 221 sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
214 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary); 222 sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
215 EXPECT_TRUE(dictionary == NULL); 223 EXPECT_TRUE(dictionary == NULL);
216 } 224 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 &dictionary); 422 &dictionary);
415 EXPECT_FALSE(dictionary); 423 EXPECT_FALSE(dictionary);
416 424
417 second_manager.GetVcdiffDictionary( 425 second_manager.GetVcdiffDictionary(
418 server_hash_1, 426 server_hash_1,
419 GURL("http://" + dictionary_domain_1 + "/random_url"), 427 GURL("http://" + dictionary_domain_1 + "/random_url"),
420 &dictionary); 428 &dictionary);
421 EXPECT_FALSE(dictionary); 429 EXPECT_FALSE(dictionary);
422 } 430 }
423 431
432 TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
433 GURL url("http://www.google.com");
434 GURL secure_url("https://www.google.com");
435
436 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
437 EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(secure_url));
438
439 SdchManager::EnableSecureSchemeSupport(true);
440 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
441 EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(secure_url));
442 }
443
424 } // namespace net 444 } // namespace net
425 445
OLDNEW
« no previous file with comments | « net/base/sdch_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698