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

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

Issue 1157333005: [net/http auth] Use strings to identify authentication schemes. Base URL: https://chromium.googlesource.com/chromium/src.git@master
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.cc » ('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"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/http/http_auth_challenge_tokenizer.h" 13 #include "net/http/http_auth_challenge_tokenizer.h"
14 #include "net/http/http_request_info.h" 14 #include "net/http/http_request_info.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 HttpAuthHandlerMock::HttpAuthHandlerMock() 19 HttpAuthHandlerMock::HttpAuthHandlerMock()
20 : resolve_(RESOLVE_INIT), 20 : generate_rv_(OK), weak_factory_(this) {}
21 generate_async_(false),
22 generate_rv_(OK),
23 auth_token_(NULL),
24 first_round_(true),
25 connection_based_(false),
26 allows_default_credentials_(false),
27 allows_explicit_credentials_(true),
28 weak_factory_(this) {
29 }
30 21
31 HttpAuthHandlerMock::~HttpAuthHandlerMock() { 22 HttpAuthHandlerMock::~HttpAuthHandlerMock() {
32 } 23 }
33 24
34 void HttpAuthHandlerMock::SetResolveExpectation(Resolve resolve) { 25 void HttpAuthHandlerMock::SetResolveExpectation(Resolve resolve) {
35 EXPECT_EQ(RESOLVE_INIT, resolve_); 26 EXPECT_EQ(RESOLVE_INIT, resolve_);
36 resolve_ = resolve; 27 resolve_ = resolve;
37 } 28 }
38 29
39 bool HttpAuthHandlerMock::NeedsCanonicalName() { 30 bool HttpAuthHandlerMock::NeedsCanonicalName() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return rv; 64 return rv;
74 } 65 }
75 66
76 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) { 67 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) {
77 generate_async_ = async; 68 generate_async_ = async;
78 generate_rv_ = rv; 69 generate_rv_ = rv;
79 } 70 }
80 71
81 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge( 72 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge(
82 HttpAuthChallengeTokenizer* challenge) { 73 HttpAuthChallengeTokenizer* challenge) {
83 // If we receive an empty challenge for a connection based scheme, or a second 74 // If we receive a second challenge for a regular scheme, assume it's a
84 // challenge for a non connection based scheme, assume it's a rejection. 75 // rejection. Receiving an empty second challenge when expecting multiple
85 if (!is_connection_based() || challenge->base64_param().empty()) 76 // rounds is also considered a rejection.
77 if (!expect_multiple_challenges() || challenge->base64_param().empty())
86 return HttpAuth::AUTHORIZATION_RESULT_REJECT; 78 return HttpAuth::AUTHORIZATION_RESULT_REJECT;
87 if (!base::LowerCaseEqualsASCII(challenge->scheme(), "mock")) 79 if (!challenge->SchemeIs("mock"))
88 return HttpAuth::AUTHORIZATION_RESULT_INVALID; 80 return HttpAuth::AUTHORIZATION_RESULT_INVALID;
89 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; 81 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT;
90 } 82 }
91 83
92 bool HttpAuthHandlerMock::NeedsIdentity() { 84 bool HttpAuthHandlerMock::NeedsIdentity() {
93 return first_round_; 85 return first_round_;
94 } 86 }
95 87
96 bool HttpAuthHandlerMock::AllowsDefaultCredentials() { 88 bool HttpAuthHandlerMock::AllowsDefaultCredentials() {
97 return allows_default_credentials_; 89 return allows_default_credentials_;
98 } 90 }
99 91
100 bool HttpAuthHandlerMock::AllowsExplicitCredentials() { 92 bool HttpAuthHandlerMock::AllowsExplicitCredentials() {
101 return allows_explicit_credentials_; 93 return allows_explicit_credentials_;
102 } 94 }
103 95
104 bool HttpAuthHandlerMock::Init(HttpAuthChallengeTokenizer* challenge) { 96 bool HttpAuthHandlerMock::Init(HttpAuthChallengeTokenizer* challenge) {
105 auth_scheme_ = HttpAuth::AUTH_SCHEME_MOCK; 97 auth_scheme_ = "mock";
106 score_ = 1;
107 properties_ = connection_based_ ? IS_CONNECTION_BASED : 0;
108 return true; 98 return true;
109 } 99 }
110 100
111 int HttpAuthHandlerMock::GenerateAuthTokenImpl( 101 int HttpAuthHandlerMock::GenerateAuthTokenImpl(
112 const AuthCredentials* credentials, 102 const AuthCredentials* credentials,
113 const HttpRequestInfo* request, 103 const HttpRequestInfo* request,
114 const CompletionCallback& callback, 104 const CompletionCallback& callback,
115 std::string* auth_token) { 105 std::string* auth_token) {
116 first_round_ = false; 106 first_round_ = false;
117 request_url_ = request->url; 107 request_url_ = request->url;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 147 }
158 148
159 HttpAuthHandlerMock::Factory::~Factory() { 149 HttpAuthHandlerMock::Factory::~Factory() {
160 } 150 }
161 151
162 void HttpAuthHandlerMock::Factory::AddMockHandler( 152 void HttpAuthHandlerMock::Factory::AddMockHandler(
163 HttpAuthHandler* handler, HttpAuth::Target target) { 153 HttpAuthHandler* handler, HttpAuth::Target target) {
164 handlers_[target].push_back(handler); 154 handlers_[target].push_back(handler);
165 } 155 }
166 156
157 bool HttpAuthHandlerMock::Factory::HaveAuthHandlers(
158 HttpAuth::Target target) const {
159 return !handlers_[target].empty();
160 }
161
167 int HttpAuthHandlerMock::Factory::CreateAuthHandler( 162 int HttpAuthHandlerMock::Factory::CreateAuthHandler(
168 HttpAuthChallengeTokenizer* challenge, 163 HttpAuthChallengeTokenizer* challenge,
169 HttpAuth::Target target, 164 HttpAuth::Target target,
170 const GURL& origin, 165 const GURL& origin,
171 CreateReason reason, 166 CreateReason reason,
172 int nonce_count, 167 int nonce_count,
173 const BoundNetLog& net_log, 168 const BoundNetLog& net_log,
174 scoped_ptr<HttpAuthHandler>* handler) { 169 scoped_ptr<HttpAuthHandler>* handler) {
175 if (handlers_[target].empty()) 170 if (handlers_[target].empty())
176 return ERR_UNEXPECTED; 171 return ERR_UNEXPECTED;
177 scoped_ptr<HttpAuthHandler> tmp_handler(handlers_[target][0]); 172 scoped_ptr<HttpAuthHandler> tmp_handler(handlers_[target][0]);
178 std::vector<HttpAuthHandler*>& handlers = handlers_[target].get(); 173 std::vector<HttpAuthHandler*>& handlers = handlers_[target].get();
179 handlers.erase(handlers.begin()); 174 handlers.erase(handlers.begin());
180 if (do_init_from_challenge_ && 175 if (do_init_from_challenge_ &&
181 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) 176 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
182 return ERR_INVALID_RESPONSE; 177 return ERR_INVALID_RESPONSE;
183 handler->swap(tmp_handler); 178 handler->swap(tmp_handler);
184 return OK; 179 return OK;
185 } 180 }
186 181
187 } // namespace net 182 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_mock.h ('k') | net/http/http_auth_handler_negotiate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698