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

Side by Side Diff: net/http/http_auth_cache_unittest.cc

Issue 2097043002: Clear HTTP auth data on clearing browsing data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More unittest fixes Created 4 years, 3 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
« no previous file with comments | « net/http/http_auth_cache.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "base/run_loop.h"
7 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h"
11 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
12 #include "net/http/http_auth_cache.h" 14 #include "net/http/http_auth_cache.h"
13 #include "net/http/http_auth_handler.h" 15 #include "net/http/http_auth_handler.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 using base::ASCIIToUTF16; 18 using base::ASCIIToUTF16;
17 19
18 namespace net { 20 namespace net {
19 21
20 namespace { 22 namespace {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const base::string16 kPassword(ASCIIToUTF16("password")); 71 const base::string16 kPassword(ASCIIToUTF16("password"));
70 const base::string16 kRoot(ASCIIToUTF16("root")); 72 const base::string16 kRoot(ASCIIToUTF16("root"));
71 const base::string16 kUsername(ASCIIToUTF16("username")); 73 const base::string16 kUsername(ASCIIToUTF16("username"));
72 const base::string16 kWileCoyote(ASCIIToUTF16("wilecoyote")); 74 const base::string16 kWileCoyote(ASCIIToUTF16("wilecoyote"));
73 75
74 AuthCredentials CreateASCIICredentials(const char* username, 76 AuthCredentials CreateASCIICredentials(const char* username,
75 const char* password) { 77 const char* password) {
76 return AuthCredentials(ASCIIToUTF16(username), ASCIIToUTF16(password)); 78 return AuthCredentials(ASCIIToUTF16(username), ASCIIToUTF16(password));
77 } 79 }
78 80
81 // Ensures that difference between TimeTicks of entering and leaving this
82 // function is non-zero.
83 void EnsureTimeDifference() {
84 base::TimeTicks begin_time = base::TimeTicks::Now();
85 base::RunLoop run_loop;
86 base::Closure quit_closure(run_loop.QuitClosure());
87 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
88 FROM_HERE, quit_closure,
89 base::TimeDelta::FromMilliseconds(
90 base::TimeTicks::IsHighResolution() ? 1 : 20));
91 run_loop.Run();
92 ASSERT_FALSE((base::TimeTicks::Now() - begin_time).is_zero());
93 }
94
79 } // namespace 95 } // namespace
80 96
81 // Test adding and looking-up cache entries (both by realm and by path). 97 // Test adding and looking-up cache entries (both by realm and by path).
82 TEST(HttpAuthCacheTest, Basic) { 98 TEST(HttpAuthCacheTest, Basic) {
83 GURL origin("http://www.google.com"); 99 GURL origin("http://www.google.com");
84 HttpAuthCache cache; 100 HttpAuthCache cache;
85 HttpAuthCache::Entry* entry; 101 HttpAuthCache::Entry* entry;
86 102
87 // Add cache entries for 4 realms: "Realm1", "Realm2", "Realm3" and 103 // Add cache entries for 4 realms: "Realm1", "Realm2", "Realm3" and
88 // "Realm4" 104 // "Realm4"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC, 386 origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC,
371 AuthCredentials(kAdmin, kPassword))); 387 AuthCredentials(kAdmin, kPassword)));
372 388
373 // Make sure that removing one entry still leaves the other available for 389 // Make sure that removing one entry still leaves the other available for
374 // lookup. 390 // lookup.
375 HttpAuthCache::Entry* entry = cache.Lookup( 391 HttpAuthCache::Entry* entry = cache.Lookup(
376 origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST); 392 origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST);
377 EXPECT_FALSE(NULL == entry); 393 EXPECT_FALSE(NULL == entry);
378 } 394 }
379 395
396 TEST(HttpAuthCacheTest, ClearEntriesAddedWithin) {
397 GURL origin("http://foobar.com");
398
399 HttpAuthCache cache;
400 cache.Add(origin, kRealm1, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm1",
401 AuthCredentials(kAlice, k123), "/");
402 cache.Add(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm2",
403 AuthCredentials(kRoot, kWileCoyote), "/");
404
405 EnsureTimeDifference();
406 base::TimeTicks start_time = base::TimeTicks::Now();
407
408 cache.Add(origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm3",
409 AuthCredentials(kAlice2, k1234), "/");
410 cache.Add(origin, kRealm4, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm4",
411 AuthCredentials(kUsername, kPassword), "/");
412 // Add path to existing entry.
413 cache.Add(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm2",
414 AuthCredentials(kAdmin, kPassword), "/baz/");
415
416 EnsureTimeDifference();
417 cache.ClearEntriesAddedWithin(base::TimeTicks::Now() - start_time);
mmenke 2016/08/25 19:28:02 I still don't think this works - ClearEntriesAdded
418
419 EXPECT_NE(nullptr,
420 cache.Lookup(origin, kRealm1, HttpAuth::AUTH_SCHEME_BASIC));
421 EXPECT_NE(nullptr,
422 cache.Lookup(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC));
423 // Creation time is set for a whole entry rather than for a particular path.
424 // Path added within the requested duration isn't be removed.
425 EXPECT_NE(nullptr, cache.LookupByPath(origin, "/baz/"));
426 EXPECT_EQ(nullptr,
427 cache.Lookup(origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC));
428 EXPECT_EQ(nullptr,
429 cache.Lookup(origin, kRealm4, HttpAuth::AUTH_SCHEME_BASIC));
430 }
431
380 TEST(HttpAuthCacheTest, UpdateStaleChallenge) { 432 TEST(HttpAuthCacheTest, UpdateStaleChallenge) {
381 HttpAuthCache cache; 433 HttpAuthCache cache;
382 GURL origin("http://foobar2.com"); 434 GURL origin("http://foobar2.com");
383 std::unique_ptr<HttpAuthHandler> digest_handler(new MockAuthHandler( 435 std::unique_ptr<HttpAuthHandler> digest_handler(new MockAuthHandler(
384 HttpAuth::AUTH_SCHEME_DIGEST, kRealm1, HttpAuth::AUTH_PROXY)); 436 HttpAuth::AUTH_SCHEME_DIGEST, kRealm1, HttpAuth::AUTH_PROXY));
385 HttpAuthCache::Entry* entry_pre = cache.Add( 437 HttpAuthCache::Entry* entry_pre = cache.Add(
386 origin, 438 origin,
387 digest_handler->realm(), 439 digest_handler->realm(),
388 digest_handler->auth_scheme(), 440 digest_handler->auth_scheme(),
389 "Digest realm=Realm1," 441 "Digest realm=Realm1,"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 CheckPathExistence(0, i, false); 652 CheckPathExistence(0, i, false);
601 653
602 for (int i = 0; i < kMaxPaths; ++i) 654 for (int i = 0; i < kMaxPaths; ++i)
603 CheckPathExistence(0, i + 3, true); 655 CheckPathExistence(0, i + 3, true);
604 656
605 for (int i = 0; i < kMaxRealms; ++i) 657 for (int i = 0; i < kMaxRealms; ++i)
606 CheckRealmExistence(i, true); 658 CheckRealmExistence(i, true);
607 } 659 }
608 660
609 } // namespace net 661 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698