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/mock_allow_http_auth_preferences.h> | |
asanka
2015/11/25 19:00:10
include "..." here and elsewhere when including fi
aberent
2015/11/26 15:58:00
Done.
| |
5 #include <set> | 6 #include <set> |
6 #include <string> | 7 #include <string> |
7 | 8 |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
12 #include "net/dns/mock_host_resolver.h" | 13 #include "net/dns/mock_host_resolver.h" |
13 #include "net/http/http_auth.h" | 14 #include "net/http/http_auth.h" |
14 #include "net/http/http_auth_challenge_tokenizer.h" | 15 #include "net/http/http_auth_challenge_tokenizer.h" |
15 #include "net/http/http_auth_filter.h" | 16 #include "net/http/http_auth_filter.h" |
16 #include "net/http/http_auth_handler.h" | 17 #include "net/http/http_auth_handler.h" |
17 #include "net/http/http_auth_handler_factory.h" | 18 #include "net/http/http_auth_handler_factory.h" |
18 #include "net/http/http_auth_handler_mock.h" | 19 #include "net/http/http_auth_handler_mock.h" |
20 #include "net/http/http_auth_scheme.h" | |
19 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
20 #include "net/http/http_util.h" | 22 #include "net/http/http_util.h" |
21 #include "net/http/mock_allow_url_security_manager.h" | |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 namespace net { | 25 namespace net { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 HttpAuthHandlerMock* CreateMockHandler(bool connection_based) { | 29 HttpAuthHandlerMock* CreateMockHandler(bool connection_based) { |
29 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); | 30 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); |
30 auth_handler->set_connection_based(connection_based); | 31 auth_handler->set_connection_based(connection_based); |
31 std::string challenge_text = "Basic"; | 32 std::string challenge_text = "Basic"; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // for gssapi. | 115 // for gssapi. |
115 HttpAuth::AUTH_SCHEME_NEGOTIATE, | 116 HttpAuth::AUTH_SCHEME_NEGOTIATE, |
116 #else | 117 #else |
117 // On systems that don't use Kerberos fall back to NTLM. | 118 // On systems that don't use Kerberos fall back to NTLM. |
118 HttpAuth::AUTH_SCHEME_NTLM, | 119 HttpAuth::AUTH_SCHEME_NTLM, |
119 #endif // defined(USE_KERBEROS) | 120 #endif // defined(USE_KERBEROS) |
120 "", | 121 "", |
121 }}; | 122 }}; |
122 GURL origin("http://www.example.com"); | 123 GURL origin("http://www.example.com"); |
123 std::set<HttpAuth::Scheme> disabled_schemes; | 124 std::set<HttpAuth::Scheme> disabled_schemes; |
124 MockAllowURLSecurityManager url_security_manager; | 125 MockAllowHttpAuthPreferences http_auth_preferences; |
125 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); | 126 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); |
126 scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( | 127 scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( |
127 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); | 128 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); |
128 http_auth_handler_factory->SetURLSecurityManager( | 129 http_auth_handler_factory->SetHttpAuthPreferences(kNegotiateAuthScheme, |
129 "negotiate", &url_security_manager); | 130 &http_auth_preferences); |
130 | 131 |
131 for (size_t i = 0; i < arraysize(tests); ++i) { | 132 for (size_t i = 0; i < arraysize(tests); ++i) { |
132 // Make a HttpResponseHeaders object. | 133 // Make a HttpResponseHeaders object. |
133 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n"); | 134 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n"); |
134 headers_with_status_line += tests[i].headers; | 135 headers_with_status_line += tests[i].headers; |
135 scoped_refptr<HttpResponseHeaders> headers( | 136 scoped_refptr<HttpResponseHeaders> headers( |
136 HeadersFromResponseText(headers_with_status_line)); | 137 HeadersFromResponseText(headers_with_status_line)); |
137 | 138 |
138 scoped_ptr<HttpAuthHandler> handler; | 139 scoped_ptr<HttpAuthHandler> handler; |
139 HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(), | 140 HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 std::string name; | 260 std::string name; |
260 | 261 |
261 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER); | 262 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER); |
262 EXPECT_STREQ("Authorization", name.c_str()); | 263 EXPECT_STREQ("Authorization", name.c_str()); |
263 | 264 |
264 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY); | 265 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY); |
265 EXPECT_STREQ("Proxy-Authorization", name.c_str()); | 266 EXPECT_STREQ("Proxy-Authorization", name.c_str()); |
266 } | 267 } |
267 | 268 |
268 } // namespace net | 269 } // namespace net |
OLD | NEW |