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

Side by Side Diff: net/http/http_auth_handler_mock.cc

Issue 1383613002: [net/http auth] Cleanup. Method names, and constness. Base URL: https://chromium.googlesource.com/chromium/src.git@mock-auth-handler-generalization
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 unified diff | Download patch
« no previous file with comments | « net/http/http_auth_handler_mock.h ('k') | net/http/http_auth_handler_negotiate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 10 matching lines...) Expand all
21 21
22 HttpAuthHandlerMock::~HttpAuthHandlerMock() { 22 HttpAuthHandlerMock::~HttpAuthHandlerMock() {
23 } 23 }
24 24
25 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) { 25 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) {
26 generate_async_ = async; 26 generate_async_ = async;
27 generate_rv_ = rv; 27 generate_rv_ = rv;
28 } 28 }
29 29
30 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge( 30 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge(
31 HttpAuthChallengeTokenizer* challenge) { 31 const HttpAuthChallengeTokenizer& challenge) {
32 // If we receive a second challenge for a regular scheme, assume it's a 32 // If we receive a second challenge for a regular scheme, assume it's a
33 // rejection. Receiving an empty second challenge when expecting multiple 33 // rejection. Receiving an empty second challenge when expecting multiple
34 // rounds is also considered a rejection. 34 // rounds is also considered a rejection.
35 if (!expect_multiple_challenges_ || challenge->base64_param().empty()) 35 if (!expect_multiple_challenges_ || challenge.base64_param().empty())
36 return HttpAuth::AUTHORIZATION_RESULT_REJECT; 36 return HttpAuth::AUTHORIZATION_RESULT_REJECT;
37 if (!challenge->SchemeIs(auth_scheme_)) 37 if (!challenge.SchemeIs(auth_scheme_))
38 return HttpAuth::AUTHORIZATION_RESULT_INVALID; 38 return HttpAuth::AUTHORIZATION_RESULT_INVALID;
39 auth_token_ = auth_scheme_; 39 auth_token_ = auth_scheme_;
40 auth_token_.append(" continuation,"); 40 auth_token_.append(" continuation,");
41 auth_token_.append(challenge->base64_param()); 41 auth_token_.append(challenge.base64_param());
42 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; 42 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT;
43 } 43 }
44 44
45 bool HttpAuthHandlerMock::NeedsIdentity() { 45 bool HttpAuthHandlerMock::NeedsIdentity() {
46 return first_round_; 46 return first_round_;
47 } 47 }
48 48
49 bool HttpAuthHandlerMock::AllowsDefaultCredentials() { 49 bool HttpAuthHandlerMock::AllowsDefaultCredentials() {
50 return allows_default_credentials_; 50 return allows_default_credentials_;
51 } 51 }
52 52
53 bool HttpAuthHandlerMock::AllowsExplicitCredentials() { 53 bool HttpAuthHandlerMock::AllowsExplicitCredentials() {
54 return allows_explicit_credentials_; 54 return allows_explicit_credentials_;
55 } 55 }
56 56
57 bool HttpAuthHandlerMock::Init(HttpAuthChallengeTokenizer* challenge) { 57 int HttpAuthHandlerMock::Init(const HttpAuthChallengeTokenizer& challenge) {
58 EXPECT_TRUE(challenge->SchemeIs(expected_auth_scheme_)) 58 EXPECT_TRUE(challenge.SchemeIs(expected_auth_scheme_))
59 << "Mismatched scheme for challenge: " << challenge->challenge_text(); 59 << "Mismatched scheme for challenge: " << challenge.challenge_text();
60 EXPECT_TRUE(auth_scheme_.empty()) << "Init was already called."; 60 EXPECT_TRUE(auth_scheme_.empty()) << "Init was already called.";
61 EXPECT_TRUE(HttpAuth::IsValidNormalizedScheme(expected_auth_scheme_)) 61 EXPECT_TRUE(HttpAuth::IsValidNormalizedScheme(expected_auth_scheme_))
62 << "Invalid expected auth scheme."; 62 << "Invalid expected auth scheme.";
63 auth_scheme_ = expected_auth_scheme_; 63 auth_scheme_ = expected_auth_scheme_;
64 auth_token_ = expected_auth_scheme_ + " auth_token"; 64 auth_token_ = expected_auth_scheme_ + " auth_token";
65 if (challenge->params_end() != challenge->params_begin()) { 65 if (challenge.params_end() != challenge.params_begin()) {
66 auth_token_ += ","; 66 auth_token_ += ",";
67 auth_token_.append(challenge->params_begin(), challenge->params_end()); 67 auth_token_.append(challenge.params_begin(), challenge.params_end());
68 } 68 }
69 return true; 69 return OK;
70 } 70 }
71 71
72 int HttpAuthHandlerMock::GenerateAuthTokenImpl( 72 int HttpAuthHandlerMock::GenerateAuthTokenImpl(
73 const AuthCredentials* credentials, 73 const AuthCredentials* credentials,
74 const HttpRequestInfo* request, 74 const HttpRequestInfo& request,
75 const CompletionCallback& callback, 75 const CompletionCallback& callback,
76 std::string* auth_token) { 76 std::string* auth_token) {
77 first_round_ = false; 77 first_round_ = false;
78 request_url_ = request->url; 78 request_url_ = request.url;
79 79
80 if (!credentials || credentials->Empty()) { 80 if (!credentials || credentials->Empty()) {
81 EXPECT_TRUE(AllowsDefaultCredentials()) << "Credentials must be specified " 81 EXPECT_TRUE(AllowsDefaultCredentials()) << "Credentials must be specified "
82 "if the handler doesn't support " 82 "if the handler doesn't support "
83 "default credentials."; 83 "default credentials.";
84 } else { 84 } else {
85 EXPECT_TRUE(AllowsExplicitCredentials()) << "Explicit credentials can only " 85 EXPECT_TRUE(AllowsExplicitCredentials()) << "Explicit credentials can only "
86 "be specified if the handler " 86 "be specified if the handler "
87 "supports it."; 87 "supports it.";
88 } 88 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 challenge_handlers_[target].push_back(handler.Pass()); 131 challenge_handlers_[target].push_back(handler.Pass());
132 } 132 }
133 133
134 bool HttpAuthHandlerMock::Factory::HaveAuthHandlers( 134 bool HttpAuthHandlerMock::Factory::HaveAuthHandlers(
135 HttpAuth::Target target) const { 135 HttpAuth::Target target) const {
136 return !challenge_handlers_[target].empty() || 136 return !challenge_handlers_[target].empty() ||
137 !preemptive_handlers_[target].empty(); 137 !preemptive_handlers_[target].empty();
138 } 138 }
139 139
140 int HttpAuthHandlerMock::Factory::CreateAuthHandler( 140 int HttpAuthHandlerMock::Factory::CreateAuthHandler(
141 HttpAuthChallengeTokenizer* challenge, 141 const HttpAuthChallengeTokenizer& challenge,
142 HttpAuth::Target target, 142 HttpAuth::Target target,
143 const GURL& origin, 143 const GURL& origin,
144 CreateReason reason, 144 CreateReason reason,
145 int nonce_count, 145 int nonce_count,
146 const BoundNetLog& net_log, 146 const BoundNetLog& net_log,
147 scoped_ptr<HttpAuthHandler>* handler) { 147 scoped_ptr<HttpAuthHandler>* handler) {
148 ScopedVector<HttpAuthHandler>& handler_list = 148 ScopedVector<HttpAuthHandler>& handler_list =
149 reason == CREATE_PREEMPTIVE ? preemptive_handlers_[target] 149 reason == CREATE_PREEMPTIVE ? preemptive_handlers_[target]
150 : challenge_handlers_[target]; 150 : challenge_handlers_[target];
151 if (handler_list.empty()) 151 if (handler_list.empty())
152 return ERR_UNEXPECTED; 152 return ERR_UNEXPECTED;
153 scoped_ptr<HttpAuthHandler> tmp_handler(handler_list.front()); 153 scoped_ptr<HttpAuthHandler> tmp_handler(handler_list.front());
154 handler_list.weak_erase(handler_list.begin()); 154 handler_list.weak_erase(handler_list.begin());
155 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) 155 int result =
156 return ERR_INVALID_RESPONSE; 156 tmp_handler->HandleInitialChallenge(challenge, target, origin, net_log);
157 handler->swap(tmp_handler); 157 if (result == OK)
158 return OK; 158 handler->swap(tmp_handler);
159 return result;
159 } 160 }
160 161
161 } // namespace net 162 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_mock.h ('k') | net/http/http_auth_handler_negotiate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698