Index: net/http/http_auth_unittest.cc |
diff --git a/net/http/http_auth_unittest.cc b/net/http/http_auth_unittest.cc |
index cf68fa8039d5136a03421397ed206e80f6266564..04d157056a4241e23ca07123e5d0b439b446d713 100644 |
--- a/net/http/http_auth_unittest.cc |
+++ b/net/http/http_auth_unittest.cc |
@@ -30,12 +30,10 @@ HttpAuthHandlerMock* CreateMockHandler(bool connection_based) { |
auth_handler->set_connection_based(connection_based); |
std::string challenge_text = "Basic"; |
HttpAuthChallengeTokenizer challenge(challenge_text.begin(), |
- challenge_text.end()); |
+ challenge_text.end()); |
GURL origin("www.example.com"); |
- EXPECT_TRUE(auth_handler->InitFromChallenge(&challenge, |
- HttpAuth::AUTH_SERVER, |
- origin, |
- BoundNetLog())); |
+ EXPECT_TRUE(auth_handler->InitFromChallenge( |
+ &challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog())); |
return auth_handler; |
} |
@@ -53,12 +51,11 @@ HttpAuth::AuthorizationResult HandleChallengeResponse( |
std::set<HttpAuth::Scheme> disabled_schemes; |
scoped_refptr<HttpResponseHeaders> headers( |
HeadersFromResponseText(headers_text)); |
- return HttpAuth::HandleChallengeResponse( |
- mock_handler.get(), |
- headers.get(), |
- HttpAuth::AUTH_SERVER, |
- disabled_schemes, |
- challenge_used); |
+ return HttpAuth::HandleChallengeResponse(mock_handler.get(), |
+ headers.get(), |
+ HttpAuth::AUTH_SERVER, |
+ disabled_schemes, |
+ challenge_used); |
} |
} // namespace |
@@ -68,66 +65,53 @@ TEST(HttpAuthTest, ChooseBestChallenge) { |
const char* headers; |
HttpAuth::Scheme challenge_scheme; |
const char* challenge_realm; |
- } tests[] = { |
- { |
- // Basic is the only challenge type, pick it. |
- "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n" |
- "www-authenticate: Basic realm=\"BasicRealm\"\n", |
- |
- HttpAuth::AUTH_SCHEME_BASIC, |
- "BasicRealm", |
- }, |
- { |
- // Fake is the only challenge type, but it is unsupported. |
- "Y: Digest realm=\"FooBar\", nonce=\"aaaaaaaaaa\"\n" |
- "www-authenticate: Fake realm=\"FooBar\"\n", |
- |
- HttpAuth::AUTH_SCHEME_MAX, |
- "", |
- }, |
- { |
- // Pick Digest over Basic. |
- "www-authenticate: Basic realm=\"FooBar\"\n" |
- "www-authenticate: Fake realm=\"FooBar\"\n" |
- "www-authenticate: nonce=\"aaaaaaaaaa\"\n" |
- "www-authenticate: Digest realm=\"DigestRealm\", nonce=\"aaaaaaaaaa\"\n", |
- |
- HttpAuth::AUTH_SCHEME_DIGEST, |
- "DigestRealm", |
- }, |
- { |
- // Handle an empty header correctly. |
- "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n" |
- "www-authenticate:\n", |
- |
- HttpAuth::AUTH_SCHEME_MAX, |
- "", |
- }, |
- { |
- "WWW-Authenticate: Negotiate\n" |
- "WWW-Authenticate: NTLM\n", |
+ } tests[] = {{// Basic is the only challenge type, pick it. |
+ "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n" |
+ "www-authenticate: Basic realm=\"BasicRealm\"\n", |
+ HttpAuth::AUTH_SCHEME_BASIC, "BasicRealm", |
+ }, |
+ {// Fake is the only challenge type, but it is unsupported. |
+ "Y: Digest realm=\"FooBar\", nonce=\"aaaaaaaaaa\"\n" |
+ "www-authenticate: Fake realm=\"FooBar\"\n", |
+ HttpAuth::AUTH_SCHEME_MAX, "", |
+ }, |
+ {// Pick Digest over Basic. |
+ "www-authenticate: Basic realm=\"FooBar\"\n" |
+ "www-authenticate: Fake realm=\"FooBar\"\n" |
+ "www-authenticate: nonce=\"aaaaaaaaaa\"\n" |
+ "www-authenticate: Digest realm=\"DigestRealm\", " |
+ "nonce=\"aaaaaaaaaa\"\n", |
+ HttpAuth::AUTH_SCHEME_DIGEST, "DigestRealm", |
+ }, |
+ {// Handle an empty header correctly. |
+ "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n" |
+ "www-authenticate:\n", |
+ HttpAuth::AUTH_SCHEME_MAX, "", |
+ }, |
+ { |
+ "WWW-Authenticate: Negotiate\n" |
+ "WWW-Authenticate: NTLM\n", |
#if defined(USE_KERBEROS) |
- // Choose Negotiate over NTLM on all platforms. |
- // TODO(ahendrickson): This may be flaky on Linux and OSX as it |
- // relies on being able to load one of the known .so files |
- // for gssapi. |
- HttpAuth::AUTH_SCHEME_NEGOTIATE, |
+ // Choose Negotiate over NTLM on all platforms. |
+ // TODO(ahendrickson): This may be flaky on Linux and OSX as it |
+ // relies on being able to load one of the known .so files |
+ // for gssapi. |
+ HttpAuth::AUTH_SCHEME_NEGOTIATE, |
#else |
- // On systems that don't use Kerberos fall back to NTLM. |
- HttpAuth::AUTH_SCHEME_NTLM, |
+ // On systems that don't use Kerberos fall back to NTLM. |
+ HttpAuth::AUTH_SCHEME_NTLM, |
#endif // defined(USE_KERBEROS) |
- "", |
- } |
- }; |
+ "", |
+ }}; |
GURL origin("http://www.example.com"); |
std::set<HttpAuth::Scheme> disabled_schemes; |
MockAllowURLSecurityManager url_security_manager; |
scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); |
scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( |
HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); |
- http_auth_handler_factory->SetURLSecurityManager( |
- "negotiate", &url_security_manager); |
+ http_auth_handler_factory->SetURLSecurityManager("negotiate", |
+ &url_security_manager); |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
// Make a HttpResponseHeaders object. |
@@ -163,8 +147,7 @@ TEST(HttpAuthTest, HandleChallengeResponse) { |
const char* const kBasicChallenge = |
"HTTP/1.1 401 Unauthorized\n" |
"WWW-Authenticate: Basic realm=\"happy\"\n"; |
- const char* const kMissingChallenge = |
- "HTTP/1.1 401 Unauthorized\n"; |
+ const char* const kMissingChallenge = "HTTP/1.1 401 Unauthorized\n"; |
const char* const kEmptyChallenge = |
"HTTP/1.1 401 Unauthorized\n" |
"WWW-Authenticate: \n"; |
@@ -181,24 +164,20 @@ TEST(HttpAuthTest, HandleChallengeResponse) { |
// previous authentication attempt. (There is a slight exception for digest |
// authentication and the stale parameter, but that is covered in the |
// http_auth_handler_digest_unittests). |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_REJECT, |
- HandleChallengeResponse(false, kMockChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
+ HandleChallengeResponse(false, kMockChallenge, &challenge_used)); |
EXPECT_EQ("Mock token_here", challenge_used); |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_REJECT, |
- HandleChallengeResponse(false, kBasicChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
+ HandleChallengeResponse(false, kBasicChallenge, &challenge_used)); |
EXPECT_EQ("", challenge_used); |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_REJECT, |
- HandleChallengeResponse(false, kMissingChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
+ HandleChallengeResponse(false, kMissingChallenge, &challenge_used)); |
EXPECT_EQ("", challenge_used); |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_REJECT, |
- HandleChallengeResponse(false, kEmptyChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
+ HandleChallengeResponse(false, kEmptyChallenge, &challenge_used)); |
EXPECT_EQ("", challenge_used); |
EXPECT_EQ( |
@@ -215,24 +194,20 @@ TEST(HttpAuthTest, HandleChallengeResponse) { |
// as acceptance (and continuance) of the current approach. If there are |
// no auth challenges for the same scheme, the response will be treated as |
// a rejection. |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
- HandleChallengeResponse(true, kMockChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
+ HandleChallengeResponse(true, kMockChallenge, &challenge_used)); |
EXPECT_EQ("Mock token_here", challenge_used); |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_REJECT, |
- HandleChallengeResponse(true, kBasicChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
+ HandleChallengeResponse(true, kBasicChallenge, &challenge_used)); |
EXPECT_EQ("", challenge_used); |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_REJECT, |
- HandleChallengeResponse(true, kMissingChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
+ HandleChallengeResponse(true, kMissingChallenge, &challenge_used)); |
EXPECT_EQ("", challenge_used); |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_REJECT, |
- HandleChallengeResponse(true, kEmptyChallenge, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
+ HandleChallengeResponse(true, kEmptyChallenge, &challenge_used)); |
EXPECT_EQ("", challenge_used); |
EXPECT_EQ( |
@@ -240,9 +215,8 @@ TEST(HttpAuthTest, HandleChallengeResponse) { |
HandleChallengeResponse(true, kBasicAndMockChallenges, &challenge_used)); |
EXPECT_EQ("Mock token_here", challenge_used); |
- EXPECT_EQ( |
- HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
- HandleChallengeResponse(true, kTwoMockChallenges, &challenge_used)); |
+ EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT, |
+ HandleChallengeResponse(true, kTwoMockChallenges, &challenge_used)); |
EXPECT_EQ("Mock token_a", challenge_used); |
} |