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

Unified Diff: net/http/http_auth_cache_unittest.cc

Issue 1949004: Added authentication scheme as key to HttpAuthCache. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Fixed nits from eroman. Created 10 years, 7 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
« no previous file with comments | « net/http/http_auth_cache.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_auth_cache_unittest.cc
diff --git a/net/http/http_auth_cache_unittest.cc b/net/http/http_auth_cache_unittest.cc
index c233f01d865773577b899f628ac8fe90f462bb28..28cb138f6204dd3dea6762c1d9363fed3aa5e34e 100644
--- a/net/http/http_auth_cache_unittest.cc
+++ b/net/http/http_auth_cache_unittest.cc
@@ -69,58 +69,89 @@ TEST(HttpAuthCacheTest, Basic) {
cache.Add(origin, realm2_handler, L"realm2-user", L"realm2-password",
"/foo2/index.html");
- scoped_refptr<HttpAuthHandler> realm3_handler =
+ scoped_refptr<HttpAuthHandler> realm3_basic_handler =
new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_PROXY);
- cache.Add(origin, realm3_handler, L"realm3-user", L"realm3-password", "");
+ cache.Add(origin, realm3_basic_handler, L"realm3-basic-user",
+ L"realm3-basic-password", "");
+
+ scoped_refptr<HttpAuthHandler> realm3_digest_handler =
+ new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_PROXY);
+ cache.Add(origin, realm3_digest_handler, L"realm3-digest-user",
+ L"realm3-digest-password", "/baz/index.html");
// There is no Realm4
- entry = cache.LookupByRealm(origin, "Realm4");
+ entry = cache.Lookup(origin, "Realm4", "basic");
EXPECT_TRUE(NULL == entry);
// While Realm3 does exist, the origin scheme is wrong.
- entry = cache.LookupByRealm(GURL("https://www.google.com"), "Realm3");
+ entry = cache.Lookup(GURL("https://www.google.com"), "Realm3",
+ "basic");
EXPECT_TRUE(NULL == entry);
- // Valid lookup by realm.
- entry = cache.LookupByRealm(GURL("http://www.google.com:80"), "Realm3");
+ // Realm, origin scheme ok, authentication scheme wrong
+ entry = cache.Lookup(GURL("http://www.google.com"), "Realm1", "digest");
+ EXPECT_TRUE(NULL == entry);
+
+ // Valid lookup by origin, realm, scheme.
+ entry = cache.Lookup(GURL("http://www.google.com:80"), "Realm3", "basic");
EXPECT_FALSE(NULL == entry);
- EXPECT_TRUE(entry->handler() == realm3_handler.get());
- EXPECT_EQ(L"realm3-user", entry->username());
- EXPECT_EQ(L"realm3-password", entry->password());
+ EXPECT_TRUE(entry->handler() == realm3_basic_handler.get());
+ EXPECT_EQ(L"realm3-basic-user", entry->username());
+ EXPECT_EQ(L"realm3-basic-password", entry->password());
+
+ // Valid lookup by origin, realm, scheme when there's a duplicate
+ // origin, realm in the cache
+ entry = cache.Lookup(GURL("http://www.google.com:80"), "Realm3", "digest");
+ EXPECT_FALSE(NULL == entry);
+ EXPECT_TRUE(entry->handler() == realm3_digest_handler.get());
+ EXPECT_EQ(L"realm3-digest-user", entry->username());
+ EXPECT_EQ(L"realm3-digest-password", entry->password());
// Valid lookup by realm.
- entry = cache.LookupByRealm(origin, "Realm2");
+ entry = cache.Lookup(origin, "Realm2", "basic");
EXPECT_FALSE(NULL == entry);
EXPECT_TRUE(entry->handler() == realm2_handler.get());
EXPECT_EQ(L"realm2-user", entry->username());
EXPECT_EQ(L"realm2-password", entry->password());
// Check that subpaths are recognized.
- HttpAuthCache::Entry* realm2Entry = cache.LookupByRealm(origin, "Realm2");
- EXPECT_FALSE(NULL == realm2Entry);
+ HttpAuthCache::Entry* realm2_entry = cache.Lookup(origin, "Realm2", "basic");
+ EXPECT_FALSE(NULL == realm2_entry);
// Positive tests:
entry = cache.LookupByPath(origin, "/foo2/index.html");
- EXPECT_TRUE(realm2Entry == entry);
+ EXPECT_TRUE(realm2_entry == entry);
entry = cache.LookupByPath(origin, "/foo2/foobar.html");
- EXPECT_TRUE(realm2Entry == entry);
+ EXPECT_TRUE(realm2_entry == entry);
entry = cache.LookupByPath(origin, "/foo2/bar/index.html");
- EXPECT_TRUE(realm2Entry == entry);
+ EXPECT_TRUE(realm2_entry == entry);
entry = cache.LookupByPath(origin, "/foo2/");
- EXPECT_TRUE(realm2Entry == entry);
+ EXPECT_TRUE(realm2_entry == entry);
+
// Negative tests:
entry = cache.LookupByPath(origin, "/foo2");
- EXPECT_FALSE(realm2Entry == entry);
+ EXPECT_FALSE(realm2_entry == entry);
entry = cache.LookupByPath(origin, "/foo3/index.html");
- EXPECT_FALSE(realm2Entry == entry);
+ EXPECT_FALSE(realm2_entry == entry);
entry = cache.LookupByPath(origin, "");
- EXPECT_FALSE(realm2Entry == entry);
+ EXPECT_FALSE(realm2_entry == entry);
entry = cache.LookupByPath(origin, "/");
- EXPECT_FALSE(realm2Entry == entry);
+ EXPECT_FALSE(realm2_entry == entry);
+
+ // Confirm we find the same realm, different auth scheme by path lookup
+ HttpAuthCache::Entry* realm3_digest_entry =
+ cache.Lookup(origin, "Realm3", "digest");
+ EXPECT_FALSE(NULL == realm3_digest_entry);
+ entry = cache.LookupByPath(origin, "/baz/index.html");
+ EXPECT_TRUE(realm3_digest_entry == entry);
+ entry = cache.LookupByPath(origin, "/baz/");
+ EXPECT_TRUE(realm3_digest_entry == entry);
+ entry = cache.LookupByPath(origin, "/baz");
+ EXPECT_FALSE(realm3_digest_entry == entry);
// Lookup using empty path (may be used for proxy).
entry = cache.LookupByPath(origin, "");
EXPECT_FALSE(NULL == entry);
- EXPECT_TRUE(entry->handler() == realm3_handler.get());
+ EXPECT_TRUE(entry->handler() == realm3_basic_handler.get());
EXPECT_EQ("Realm3", entry->realm());
}
@@ -170,7 +201,7 @@ TEST(HttpAuthCacheTest, AddToExistingEntry) {
cache.Add(origin, handler, L"user2", L"password2", "/z/y/x/");
cache.Add(origin, handler, L"user3", L"password3", "/z/y");
- HttpAuthCache::Entry* entry = cache.LookupByRealm(origin, "MyRealm");
+ HttpAuthCache::Entry* entry = cache.Lookup(origin, "MyRealm", "basic");
EXPECT_TRUE(entry == orig_entry);
EXPECT_EQ(L"user3", entry->username());
@@ -190,32 +221,51 @@ TEST(HttpAuthCacheTest, Remove) {
scoped_refptr<HttpAuthHandler> realm2_handler =
new MockAuthHandler("basic", "Realm2", HttpAuth::AUTH_SERVER);
- scoped_refptr<HttpAuthHandler> realm3_handler =
+ scoped_refptr<HttpAuthHandler> realm3_basic_handler =
new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_SERVER);
+ scoped_refptr<HttpAuthHandler> realm3_digest_handler =
+ new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_SERVER);
+
HttpAuthCache cache;
cache.Add(origin, realm1_handler, L"alice", L"123", "/");
cache.Add(origin, realm2_handler, L"bob", L"princess", "/");
- cache.Add(origin, realm3_handler, L"admin", L"password", "/");
+ cache.Add(origin, realm3_basic_handler, L"admin", L"password", "/");
+ cache.Add(origin, realm3_digest_handler, L"root", L"wilecoyote", "/");
// Fails, because there is no realm "Realm4".
- EXPECT_FALSE(cache.Remove(origin, "Realm4", L"alice", L"123"));
+ EXPECT_FALSE(cache.Remove(origin, "Realm4", "basic", L"alice", L"123"));
// Fails because the origin is wrong.
EXPECT_FALSE(cache.Remove(
- GURL("http://foobar2.com:100"), "Realm1", L"alice", L"123"));
+ GURL("http://foobar2.com:100"), "Realm1", "basic", L"alice", L"123"));
// Fails because the username is wrong.
- EXPECT_FALSE(cache.Remove(origin, "Realm1", L"alice2", L"123"));
+ EXPECT_FALSE(cache.Remove(origin, "Realm1", "basic", L"alice2", L"123"));
// Fails because the password is wrong.
- EXPECT_FALSE(cache.Remove(origin, "Realm1", L"alice", L"1234"));
+ EXPECT_FALSE(cache.Remove(origin, "Realm1", "basic", L"alice", L"1234"));
+
+ // Fails because the authentication type is wrong.
+ EXPECT_FALSE(cache.Remove(origin, "Realm1", "digest", L"alice", L"123"));
// Succeeds.
- EXPECT_TRUE(cache.Remove(origin, "Realm1", L"alice", L"123"));
+ EXPECT_TRUE(cache.Remove(origin, "Realm1", "basic", L"alice", L"123"));
// Fails because we just deleted the entry!
- EXPECT_FALSE(cache.Remove(origin, "Realm1", L"alice", L"123"));
+ EXPECT_FALSE(cache.Remove(origin, "Realm1", "basic", L"alice", L"123"));
+
+ // Succeed when there are two authentication types for the same origin,realm.
+ EXPECT_TRUE(cache.Remove(origin, "Realm3", "digest", L"root", L"wilecoyote"));
+
+ // Succeed as above, but when entries were added in opposite order
+ cache.Add(origin, realm3_digest_handler, L"root", L"wilecoyote", "/");
+ EXPECT_TRUE(cache.Remove(origin, "Realm3", "basic", L"admin", L"password"));
+
+ // Make sure that removing one entry still leaves the other available
+ // for lookup
+ HttpAuthCache::Entry* entry = cache.Lookup(origin, "Realm3", "digest");
+ EXPECT_FALSE(NULL == entry);
}
// Test fixture class for eviction tests (contains helpers for bulk
@@ -246,7 +296,7 @@ class HttpAuthCacheEvictionTest : public testing::Test {
void CheckRealmExistence(int realm_i, bool exists) {
const HttpAuthCache::Entry* entry =
- cache_.LookupByRealm(origin_, GenerateRealm(realm_i));
+ cache_.Lookup(origin_, GenerateRealm(realm_i), "basic");
if (exists) {
EXPECT_FALSE(entry == NULL);
EXPECT_EQ(GenerateRealm(realm_i), entry->realm());
« no previous file with comments | « net/http/http_auth_cache.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698