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

Unified Diff: net/http/http_auth_handler_digest_unittest.cc

Issue 1391053002: [net/http auth] Make HttpAuthHandler challenge handling asynchronous. Base URL: https://chromium.googlesource.com/chromium/src.git@auth-handler-init-split
Patch Set: Created 5 years, 2 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_handler_digest.cc ('k') | net/http/http_auth_handler_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_auth_handler_digest_unittest.cc
diff --git a/net/http/http_auth_handler_digest_unittest.cc b/net/http/http_auth_handler_digest_unittest.cc
index 2cac21c99b7f4aaae946c8535576e63db5261c69..b7eaced5aef05408378b4874f36647ad35d0c274 100644
--- a/net/http/http_auth_handler_digest_unittest.cc
+++ b/net/http/http_auth_handler_digest_unittest.cc
@@ -12,6 +12,7 @@
#include "net/http/http_auth_challenge_tokenizer.h"
#include "net/http/http_auth_handler_digest.h"
#include "net/http/http_request_info.h"
+#include "net/http/http_response_info.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
@@ -56,8 +57,12 @@ bool RespondToChallenge(HttpAuth::Target target,
HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end());
scoped_ptr<HttpAuthHandler> handler =
factory->CreateAuthHandlerForScheme(tokenizer.NormalizedScheme());
- int rv = handler->HandleInitialChallenge(
- tokenizer, target, url_origin.GetOrigin(), BoundNetLog());
+ HttpResponseInfo response_info;
+ TestCompletionCallback callback;
+ int rv = handler->HandleInitialChallenge(tokenizer, response_info, target,
+ url_origin.GetOrigin(),
+ BoundNetLog(), callback.callback());
+ rv = callback.GetResult(rv);
if (rv != OK || handler.get() == NULL) {
ADD_FAILURE() << "Unable to create auth handler.";
return false;
@@ -67,7 +72,6 @@ bool RespondToChallenge(HttpAuth::Target target,
// 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);
AuthCredentials credentials(base::ASCIIToUTF16("foo"),
@@ -95,26 +99,24 @@ TEST(HttpAuthHandlerDigestTest, CreateAndInitPreemptiveAuthHandler_Valid) {
HttpAuthHandlerDigest::Factory digest_factory;
HttpAuthCache auth_cache;
std::string challenge(kSimpleChallenge);
- HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end());
HttpAuthCache::Entry* entry =
auth_cache.Add(GURL("http://example.com/foo").GetOrigin(), "foo",
"digest", challenge, AuthCredentials(), "/foo");
EXPECT_TRUE(digest_factory.CreateAndInitPreemptiveAuthHandler(
- entry, tokenizer, HttpAuth::AUTH_SERVER, BoundNetLog()));
+ entry, HttpAuth::AUTH_SERVER, BoundNetLog()));
}
TEST(HttpAuthHandlerDigestTest, CreateAndInitPreemptiveAuthHandler_Invalid) {
HttpAuthHandlerDigest::Factory digest_factory;
HttpAuthCache auth_cache;
std::string challenge("Basic realm=\"bar\"");
- HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end());
HttpAuthCache::Entry* entry =
auth_cache.Add(GURL("http://example.com").GetOrigin(), "bar", "basic",
challenge, AuthCredentials(), "/bar");
EXPECT_FALSE(digest_factory.CreateAndInitPreemptiveAuthHandler(
- entry, tokenizer, HttpAuth::AUTH_SERVER, BoundNetLog()));
+ entry, HttpAuth::AUTH_SERVER, BoundNetLog()));
}
TEST(HttpAuthHandlerDigestTest, ParseChallenge) {
@@ -379,8 +381,12 @@ TEST(HttpAuthHandlerDigestTest, ParseChallenge) {
scoped_ptr<HttpAuthHandler> handler =
factory->CreateAuthHandlerForScheme(tokenizer.NormalizedScheme());
ASSERT_TRUE(handler);
- int rv = handler->HandleInitialChallenge(tokenizer, HttpAuth::AUTH_SERVER,
- origin, BoundNetLog());
+ HttpResponseInfo response_info;
+ TestCompletionCallback callback;
+ int rv = handler->HandleInitialChallenge(
+ tokenizer, response_info, HttpAuth::AUTH_SERVER, origin, BoundNetLog(),
+ callback.callback());
+ rv = callback.GetResult(rv);
if (tests[i].parsed_success) {
EXPECT_EQ(OK, rv);
} else {
@@ -540,9 +546,12 @@ TEST(HttpAuthHandlerDigestTest, AssembleCredentials) {
factory->CreateAuthHandlerForScheme("digest");
std::string challenge = tests[i].challenge;
HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end());
- int rv = handler->HandleInitialChallenge(tokenizer, HttpAuth::AUTH_SERVER,
- origin, BoundNetLog());
- EXPECT_EQ(OK, rv);
+ HttpResponseInfo response_info;
+ TestCompletionCallback callback;
+ int rv = handler->HandleInitialChallenge(
+ tokenizer, response_info, HttpAuth::AUTH_SERVER, origin, BoundNetLog(),
+ callback.callback());
+ EXPECT_EQ(OK, callback.GetResult(rv));
HttpAuthHandlerDigest* digest =
static_cast<HttpAuthHandlerDigest*>(handler.get());
@@ -569,8 +578,12 @@ TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) {
GURL origin("intranet.google.com");
scoped_ptr<HttpAuthHandler> handler =
factory->CreateAuthHandlerForScheme(tok_default.NormalizedScheme());
- EXPECT_EQ(OK, handler->HandleInitialChallenge(
- tok_default, HttpAuth::AUTH_SERVER, origin, BoundNetLog()));
+ HttpResponseInfo response_info;
+ TestCompletionCallback callback;
+ int rv = handler->HandleInitialChallenge(tok_default, response_info,
+ HttpAuth::AUTH_SERVER, origin,
+ BoundNetLog(), callback.callback());
+ EXPECT_EQ(OK, callback.GetResult(rv));
ASSERT_TRUE(handler.get() != NULL);
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
handler->HandleAnotherChallenge(tok_default));
« no previous file with comments | « net/http/http_auth_handler_digest.cc ('k') | net/http/http_auth_handler_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698