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

Unified Diff: net/http/http_auth_controller_unittest.cc

Issue 1381493004: [net/http auth] Generalize HttpAuthHandlerMock. Base URL: https://chromium.googlesource.com/chromium/src.git@http-auth-scheme-properties
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 | « no previous file | net/http/http_auth_handler_mock.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_auth_controller_unittest.cc
diff --git a/net/http/http_auth_controller_unittest.cc b/net/http/http_auth_controller_unittest.cc
index 126f76d454dcb2ac43d22af19cfdf5cfddffedb1..32a92bc1ed2f2ee45f5b287a3a35e85a5cd9a7ab 100644
--- a/net/http/http_auth_controller_unittest.cc
+++ b/net/http/http_auth_controller_unittest.cc
@@ -62,11 +62,12 @@ void RunSingleRoundAuthTest(HandlerRunMode run_mode,
"\r\n"));
HttpAuthHandlerMock::Factory auth_handler_factory;
- HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock();
+ scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock());
auth_handler->SetGenerateExpectation((run_mode == RUN_HANDLER_ASYNC),
handler_rv);
- auth_handler_factory.AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
- auth_handler_factory.set_do_init_from_challenge(true);
+ auth_handler_factory.AddMockHandler(auth_handler.Pass(),
+ HttpAuthHandlerFactory::CREATE_CHALLENGE,
+ HttpAuth::AUTH_PROXY);
scoped_refptr<HttpAuthController> controller(
new HttpAuthController(HttpAuth::AUTH_PROXY,
@@ -75,7 +76,8 @@ void RunSingleRoundAuthTest(HandlerRunMode run_mode,
ASSERT_EQ(OK,
controller->HandleAuthChallenge(headers, false, false, dummy_log));
ASSERT_TRUE(controller->HaveAuthHandler());
- controller->ResetAuth(AuthCredentials());
+ controller->ResetAuth(
+ AuthCredentials(base::ASCIIToUTF16("a"), base::ASCIIToUTF16("b")));
EXPECT_TRUE(controller->HaveAuth());
TestCompletionCallback callback;
@@ -119,48 +121,6 @@ TEST(HttpAuthControllerTest, PermanentErrors) {
// If an HttpAuthHandler indicates that it doesn't allow explicit
// credentials, don't prompt for credentials.
TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) {
- // Modified mock HttpAuthHandler for this test.
- class MockHandler : public HttpAuthHandlerMock {
- public:
- MockHandler(int expected_rv, const std::string& scheme)
- : expected_scheme_(scheme) {
- SetGenerateExpectation(false, expected_rv);
- }
-
- protected:
- bool Init(HttpAuthChallengeTokenizer* challenge) override {
- HttpAuthHandlerMock::Init(challenge);
- set_allows_default_credentials(true);
- set_allows_explicit_credentials(false);
- // Pretend to be Bert so we can test failover logic.
- if (challenge->SchemeIs("bert")) {
- auth_scheme_ = "bert";
- set_allows_explicit_credentials(true);
- } else {
- auth_scheme_ = "ernie";
- }
- EXPECT_EQ(expected_scheme_, auth_scheme_);
- return true;
- }
-
- int GenerateAuthTokenImpl(const AuthCredentials* credentials,
- const HttpRequestInfo* request,
- const CompletionCallback& callback,
- std::string* auth_token) override {
- int result =
- HttpAuthHandlerMock::GenerateAuthTokenImpl(credentials,
- request, callback,
- auth_token);
- EXPECT_TRUE(result != OK ||
- !AllowsExplicitCredentials() ||
- !credentials->Empty());
- return result;
- }
-
- private:
- std::string expected_scheme_;
- };
-
BoundNetLog dummy_log;
HttpAuthCache dummy_auth_cache;
HttpRequestInfo request;
@@ -175,11 +135,15 @@ TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) {
"\r\n"));
HttpAuthHandlerMock::Factory auth_handler_factory;
- auth_handler_factory.set_do_init_from_challenge(true);
// Handler for the first attempt at authentication. "Ernie" handler accepts
- // the default identity and successfully constructs a token.
- auth_handler_factory.AddMockHandler(new MockHandler(OK, "ernie"),
+ // the default identity and successfully constructs a token. Handler for the
+ scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock());
+ auth_handler->set_allows_default_credentials(true);
+ auth_handler->set_allows_explicit_credentials(false);
+ auth_handler->set_expected_auth_scheme("ernie");
+ auth_handler_factory.AddMockHandler(auth_handler.Pass(),
+ HttpAuthHandlerFactory::CREATE_CHALLENGE,
HttpAuth::AUTH_SERVER);
scoped_refptr<HttpAuthController> controller(
@@ -201,13 +165,23 @@ TEST(HttpAuthControllerTest, NoExplicitCredentialsAllowed) {
// Handlers for the second attempt. Neither should be used to generate a
// token. Instead the controller should realize that there are no viable
// identities to use with the "Ernie" handler and fail.
- auth_handler_factory.AddMockHandler(new MockHandler(ERR_UNEXPECTED, "ernie"),
+ auth_handler.reset(new HttpAuthHandlerMock());
+ auth_handler->set_allows_default_credentials(true);
+ auth_handler->set_allows_explicit_credentials(false);
+ auth_handler->set_expected_auth_scheme("ernie");
+ auth_handler_factory.AddMockHandler(auth_handler.Pass(),
+ HttpAuthHandlerFactory::CREATE_CHALLENGE,
HttpAuth::AUTH_SERVER);
// Fallback handlers for the second attempt. The "Ernie" handler should be
// discarded due to the disabled scheme, and the "Bert" handler should
// successfully be used to generate a token.
- auth_handler_factory.AddMockHandler(new MockHandler(OK, "bert"),
+ auth_handler.reset(new HttpAuthHandlerMock());
+ auth_handler->set_allows_default_credentials(false);
+ auth_handler->set_allows_explicit_credentials(true);
+ auth_handler->set_expected_auth_scheme("bert");
+ auth_handler_factory.AddMockHandler(auth_handler.Pass(),
+ HttpAuthHandlerFactory::CREATE_CHALLENGE,
HttpAuth::AUTH_SERVER);
// Once a token is generated, simulate the receipt of a server response
« no previous file with comments | « no previous file | net/http/http_auth_handler_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698