summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-02 14:56:23 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-02 14:56:23 +0000
commite06306f07273ecff7bfed040ce355a7c943851f9 (patch)
tree232119d96f85a3a3f9e446f21b9ce00551d77924 /net
parent5f24f215c60528bd329930bf98373a52dfe08555 (diff)
downloadchromium_src-e06306f07273ecff7bfed040ce355a7c943851f9.zip
chromium_src-e06306f07273ecff7bfed040ce355a7c943851f9.tar.gz
chromium_src-e06306f07273ecff7bfed040ce355a7c943851f9.tar.bz2
HttpAuthHandlerDigest unit test cleanup.
DCHECK replaced by EXPECT for HttpAuthHandlerDigest unittests. Also, changed RespondToChallenge to return a success boolean and LOG the failure reasons, rather than returning an error string. BUG=None TEST=net_unittests --gtest_filter="*HttpAuthHandlerDigest*" Review URL: http://codereview.chromium.org/5205005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_auth_handler_digest_unittest.cc157
1 files changed, 79 insertions, 78 deletions
diff --git a/net/http/http_auth_handler_digest_unittest.cc b/net/http/http_auth_handler_digest_unittest.cc
index 9338bca..9b57c16e 100644
--- a/net/http/http_auth_handler_digest_unittest.cc
+++ b/net/http/http_auth_handler_digest_unittest.cc
@@ -15,6 +15,73 @@
namespace net {
+namespace {
+
+const char* const kSimpleChallenge =
+ "Digest realm=\"Oblivion\", nonce=\"nonce-value\"";
+
+// RespondToChallenge creates an HttpAuthHandlerDigest for the specified
+// |challenge|, and generates a response to the challenge which is returned in
+// |token|.
+//
+// The return value indicates whether the |token| was successfully created.
+//
+// If |target| is HttpAuth::AUTH_PROXY, then |proxy_name| specifies the source
+// of the |challenge|. Otherwise, the scheme and host and port of |request_url|
+// indicates the origin of the challenge.
+bool RespondToChallenge(HttpAuth::Target target,
+ const std::string& proxy_name,
+ const std::string& request_url,
+ const std::string& challenge,
+ std::string* token) {
+ // Input validation.
+ if (token == NULL) {
+ ADD_FAILURE() << "|token| must be non-NULL";
+ return false;
+ }
+ EXPECT_TRUE(target != HttpAuth::AUTH_PROXY || !proxy_name.empty());
+ EXPECT_FALSE(request_url.empty());
+ EXPECT_FALSE(challenge.empty());
+
+ token->clear();
+ scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
+ new HttpAuthHandlerDigest::Factory());
+ HttpAuthHandlerDigest::NonceGenerator* nonce_generator =
+ new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce");
+ factory->set_nonce_generator(nonce_generator);
+ scoped_ptr<HttpAuthHandler> handler;
+
+ // Create a handler for a particular challenge.
+ GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name);
+ int rv_create = factory->CreateAuthHandlerFromString(
+ challenge, target, url_origin.GetOrigin(), BoundNetLog(), &handler);
+ if (rv_create != OK || handler.get() == NULL) {
+ ADD_FAILURE() << "Unable to create auth handler.";
+ return false;
+ }
+
+ // Create a token in response to the challenge.
+ // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always
+ // completes synchronously. That's why this test can get away with a
+ // TestCompletionCallback without an IO thread.
+ TestCompletionCallback callback;
+ scoped_ptr<HttpRequestInfo> request(new HttpRequestInfo());
+ request->url = GURL(request_url);
+ const string16 kFoo = ASCIIToUTF16("foo");
+ const string16 kBar = ASCIIToUTF16("bar");
+ int rv_generate = handler->GenerateAuthToken(
+ &kFoo, &kBar, request.get(), &callback, token);
+ if (rv_generate != OK) {
+ ADD_FAILURE() << "Problems generating auth token";
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace
+
+
TEST(HttpAuthHandlerDigestTest, ParseChallenge) {
static const struct {
// The challenge string.
@@ -488,75 +555,14 @@ TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) {
handler->HandleAnotherChallenge(&tok_stale_false));
}
-namespace {
-
-const char* const kSimpleChallenge =
- "Digest realm=\"Oblivion\", nonce=\"nonce-value\"";
-
-// RespondToChallenge creates an HttpAuthHandlerDigest for the specified
-// |challenge|, and generates a response to the challenge which is returned in
-// |token|.
-//
-// The return value is an error string - an empty string indicates no errors.
-//
-// If |target| is HttpAuth::AUTH_PROXY, then |proxy_name| specifies the source
-// of the |challenge|. Otherwise, the scheme and host and port of |request_url|
-// indicates the origin of the challenge.
-std::string RespondToChallenge(HttpAuth::Target target,
- const std::string& proxy_name,
- const std::string& request_url,
- const std::string& challenge,
- std::string* token) {
- // Input validation.
- DCHECK(token);
- DCHECK(target != HttpAuth::AUTH_PROXY || !proxy_name.empty());
- DCHECK(!request_url.empty());
- DCHECK(!challenge.empty());
-
- token->clear();
- scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
- new HttpAuthHandlerDigest::Factory());
- HttpAuthHandlerDigest::NonceGenerator* nonce_generator =
- new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce");
- factory->set_nonce_generator(nonce_generator);
- scoped_ptr<HttpAuthHandler> handler;
-
- // Create a handler for a particular challenge.
- GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name);
- int rv_create = factory->CreateAuthHandlerFromString(
- challenge, target, url_origin.GetOrigin(), BoundNetLog(), &handler);
- if (rv_create != OK || handler.get() == NULL)
- return "Unable to create auth handler.";
-
- // Create a token in response to the challenge.
- // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always
- // completes synchronously. That's why this test can get away with a
- // TestCompletionCallback without an IO thread.
- TestCompletionCallback callback;
- scoped_ptr<HttpRequestInfo> request(new HttpRequestInfo());
- request->url = GURL(request_url);
- const string16 kFoo = ASCIIToUTF16("foo");
- const string16 kBar = ASCIIToUTF16("bar");
- int rv_generate = handler->GenerateAuthToken(
- &kFoo, &kBar, request.get(), &callback, token);
- if (rv_generate != OK)
- return "Problems generating auth token";
-
- // The token was correctly generated and is returned in |token|.
- return std::string();
-}
-
-} // namespace
-
TEST(HttpAuthHandlerDigest, RespondToServerChallenge) {
std::string auth_token;
- std::string error_text = RespondToChallenge(
+ EXPECT_TRUE(RespondToChallenge(
HttpAuth::AUTH_SERVER,
std::string(),
"http://www.example.com/path/to/resource",
kSimpleChallenge,
- &auth_token);
- EXPECT_EQ("", error_text);
+ &auth_token));
EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", "
"nonce=\"nonce-value\", uri=\"/path/to/resource\", "
"response=\"6779f90bd0d658f937c1af967614fe84\"",
@@ -565,13 +571,12 @@ TEST(HttpAuthHandlerDigest, RespondToServerChallenge) {
TEST(HttpAuthHandlerDigest, RespondToHttpsServerChallenge) {
std::string auth_token;
- std::string error_text = RespondToChallenge(
+ EXPECT_TRUE(RespondToChallenge(
HttpAuth::AUTH_SERVER,
std::string(),
"https://www.example.com/path/to/resource",
kSimpleChallenge,
- &auth_token);
- EXPECT_EQ("", error_text);
+ &auth_token));
EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", "
"nonce=\"nonce-value\", uri=\"/path/to/resource\", "
"response=\"6779f90bd0d658f937c1af967614fe84\"",
@@ -580,13 +585,12 @@ TEST(HttpAuthHandlerDigest, RespondToHttpsServerChallenge) {
TEST(HttpAuthHandlerDigest, RespondToProxyChallenge) {
std::string auth_token;
- std::string error_text = RespondToChallenge(
+ EXPECT_TRUE(RespondToChallenge(
HttpAuth::AUTH_PROXY,
"http://proxy.intranet.corp.com:3128",
"http://www.example.com/path/to/resource",
kSimpleChallenge,
- &auth_token);
- EXPECT_EQ("", error_text);
+ &auth_token));
EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", "
"nonce=\"nonce-value\", uri=\"/path/to/resource\", "
"response=\"6779f90bd0d658f937c1af967614fe84\"",
@@ -595,13 +599,12 @@ TEST(HttpAuthHandlerDigest, RespondToProxyChallenge) {
TEST(HttpAuthHandlerDigest, RespondToProxyChallengeHttps) {
std::string auth_token;
- std::string error_text = RespondToChallenge(
+ EXPECT_TRUE(RespondToChallenge(
HttpAuth::AUTH_PROXY,
"http://proxy.intranet.corp.com:3128",
"https://www.example.com/path/to/resource",
kSimpleChallenge,
- &auth_token);
- EXPECT_EQ("", error_text);
+ &auth_token));
EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", "
"nonce=\"nonce-value\", uri=\"www.example.com:443\", "
"response=\"3270da8467afbe9ddf2334a48d46e9b9\"",
@@ -610,13 +613,12 @@ TEST(HttpAuthHandlerDigest, RespondToProxyChallengeHttps) {
TEST(HttpAuthHandlerDigest, RespondToChallengeAuthQop) {
std::string auth_token;
- std::string error_text = RespondToChallenge(
+ EXPECT_TRUE(RespondToChallenge(
HttpAuth::AUTH_SERVER,
std::string(),
"http://www.example.com/path/to/resource",
"Digest realm=\"Oblivion\", nonce=\"nonce-value\", qop=\"auth\"",
- &auth_token);
- EXPECT_EQ("", error_text);
+ &auth_token));
EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", "
"nonce=\"nonce-value\", uri=\"/path/to/resource\", "
"response=\"5b1459beda5cee30d6ff9e970a69c0ea\", "
@@ -626,14 +628,13 @@ TEST(HttpAuthHandlerDigest, RespondToChallengeAuthQop) {
TEST(HttpAuthHandlerDigest, RespondToChallengeOpaque) {
std::string auth_token;
- std::string error_text = RespondToChallenge(
+ EXPECT_TRUE(RespondToChallenge(
HttpAuth::AUTH_SERVER,
std::string(),
"http://www.example.com/path/to/resource",
"Digest realm=\"Oblivion\", nonce=\"nonce-value\", "
"qop=\"auth\", opaque=\"opaque text\"",
- &auth_token);
- EXPECT_EQ("", error_text);
+ &auth_token));
EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", "
"nonce=\"nonce-value\", uri=\"/path/to/resource\", "
"response=\"5b1459beda5cee30d6ff9e970a69c0ea\", "