| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_auth_controller.h" | 5 #include "net/http/http_auth_controller.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 auth_handler_factory.AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); | 67 auth_handler_factory.AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 68 auth_handler_factory.set_do_init_from_challenge(true); | 68 auth_handler_factory.set_do_init_from_challenge(true); |
| 69 | 69 |
| 70 scoped_refptr<HttpAuthController> controller( | 70 scoped_refptr<HttpAuthController> controller( |
| 71 new HttpAuthController(HttpAuth::AUTH_PROXY, | 71 new HttpAuthController(HttpAuth::AUTH_PROXY, |
| 72 GURL("http://example.com"), | 72 GURL("http://example.com"), |
| 73 &dummy_auth_cache, &auth_handler_factory)); | 73 &dummy_auth_cache, &auth_handler_factory)); |
| 74 ASSERT_EQ(OK, | 74 ASSERT_EQ(OK, |
| 75 controller->HandleAuthChallenge(headers, false, false, dummy_log)); | 75 controller->HandleAuthChallenge(headers, false, false, dummy_log)); |
| 76 ASSERT_TRUE(controller->HaveAuthHandler()); | 76 ASSERT_TRUE(controller->HaveAuthHandler()); |
| 77 controller->ResetAuth(string16(), string16()); | 77 controller->ResetAuth(AuthCredentials()); |
| 78 EXPECT_TRUE(controller->HaveAuth()); | 78 EXPECT_TRUE(controller->HaveAuth()); |
| 79 | 79 |
| 80 TestOldCompletionCallback callback; | 80 TestOldCompletionCallback callback; |
| 81 EXPECT_EQ((run_mode == RUN_HANDLER_ASYNC)? ERR_IO_PENDING: | 81 EXPECT_EQ((run_mode == RUN_HANDLER_ASYNC)? ERR_IO_PENDING: |
| 82 expected_controller_rv, | 82 expected_controller_rv, |
| 83 controller->MaybeGenerateAuthToken(&request, &callback, | 83 controller->MaybeGenerateAuthToken(&request, &callback, |
| 84 dummy_log)); | 84 dummy_log)); |
| 85 if (run_mode == RUN_HANDLER_ASYNC) | 85 if (run_mode == RUN_HANDLER_ASYNC) |
| 86 EXPECT_EQ(expected_controller_rv, callback.WaitForResult()); | 86 EXPECT_EQ(expected_controller_rv, callback.WaitForResult()); |
| 87 EXPECT_EQ((scheme_state == SCHEME_IS_DISABLED), | 87 EXPECT_EQ((scheme_state == SCHEME_IS_DISABLED), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // Pretend to be SCHEME_BASIC so we can test failover logic. | 135 // Pretend to be SCHEME_BASIC so we can test failover logic. |
| 136 if (challenge->scheme() == "Basic") { | 136 if (challenge->scheme() == "Basic") { |
| 137 auth_scheme_ = HttpAuth::AUTH_SCHEME_BASIC; | 137 auth_scheme_ = HttpAuth::AUTH_SCHEME_BASIC; |
| 138 --score_; // Reduce score, so we rank below Mock. | 138 --score_; // Reduce score, so we rank below Mock. |
| 139 set_allows_explicit_credentials(true); | 139 set_allows_explicit_credentials(true); |
| 140 } | 140 } |
| 141 EXPECT_EQ(expected_scheme_, auth_scheme_); | 141 EXPECT_EQ(expected_scheme_, auth_scheme_); |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 | 144 |
| 145 virtual int GenerateAuthTokenImpl(const string16* username, | 145 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 146 const string16* password, | |
| 147 const HttpRequestInfo* request, | 146 const HttpRequestInfo* request, |
| 148 OldCompletionCallback* callback, | 147 OldCompletionCallback* callback, |
| 149 std::string* auth_token) OVERRIDE { | 148 std::string* auth_token) OVERRIDE { |
| 150 int result = | 149 int result = |
| 151 HttpAuthHandlerMock::GenerateAuthTokenImpl(username, password, | 150 HttpAuthHandlerMock::GenerateAuthTokenImpl(credentials, |
| 152 request, callback, | 151 request, callback, |
| 153 auth_token); | 152 auth_token); |
| 154 EXPECT_TRUE(result != OK || | 153 EXPECT_TRUE(result != OK || |
| 155 !AllowsExplicitCredentials() || !username->empty()); | 154 !AllowsExplicitCredentials() || |
| 155 !credentials->Empty()); |
| 156 return result; | 156 return result; |
| 157 } | 157 } |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 HttpAuth::Scheme expected_scheme_; | 160 HttpAuth::Scheme expected_scheme_; |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 BoundNetLog dummy_log; | 163 BoundNetLog dummy_log; |
| 164 HttpAuthCache dummy_auth_cache; | 164 HttpAuthCache dummy_auth_cache; |
| 165 HttpRequestInfo request; | 165 HttpRequestInfo request; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 HttpAuth::AUTH_SERVER); | 204 HttpAuth::AUTH_SERVER); |
| 205 auth_handler_factory.set_do_init_from_challenge(true); | 205 auth_handler_factory.set_do_init_from_challenge(true); |
| 206 | 206 |
| 207 scoped_refptr<HttpAuthController> controller( | 207 scoped_refptr<HttpAuthController> controller( |
| 208 new HttpAuthController(HttpAuth::AUTH_SERVER, | 208 new HttpAuthController(HttpAuth::AUTH_SERVER, |
| 209 GURL("http://example.com"), | 209 GURL("http://example.com"), |
| 210 &dummy_auth_cache, &auth_handler_factory)); | 210 &dummy_auth_cache, &auth_handler_factory)); |
| 211 ASSERT_EQ(OK, | 211 ASSERT_EQ(OK, |
| 212 controller->HandleAuthChallenge(headers, false, false, dummy_log)); | 212 controller->HandleAuthChallenge(headers, false, false, dummy_log)); |
| 213 ASSERT_TRUE(controller->HaveAuthHandler()); | 213 ASSERT_TRUE(controller->HaveAuthHandler()); |
| 214 controller->ResetAuth(string16(), string16()); | 214 controller->ResetAuth(AuthCredentials()); |
| 215 EXPECT_TRUE(controller->HaveAuth()); | 215 EXPECT_TRUE(controller->HaveAuth()); |
| 216 | 216 |
| 217 // Should only succeed if we are using the AUTH_SCHEME_MOCK MockHandler. | 217 // Should only succeed if we are using the AUTH_SCHEME_MOCK MockHandler. |
| 218 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log)); | 218 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log)); |
| 219 controller->AddAuthorizationHeader(&request_headers); | 219 controller->AddAuthorizationHeader(&request_headers); |
| 220 | 220 |
| 221 // Once a token is generated, simulate the receipt of a server response | 221 // Once a token is generated, simulate the receipt of a server response |
| 222 // indicating that the authentication attempt was rejected. | 222 // indicating that the authentication attempt was rejected. |
| 223 ASSERT_EQ(OK, | 223 ASSERT_EQ(OK, |
| 224 controller->HandleAuthChallenge(headers, false, false, dummy_log)); | 224 controller->HandleAuthChallenge(headers, false, false, dummy_log)); |
| 225 ASSERT_TRUE(controller->HaveAuthHandler()); | 225 ASSERT_TRUE(controller->HaveAuthHandler()); |
| 226 controller->ResetAuth(ASCIIToUTF16("Hello"), string16()); | 226 controller->ResetAuth(AuthCredentials(ASCIIToUTF16("Hello"), string16())); |
| 227 EXPECT_TRUE(controller->HaveAuth()); | 227 EXPECT_TRUE(controller->HaveAuth()); |
| 228 EXPECT_TRUE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK)); | 228 EXPECT_TRUE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK)); |
| 229 EXPECT_FALSE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_BASIC)); | 229 EXPECT_FALSE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_BASIC)); |
| 230 | 230 |
| 231 // Should only succeed if we are using the AUTH_SCHEME_BASIC MockHandler. | 231 // Should only succeed if we are using the AUTH_SCHEME_BASIC MockHandler. |
| 232 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log)); | 232 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log)); |
| 233 } | 233 } |
| 234 | 234 |
| 235 } // namespace net | 235 } // namespace net |
| OLD | NEW |