OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_negotiate.h" | 5 #include "net/http/http_auth_handler_negotiate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
13 #include "net/dns/mock_host_resolver.h" | 13 #include "net/dns/mock_host_resolver.h" |
14 #include "net/http/http_auth_challenge_tokenizer.h" | 14 #include "net/http/http_auth_challenge_tokenizer.h" |
15 #include "net/http/http_request_info.h" | 15 #include "net/http/http_request_info.h" |
| 16 #include "net/http/http_response_info.h" |
16 #include "net/http/mock_allow_url_security_manager.h" | 17 #include "net/http/mock_allow_url_security_manager.h" |
17 #if defined(OS_ANDROID) | 18 #if defined(OS_ANDROID) |
18 #include "net/android/dummy_spnego_authenticator.h" | 19 #include "net/android/dummy_spnego_authenticator.h" |
19 #elif defined(OS_WIN) | 20 #elif defined(OS_WIN) |
20 #include "net/http/mock_sspi_library_win.h" | 21 #include "net/http/mock_sspi_library_win.h" |
21 #elif defined(OS_POSIX) | 22 #elif defined(OS_POSIX) |
22 #include "net/http/mock_gssapi_library_posix.h" | 23 #include "net/http/mock_gssapi_library_posix.h" |
23 #endif | 24 #endif |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "testing/platform_test.h" | 26 #include "testing/platform_test.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 mock_library->ExpectSecurityContext(query.expected_package, | 185 mock_library->ExpectSecurityContext(query.expected_package, |
185 query.response_code, | 186 query.response_code, |
186 query.minor_response_code, | 187 query.minor_response_code, |
187 query.context_info, | 188 query.context_info, |
188 query.expected_input_token, | 189 query.expected_input_token, |
189 query.output_token); | 190 query.output_token); |
190 } | 191 } |
191 | 192 |
192 #endif // defined(OS_POSIX) | 193 #endif // defined(OS_POSIX) |
193 | 194 |
194 int CreateHandler(bool disable_cname_lookup, bool use_port, | 195 int CreateHandler(bool disable_cname_lookup, |
195 bool synchronous_resolve_mode, | 196 bool use_port, |
196 const std::string& url_string, | 197 bool synchronous_resolve_mode, |
197 scoped_ptr<HttpAuthHandlerNegotiate>* handler) { | 198 const std::string& url_string, |
| 199 scoped_ptr<HttpAuthHandlerNegotiate>* handler) { |
198 factory_->set_disable_cname_lookup(disable_cname_lookup); | 200 factory_->set_disable_cname_lookup(disable_cname_lookup); |
199 factory_->set_use_port(use_port); | 201 factory_->set_use_port(use_port); |
200 resolver_->set_synchronous_mode(synchronous_resolve_mode); | 202 resolver_->set_synchronous_mode(synchronous_resolve_mode); |
201 GURL gurl(url_string); | 203 GURL gurl(url_string); |
202 | 204 |
203 // Note: This is a little tricky because CreateAuthHandlerFromString | 205 // Note: This is a little tricky because CreateAuthHandlerFromString |
204 // expects a scoped_ptr<HttpAuthHandler>* rather than a | 206 // expects a scoped_ptr<HttpAuthHandler>* rather than a |
205 // scoped_ptr<HttpAuthHandlerNegotiate>*. This needs to do the cast | 207 // scoped_ptr<HttpAuthHandlerNegotiate>*. This needs to do the cast |
206 // after creating the handler, and make sure that generic_handler | 208 // after creating the handler, and make sure that generic_handler |
207 // no longer holds on to the HttpAuthHandlerNegotiate object. | 209 // no longer holds on to the HttpAuthHandlerNegotiate object. |
208 std::string challenge = "Negotiate"; | 210 std::string challenge = "Negotiate"; |
209 HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end()); | 211 HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end()); |
210 | 212 |
211 scoped_ptr<HttpAuthHandler> generic_handler = | 213 scoped_ptr<HttpAuthHandler> generic_handler = |
212 factory_->CreateAuthHandlerForScheme(tokenizer.NormalizedScheme()); | 214 factory_->CreateAuthHandlerForScheme(tokenizer.NormalizedScheme()); |
213 if (!generic_handler) | 215 if (!generic_handler) |
214 return ERR_UNSUPPORTED_AUTH_SCHEME; | 216 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 217 HttpResponseInfo fake_response_info; |
| 218 TestCompletionCallback callback; |
215 int rv = generic_handler->HandleInitialChallenge( | 219 int rv = generic_handler->HandleInitialChallenge( |
216 tokenizer, HttpAuth::AUTH_SERVER, gurl, BoundNetLog()); | 220 tokenizer, fake_response_info, HttpAuth::AUTH_SERVER, gurl, |
| 221 BoundNetLog(), callback.callback()); |
| 222 rv = callback.GetResult(rv); |
217 if (rv != OK) | 223 if (rv != OK) |
218 return rv; | 224 return rv; |
219 HttpAuthHandlerNegotiate* negotiate_handler = | 225 HttpAuthHandlerNegotiate* negotiate_handler = |
220 static_cast<HttpAuthHandlerNegotiate*>(generic_handler.release()); | 226 static_cast<HttpAuthHandlerNegotiate*>(generic_handler.release()); |
221 handler->reset(negotiate_handler); | 227 handler->reset(negotiate_handler); |
222 return rv; | 228 return rv; |
223 } | 229 } |
224 | 230 |
225 MockAuthLibrary* AuthLibrary() { return auth_library_; } | 231 MockAuthLibrary* AuthLibrary() { return auth_library_; } |
226 | 232 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 BoundNetLog(), | 390 BoundNetLog(), |
385 &generic_handler); | 391 &generic_handler); |
386 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); | 392 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); |
387 EXPECT_TRUE(generic_handler.get() == NULL); | 393 EXPECT_TRUE(generic_handler.get() == NULL); |
388 } | 394 } |
389 #endif // defined(DLOPEN_KERBEROS) | 395 #endif // defined(DLOPEN_KERBEROS) |
390 | 396 |
391 #endif // defined(OS_POSIX) | 397 #endif // defined(OS_POSIX) |
392 | 398 |
393 } // namespace net | 399 } // namespace net |
OLD | NEW |