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_handler_mock.h" | 5 #include "net/http/http_auth_handler_mock.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/http/http_request_info.h" | 10 #include "net/http/http_request_info.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 HttpAuthHandlerMock::HttpAuthHandlerMock() | 15 HttpAuthHandlerMock::HttpAuthHandlerMock() |
16 : resolve_(RESOLVE_INIT), user_callback_(NULL), | 16 : resolve_(RESOLVE_INIT), user_callback_(NULL), |
17 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 17 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
18 generate_async_(false), generate_rv_(OK), | 18 generate_async_(false), generate_rv_(OK), |
19 auth_token_(NULL), | 19 auth_token_(NULL), |
20 first_round_(true), | 20 first_round_(true), |
21 connection_based_(false) { | 21 connection_based_(false), |
| 22 allows_default_credentials_(false), |
| 23 allows_explicit_credentials_(true) { |
22 } | 24 } |
23 | 25 |
24 HttpAuthHandlerMock::~HttpAuthHandlerMock() { | 26 HttpAuthHandlerMock::~HttpAuthHandlerMock() { |
25 } | 27 } |
26 | 28 |
27 void HttpAuthHandlerMock::SetResolveExpectation(Resolve resolve) { | 29 void HttpAuthHandlerMock::SetResolveExpectation(Resolve resolve) { |
28 EXPECT_EQ(RESOLVE_INIT, resolve_); | 30 EXPECT_EQ(RESOLVE_INIT, resolve_); |
29 resolve_ = resolve; | 31 resolve_ = resolve; |
30 } | 32 } |
31 | 33 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return rv; | 68 return rv; |
67 } | 69 } |
68 | 70 |
69 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) { | 71 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) { |
70 generate_async_ = async; | 72 generate_async_ = async; |
71 generate_rv_ = rv; | 73 generate_rv_ = rv; |
72 } | 74 } |
73 | 75 |
74 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge( | 76 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge( |
75 HttpAuth::ChallengeTokenizer* challenge) { | 77 HttpAuth::ChallengeTokenizer* challenge) { |
76 if (!is_connection_based()) | 78 // If we receive an empty challenge for a connection based scheme, or a second |
| 79 // challenge for a non connection based scheme, assume it's a rejection. |
| 80 if (!is_connection_based() || challenge->base64_param().empty()) |
77 return HttpAuth::AUTHORIZATION_RESULT_REJECT; | 81 return HttpAuth::AUTHORIZATION_RESULT_REJECT; |
78 if (!LowerCaseEqualsASCII(challenge->scheme(), "mock")) | 82 if (!LowerCaseEqualsASCII(challenge->scheme(), "mock")) |
79 return HttpAuth::AUTHORIZATION_RESULT_INVALID; | 83 return HttpAuth::AUTHORIZATION_RESULT_INVALID; |
80 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; | 84 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; |
81 } | 85 } |
82 | 86 |
83 bool HttpAuthHandlerMock::NeedsIdentity() { | 87 bool HttpAuthHandlerMock::NeedsIdentity() { |
84 return first_round_; | 88 return first_round_; |
85 } | 89 } |
86 | 90 |
| 91 bool HttpAuthHandlerMock::AllowsDefaultCredentials() { |
| 92 return allows_default_credentials_; |
| 93 } |
| 94 |
| 95 bool HttpAuthHandlerMock::AllowsExplicitCredentials() { |
| 96 return allows_explicit_credentials_; |
| 97 } |
| 98 |
87 bool HttpAuthHandlerMock::Init(HttpAuth::ChallengeTokenizer* challenge) { | 99 bool HttpAuthHandlerMock::Init(HttpAuth::ChallengeTokenizer* challenge) { |
88 auth_scheme_ = HttpAuth::AUTH_SCHEME_MOCK; | 100 auth_scheme_ = HttpAuth::AUTH_SCHEME_MOCK; |
89 score_ = 1; | 101 score_ = 1; |
90 properties_ = connection_based_ ? IS_CONNECTION_BASED : 0; | 102 properties_ = connection_based_ ? IS_CONNECTION_BASED : 0; |
91 return true; | 103 return true; |
92 } | 104 } |
93 | 105 |
94 int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, | 106 int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, |
95 const string16* password, | 107 const string16* password, |
96 const HttpRequestInfo* request, | 108 const HttpRequestInfo* request, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 std::vector<HttpAuthHandler*>& handlers = handlers_[target].get(); | 173 std::vector<HttpAuthHandler*>& handlers = handlers_[target].get(); |
162 handlers.erase(handlers.begin()); | 174 handlers.erase(handlers.begin()); |
163 if (do_init_from_challenge_ && | 175 if (do_init_from_challenge_ && |
164 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 176 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
165 return ERR_INVALID_RESPONSE; | 177 return ERR_INVALID_RESPONSE; |
166 handler->swap(tmp_handler); | 178 handler->swap(tmp_handler); |
167 return OK; | 179 return OK; |
168 } | 180 } |
169 | 181 |
170 } // namespace net | 182 } // namespace net |
OLD | NEW |