summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth_cache_unittest.cc
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-13 16:21:40 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-13 16:21:40 +0000
commit9001c8ca3fa4ccd1dee1c54dbedf3e2619179f11 (patch)
treeba3e20bc47a210d60a16afb38f38bc775274db86 /net/http/http_auth_cache_unittest.cc
parentdc7364f1c2f0c9fa29c5dad211892f45e31c9b6e (diff)
downloadchromium_src-9001c8ca3fa4ccd1dee1c54dbedf3e2619179f11.zip
chromium_src-9001c8ca3fa4ccd1dee1c54dbedf3e2619179f11.tar.gz
chromium_src-9001c8ca3fa4ccd1dee1c54dbedf3e2619179f11.tar.bz2
Added authentication scheme as key to HttpAuthCache.
Behavioral changes are small; this is mostly a syntactic sugar change. But there are a few behavioral changes: * If a web site replies with different schemes for the same realm, we'll have two entries in the cache. * There will not be a log entry in HttpNetworkTransaction::SelectNextAuthIdentityToTry when we have the wrong authentication scheme (we don't see that entry any more) * We will no longer return ERR_TUNNEL_CONNECTION_FAILED from SocketStream::HandleAuthChallenge when there's an entry in the cache with a non-basic authentication scheme (we won't know it's there). Contributed by rdsmith@chromium.org BUG=33433 TEST=HttpAuthCacheTest.* (as modified in this commit), HttpNetworkTransactionTest.*, SocketStreamTest.*, only on Linux. Review URL: http://codereview.chromium.org/1949004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth_cache_unittest.cc')
-rw-r--r--net/http/http_auth_cache_unittest.cc112
1 files changed, 81 insertions, 31 deletions
diff --git a/net/http/http_auth_cache_unittest.cc b/net/http/http_auth_cache_unittest.cc
index c233f01..28cb138 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());