OLD | NEW |
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/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC, | 370 origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC, |
371 AuthCredentials(kAdmin, kPassword))); | 371 AuthCredentials(kAdmin, kPassword))); |
372 | 372 |
373 // Make sure that removing one entry still leaves the other available for | 373 // Make sure that removing one entry still leaves the other available for |
374 // lookup. | 374 // lookup. |
375 HttpAuthCache::Entry* entry = cache.Lookup( | 375 HttpAuthCache::Entry* entry = cache.Lookup( |
376 origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST); | 376 origin, kRealm3, HttpAuth::AUTH_SCHEME_DIGEST); |
377 EXPECT_FALSE(NULL == entry); | 377 EXPECT_FALSE(NULL == entry); |
378 } | 378 } |
379 | 379 |
| 380 TEST(HttpAuthCacheTest, ClearEntriesAddedWithin) { |
| 381 GURL origin("http://foobar.com"); |
| 382 |
| 383 HttpAuthCache cache; |
| 384 base::TimeTicks old_creation_time = |
| 385 base::TimeTicks::Now() - base::TimeDelta::FromMinutes(2); |
| 386 cache |
| 387 .Add(origin, kRealm1, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm1", |
| 388 AuthCredentials(kAlice, k123), "/") |
| 389 ->set_creation_time_for_testing(old_creation_time); |
| 390 cache |
| 391 .Add(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm2", |
| 392 AuthCredentials(kRoot, kWileCoyote), "/") |
| 393 ->set_creation_time_for_testing(old_creation_time); |
| 394 |
| 395 cache.Add(origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm3", |
| 396 AuthCredentials(kAlice2, k1234), "/"); |
| 397 cache.Add(origin, kRealm4, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm4", |
| 398 AuthCredentials(kUsername, kPassword), "/"); |
| 399 // Add path to existing entry. |
| 400 cache.Add(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm2", |
| 401 AuthCredentials(kAdmin, kPassword), "/baz/"); |
| 402 |
| 403 cache.ClearEntriesAddedWithin(base::TimeDelta::FromMinutes(1)); |
| 404 |
| 405 EXPECT_NE(nullptr, |
| 406 cache.Lookup(origin, kRealm1, HttpAuth::AUTH_SCHEME_BASIC)); |
| 407 EXPECT_NE(nullptr, |
| 408 cache.Lookup(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC)); |
| 409 // Creation time is set for a whole entry rather than for a particular path. |
| 410 // Path added within the requested duration isn't be removed. |
| 411 EXPECT_NE(nullptr, cache.LookupByPath(origin, "/baz/")); |
| 412 EXPECT_EQ(nullptr, |
| 413 cache.Lookup(origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC)); |
| 414 EXPECT_EQ(nullptr, |
| 415 cache.Lookup(origin, kRealm4, HttpAuth::AUTH_SCHEME_BASIC)); |
| 416 } |
| 417 |
380 TEST(HttpAuthCacheTest, UpdateStaleChallenge) { | 418 TEST(HttpAuthCacheTest, UpdateStaleChallenge) { |
381 HttpAuthCache cache; | 419 HttpAuthCache cache; |
382 GURL origin("http://foobar2.com"); | 420 GURL origin("http://foobar2.com"); |
383 std::unique_ptr<HttpAuthHandler> digest_handler(new MockAuthHandler( | 421 std::unique_ptr<HttpAuthHandler> digest_handler(new MockAuthHandler( |
384 HttpAuth::AUTH_SCHEME_DIGEST, kRealm1, HttpAuth::AUTH_PROXY)); | 422 HttpAuth::AUTH_SCHEME_DIGEST, kRealm1, HttpAuth::AUTH_PROXY)); |
385 HttpAuthCache::Entry* entry_pre = cache.Add( | 423 HttpAuthCache::Entry* entry_pre = cache.Add( |
386 origin, | 424 origin, |
387 digest_handler->realm(), | 425 digest_handler->realm(), |
388 digest_handler->auth_scheme(), | 426 digest_handler->auth_scheme(), |
389 "Digest realm=Realm1," | 427 "Digest realm=Realm1," |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 CheckPathExistence(0, i, false); | 638 CheckPathExistence(0, i, false); |
601 | 639 |
602 for (int i = 0; i < kMaxPaths; ++i) | 640 for (int i = 0; i < kMaxPaths; ++i) |
603 CheckPathExistence(0, i + 3, true); | 641 CheckPathExistence(0, i + 3, true); |
604 | 642 |
605 for (int i = 0; i < kMaxRealms; ++i) | 643 for (int i = 0; i < kMaxRealms; ++i) |
606 CheckRealmExistence(i, true); | 644 CheckRealmExistence(i, true); |
607 } | 645 } |
608 | 646 |
609 } // namespace net | 647 } // namespace net |
OLD | NEW |