| 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 "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| 11 #include "net/dns/mock_host_resolver.h" | 11 #include "net/dns/mock_host_resolver.h" |
| 12 #include "net/http/http_request_info.h" | 12 #include "net/http/http_request_info.h" |
| 13 #include "net/http/mock_allow_url_security_manager.h" | 13 #include "net/http/mock_allow_url_security_manager.h" |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include "net/http/mock_sspi_library_win.h" | 15 #include "net/http/mock_sspi_library_win.h" |
| 16 #elif defined(OS_POSIX) | 16 #elif defined(OS_POSIX) |
| 17 #include "net/http/mock_gssapi_library_posix.h" | 17 #include "net/http/mock_gssapi_library_posix.h" |
| 18 #endif | 18 #endif |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
| 21 #include "url/origin.h" |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 25 typedef MockSSPILibrary MockAuthLibrary; | 26 typedef MockSSPILibrary MockAuthLibrary; |
| 26 #elif defined(OS_POSIX) | 27 #elif defined(OS_POSIX) |
| 27 typedef test::MockGSSAPILibrary MockAuthLibrary; | 28 typedef test::MockGSSAPILibrary MockAuthLibrary; |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 class HttpAuthHandlerNegotiateTest : public PlatformTest { | 31 class HttpAuthHandlerNegotiateTest : public PlatformTest { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 173 |
| 173 #endif // defined(OS_POSIX) | 174 #endif // defined(OS_POSIX) |
| 174 | 175 |
| 175 int CreateHandler(bool disable_cname_lookup, bool use_port, | 176 int CreateHandler(bool disable_cname_lookup, bool use_port, |
| 176 bool synchronous_resolve_mode, | 177 bool synchronous_resolve_mode, |
| 177 const std::string& url_string, | 178 const std::string& url_string, |
| 178 scoped_ptr<HttpAuthHandlerNegotiate>* handler) { | 179 scoped_ptr<HttpAuthHandlerNegotiate>* handler) { |
| 179 factory_->set_disable_cname_lookup(disable_cname_lookup); | 180 factory_->set_disable_cname_lookup(disable_cname_lookup); |
| 180 factory_->set_use_port(use_port); | 181 factory_->set_use_port(use_port); |
| 181 resolver_->set_synchronous_mode(synchronous_resolve_mode); | 182 resolver_->set_synchronous_mode(synchronous_resolve_mode); |
| 182 GURL gurl(url_string); | 183 url::Origin origin(url_string); |
| 183 | 184 |
| 184 // Note: This is a little tricky because CreateAuthHandlerFromString | 185 // Note: This is a little tricky because CreateAuthHandlerFromString |
| 185 // expects a scoped_ptr<HttpAuthHandler>* rather than a | 186 // expects a scoped_ptr<HttpAuthHandler>* rather than a |
| 186 // scoped_ptr<HttpAuthHandlerNegotiate>*. This needs to do the cast | 187 // scoped_ptr<HttpAuthHandlerNegotiate>*. This needs to do the cast |
| 187 // after creating the handler, and make sure that generic_handler | 188 // after creating the handler, and make sure that generic_handler |
| 188 // no longer holds on to the HttpAuthHandlerNegotiate object. | 189 // no longer holds on to the HttpAuthHandlerNegotiate object. |
| 189 scoped_ptr<HttpAuthHandler> generic_handler; | 190 scoped_ptr<HttpAuthHandler> generic_handler; |
| 190 int rv = factory_->CreateAuthHandlerFromString("Negotiate", | 191 int rv = factory_->CreateAuthHandlerFromString( |
| 191 HttpAuth::AUTH_SERVER, | 192 "Negotiate", HttpAuth::AUTH_SERVER, origin, BoundNetLog(), |
| 192 gurl, | 193 &generic_handler); |
| 193 BoundNetLog(), | |
| 194 &generic_handler); | |
| 195 if (rv != OK) | 194 if (rv != OK) |
| 196 return rv; | 195 return rv; |
| 197 HttpAuthHandlerNegotiate* negotiate_handler = | 196 HttpAuthHandlerNegotiate* negotiate_handler = |
| 198 static_cast<HttpAuthHandlerNegotiate*>(generic_handler.release()); | 197 static_cast<HttpAuthHandlerNegotiate*>(generic_handler.release()); |
| 199 handler->reset(negotiate_handler); | 198 handler->reset(negotiate_handler); |
| 200 return rv; | 199 return rv; |
| 201 } | 200 } |
| 202 | 201 |
| 203 MockAuthLibrary* AuthLibrary() { return auth_library_; } | 202 MockAuthLibrary* AuthLibrary() { return auth_library_; } |
| 204 | 203 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 BoundNetLog(), | 358 BoundNetLog(), |
| 360 &generic_handler); | 359 &generic_handler); |
| 361 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); | 360 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); |
| 362 EXPECT_TRUE(generic_handler.get() == NULL); | 361 EXPECT_TRUE(generic_handler.get() == NULL); |
| 363 } | 362 } |
| 364 #endif // defined(DLOPEN_KERBEROS) | 363 #endif // defined(DLOPEN_KERBEROS) |
| 365 | 364 |
| 366 #endif // defined(OS_POSIX) | 365 #endif // defined(OS_POSIX) |
| 367 | 366 |
| 368 } // namespace net | 367 } // namespace net |
| OLD | NEW |