diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-15 06:43:48 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-15 06:43:48 +0000 |
commit | 515838ce76cb8bec7f51f6143cac74f113e247ad (patch) | |
tree | 71b70d594974310b35d1c8f7843aeda5717c044b /net/base | |
parent | 92352a66515fd9a01f538529356ad45870109f28 (diff) | |
download | chromium_src-515838ce76cb8bec7f51f6143cac74f113e247ad.zip chromium_src-515838ce76cb8bec7f51f6143cac74f113e247ad.tar.gz chromium_src-515838ce76cb8bec7f51f6143cac74f113e247ad.tar.bz2 |
post-winhttp cleanup: refactor net/base/auth_cache into net/ftp/ftp_auth_cache.
Also moves AuthCache::HttpKey() --> GetSignonRealmKey().
Review URL: http://codereview.chromium.org/18218
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/auth_cache.cc | 49 | ||||
-rw-r--r-- | net/base/auth_cache.h | 62 | ||||
-rw-r--r-- | net/base/auth_cache_unittest.cc | 48 |
3 files changed, 0 insertions, 159 deletions
diff --git a/net/base/auth_cache.cc b/net/base/auth_cache.cc deleted file mode 100644 index 025a520..0000000 --- a/net/base/auth_cache.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/base/auth_cache.h" - -#include "base/string_util.h" -#include "googleurl/src/gurl.h" - -namespace net { - -// Create an AuthCacheKey from url and auth_info. -// -// The cache key is made up of two components, separated by a slash /. -// 1. The host (proxy or server) requesting authentication. For a server, -// this component also includes the scheme (protocol) and port (if not -// the default port for the protocol) to distinguish between multiple -// servers running on the same computer. -// 2. The realm. -// -// The format of the cache key for proxy auth is: -// proxy-host/auth-realm -// The format of the cache key for server auth is: -// url-scheme://url-host[:url-port]/auth-realm - -// static -AuthCache::AuthCacheKey AuthCache::HttpKey( - const GURL& url, - const AuthChallengeInfo& auth_info) { - AuthCacheKey auth_cache_key; - if (auth_info.is_proxy) { - auth_cache_key = WideToASCII(auth_info.host); - auth_cache_key.append("/"); - } else { - // Take scheme, host, and port from the url. - auth_cache_key = url.GetOrigin().spec(); - // This ends with a "/". - } - auth_cache_key.append(WideToUTF8(auth_info.realm)); - return auth_cache_key; -} - -AuthData* AuthCache::Lookup(const AuthCacheKey& key) { - AuthCacheMap::iterator iter = cache_.find(key); - return (iter == cache_.end()) ? NULL : iter->second; -} - -} // namespace net - diff --git a/net/base/auth_cache.h b/net/base/auth_cache.h deleted file mode 100644 index ff7444d..0000000 --- a/net/base/auth_cache.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_BASE_AUTH_CACHE_H__ -#define NET_BASE_AUTH_CACHE_H__ - -#include <string> -#include <map> - -#include "net/base/auth.h" - -class GURL; - -namespace net { - -// The AuthCache class is a simple cache structure to store authentication -// information for ftp or http/https sites. Provides lookup, addition, and -// validation of entries. -class AuthCache { - public: - AuthCache() {} - ~AuthCache() {} - - typedef std::string AuthCacheKey; - - // Return the key for looking up the auth data in the auth cache for HTTP, - // consisting of the scheme, host, and port of the request URL and the - // realm in the auth challenge. - static AuthCacheKey HttpKey(const GURL& url, - const AuthChallengeInfo& auth_info); - - // Check if we have authentication data for given key. The key parameter - // is input, consisting of the hostname and any other info (such as realm) - // appropriate for the protocol. Return the address of corresponding - // AuthData object (if found) or NULL (if not found). - AuthData* Lookup(const AuthCacheKey& key); - - // Add to the cache. If key already exists, this will overwrite. Both - // parameters are IN only. - void Add(const AuthCacheKey& key, AuthData* value) { - cache_[key] = value; - } - - // Called when we have an auth failure to remove - // the likely invalid credentials. - void Remove(const AuthCacheKey& key) { - cache_.erase(key); - } - - private: - typedef scoped_refptr<AuthData> AuthCacheValue; - typedef std::map<AuthCacheKey,AuthCacheValue> AuthCacheMap; - - // internal representation of cache, an STL map. - AuthCacheMap cache_; -}; - -} // namespace net - -#endif // NET_BASE_AUTH_CACHE_H__ - diff --git a/net/base/auth_cache_unittest.cc b/net/base/auth_cache_unittest.cc deleted file mode 100644 index e730345..0000000 --- a/net/base/auth_cache_unittest.cc +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "googleurl/src/gurl.h" -#include "net/base/auth_cache.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class AuthCacheTest : public testing::Test { -}; - -} // namespace - -TEST(AuthCacheTest, HttpKey) { - scoped_refptr<net::AuthChallengeInfo> auth_info = new net::AuthChallengeInfo; - auth_info->is_proxy = false; // server auth - // auth_info->host is intentionally left empty. - auth_info->scheme = L"Basic"; - auth_info->realm = L"WallyWorld"; - - std::string url[] = { - "https://www.nowhere.org/dir/index.html", - "https://www.nowhere.org:443/dir/index.html", // default port - "https://www.nowhere.org:8443/dir/index.html", // non-default port - "https://www.nowhere.org", // no trailing slash - "https://foo:bar@www.nowhere.org/dir/index.html", // username:password - "https://www.nowhere.org/dir/index.html?id=965362", // query - "https://www.nowhere.org/dir/index.html#toc", // reference - }; - - std::string expected[] = { - "https://www.nowhere.org/WallyWorld", - "https://www.nowhere.org/WallyWorld", - "https://www.nowhere.org:8443/WallyWorld", - "https://www.nowhere.org/WallyWorld", - "https://www.nowhere.org/WallyWorld", - "https://www.nowhere.org/WallyWorld", - "https://www.nowhere.org/WallyWorld" - }; - - for (size_t i = 0; i < arraysize(url); i++) { - std::string key = net::AuthCache::HttpKey(GURL(url[i]), *auth_info); - EXPECT_EQ(expected[i], key); - } -} - |