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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 typedef net::test::MockGSSAPILibrary MockAuthLibrary; | 25 typedef net::test::MockGSSAPILibrary MockAuthLibrary; |
26 #endif | 26 #endif |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 | 29 |
30 class HttpAuthHandlerNegotiateTest : public PlatformTest { | 30 class HttpAuthHandlerNegotiateTest : public PlatformTest { |
31 public: | 31 public: |
32 virtual void SetUp() { | 32 virtual void SetUp() { |
33 auth_library_ = new MockAuthLibrary(); | 33 auth_library_ = new MockAuthLibrary(); |
34 resolver_.reset(new MockHostResolver()); | 34 resolver_.reset(new MockHostResolver()); |
35 resolver_->rules()->AddIPLiteralRule("alias", "10.0.0.2", | 35 resolver_->rules()->AddIPLiteralRule( |
36 "canonical.example.com"); | 36 "alias", "10.0.0.2", "canonical.example.com"); |
37 | 37 |
38 url_security_manager_.reset(new MockAllowURLSecurityManager()); | 38 url_security_manager_.reset(new MockAllowURLSecurityManager()); |
39 factory_.reset(new HttpAuthHandlerNegotiate::Factory()); | 39 factory_.reset(new HttpAuthHandlerNegotiate::Factory()); |
40 factory_->set_url_security_manager(url_security_manager_.get()); | 40 factory_->set_url_security_manager(url_security_manager_.get()); |
41 factory_->set_library(auth_library_); | 41 factory_->set_library(auth_library_); |
42 factory_->set_host_resolver(resolver_.get()); | 42 factory_->set_host_resolver(resolver_.get()); |
43 } | 43 } |
44 | 44 |
45 void SetupMocks(MockAuthLibrary* mock_library) { | 45 void SetupMocks(MockAuthLibrary* mock_library) { |
46 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 "\x2C\xE3\xEA\x64\xEF\x91\xA5\x4E\x94\xE1\xDC\x56\x3A\xAF\xD5\xBC" | 91 "\x2C\xE3\xEA\x64\xEF\x91\xA5\x4E\x94\xE1\xDC\x56\x3A\xAF\xD5\xBC" |
92 "\xC9\xD3\x9B\x6B\x1F\xBE\x40\xE5\x40\xFF\x5E\x21\xEA\xCE\xFC\xD5" | 92 "\xC9\xD3\x9B\x6B\x1F\xBE\x40\xE5\x40\xFF\x5E\x21\xEA\xCE\xFC\xD5" |
93 "\xB0\xE5\xBA\x10\x94\xAE\x16\x54\xFC\xEB\xAB\xF1\xD4\x20\x31\xCC" | 93 "\xB0\xE5\xBA\x10\x94\xAE\x16\x54\xFC\xEB\xAB\xF1\xD4\x20\x31\xCC" |
94 "\x26\xFE\xBE\xFE\x22\xB6\x9B\x1A\xE5\x55\x2C\x93\xB7\x3B\xD6\x4C" | 94 "\x26\xFE\xBE\xFE\x22\xB6\x9B\x1A\xE5\x55\x2C\x93\xB7\x3B\xD6\x4C" |
95 "\x35\x35\xC1\x59\x61\xD4\x1F\x2E\x4C\xE1\x72\x8F\x71\x4B\x0C\x39" | 95 "\x35\x35\xC1\x59\x61\xD4\x1F\x2E\x4C\xE1\x72\x8F\x71\x4B\x0C\x39" |
96 "\x80\x79\xFA\xCD\xEA\x71\x1B\xAE\x35\x41\xED\xF9\x65\x0C\x59\xF8" | 96 "\x80\x79\xFA\xCD\xEA\x71\x1B\xAE\x35\x41\xED\xF9\x65\x0C\x59\xF8" |
97 "\xE1\x27\xDA\xD6\xD1\x20\x32\xCD\xBF\xD1\xEF\xE2\xED\xAD\x5D\xA7" | 97 "\xE1\x27\xDA\xD6\xD1\x20\x32\xCD\xBF\xD1\xEF\xE2\xED\xAD\x5D\xA7" |
98 "\x69\xE3\x55\xF9\x30\xD3\xD4\x08\xC8\xCA\x62\xF8\x64\xEC\x9B\x92" | 98 "\x69\xE3\x55\xF9\x30\xD3\xD4\x08\xC8\xCA\x62\xF8\x64\xEC\x9B\x92" |
99 "\x1A\xF1\x03\x2E\xCC\xDC\xEB\x17\xDE\x09\xAC\xA9\x58\x86"; | 99 "\x1A\xF1\x03\x2E\xCC\xDC\xEB\x17\xDE\x09\xAC\xA9\x58\x86"; |
100 test::GssContextMockImpl context1( | 100 test::GssContextMockImpl context1( |
101 "localhost", // Source name | 101 "localhost", // Source name |
102 "example.com", // Target name | 102 "example.com", // Target name |
103 23, // Lifetime | 103 23, // Lifetime |
104 *CHROME_GSS_SPNEGO_MECH_OID_DESC, // Mechanism | 104 *CHROME_GSS_SPNEGO_MECH_OID_DESC, // Mechanism |
105 0, // Context flags | 105 0, // Context flags |
106 1, // Locally initiated | 106 1, // Locally initiated |
107 0); // Open | 107 0); // Open |
108 test::GssContextMockImpl context2( | 108 test::GssContextMockImpl context2( |
109 "localhost", // Source name | 109 "localhost", // Source name |
110 "example.com", // Target name | 110 "example.com", // Target name |
111 23, // Lifetime | 111 23, // Lifetime |
112 *CHROME_GSS_SPNEGO_MECH_OID_DESC, // Mechanism | 112 *CHROME_GSS_SPNEGO_MECH_OID_DESC, // Mechanism |
113 0, // Context flags | 113 0, // Context flags |
114 1, // Locally initiated | 114 1, // Locally initiated |
115 1); // Open | 115 1); // Open |
116 test::MockGSSAPILibrary::SecurityContextQuery queries[] = { | 116 test::MockGSSAPILibrary::SecurityContextQuery queries[] = { |
117 test::MockGSSAPILibrary::SecurityContextQuery( | 117 test::MockGSSAPILibrary::SecurityContextQuery( |
118 "Negotiate", // Package name | 118 "Negotiate", // Package name |
119 GSS_S_CONTINUE_NEEDED, // Major response code | 119 GSS_S_CONTINUE_NEEDED, // Major response code |
120 0, // Minor response code | 120 0, // Minor response code |
121 context1, // Context | 121 context1, // Context |
122 NULL, // Expected input token | 122 NULL, // Expected input token |
123 kAuthResponse), // Output token | 123 kAuthResponse), // Output token |
124 test::MockGSSAPILibrary::SecurityContextQuery( | 124 test::MockGSSAPILibrary::SecurityContextQuery( |
125 "Negotiate", // Package name | 125 "Negotiate", // Package name |
126 GSS_S_COMPLETE, // Major response code | 126 GSS_S_COMPLETE, // Major response code |
127 0, // Minor response code | 127 0, // Minor response code |
128 context2, // Context | 128 context2, // Context |
129 kAuthResponse, // Expected input token | 129 kAuthResponse, // Expected input token |
130 kAuthResponse) // Output token | 130 kAuthResponse) // Output token |
131 }; | 131 }; |
132 | 132 |
133 for (size_t i = 0; i < arraysize(queries); ++i) { | 133 for (size_t i = 0; i < arraysize(queries); ++i) { |
134 mock_library->ExpectSecurityContext(queries[i].expected_package, | 134 mock_library->ExpectSecurityContext(queries[i].expected_package, |
135 queries[i].response_code, | 135 queries[i].response_code, |
136 queries[i].minor_response_code, | 136 queries[i].minor_response_code, |
137 queries[i].context_info, | 137 queries[i].context_info, |
138 queries[i].expected_input_token, | 138 queries[i].expected_input_token, |
139 queries[i].output_token); | 139 queries[i].output_token); |
140 } | 140 } |
141 #endif // defined(OS_POSIX) | 141 #endif // defined(OS_POSIX) |
142 } | 142 } |
143 | 143 |
144 #if defined(OS_POSIX) | 144 #if defined(OS_POSIX) |
145 void SetupErrorMocks(MockAuthLibrary* mock_library, | 145 void SetupErrorMocks(MockAuthLibrary* mock_library, |
146 int major_status, | 146 int major_status, |
147 int minor_status) { | 147 int minor_status) { |
148 const gss_OID_desc kDefaultMech = { 0, NULL }; | 148 const gss_OID_desc kDefaultMech = {0, NULL}; |
149 test::GssContextMockImpl context( | 149 test::GssContextMockImpl context("localhost", // Source name |
150 "localhost", // Source name | 150 "example.com", // Target name |
151 "example.com", // Target name | 151 0, // Lifetime |
152 0, // Lifetime | 152 kDefaultMech, // Mechanism |
153 kDefaultMech, // Mechanism | 153 0, // Context flags |
154 0, // Context flags | 154 1, // Locally initiated |
155 1, // Locally initiated | 155 0); // Open |
156 0); // Open | |
157 test::MockGSSAPILibrary::SecurityContextQuery query( | 156 test::MockGSSAPILibrary::SecurityContextQuery query( |
158 "Negotiate", // Package name | 157 "Negotiate", // Package name |
159 major_status, // Major response code | 158 major_status, // Major response code |
160 minor_status, // Minor response code | 159 minor_status, // Minor response code |
161 context, // Context | 160 context, // Context |
162 NULL, // Expected input token | 161 NULL, // Expected input token |
163 NULL); // Output token | 162 NULL); // Output token |
164 | 163 |
165 mock_library->ExpectSecurityContext(query.expected_package, | 164 mock_library->ExpectSecurityContext(query.expected_package, |
166 query.response_code, | 165 query.response_code, |
167 query.minor_response_code, | 166 query.minor_response_code, |
168 query.context_info, | 167 query.context_info, |
169 query.expected_input_token, | 168 query.expected_input_token, |
170 query.output_token); | 169 query.output_token); |
171 } | 170 } |
172 | 171 |
173 #endif // defined(OS_POSIX) | 172 #endif // defined(OS_POSIX) |
174 | 173 |
175 int CreateHandler(bool disable_cname_lookup, bool use_port, | 174 int CreateHandler(bool disable_cname_lookup, |
176 bool synchronous_resolve_mode, | 175 bool use_port, |
177 const std::string& url_string, | 176 bool synchronous_resolve_mode, |
178 scoped_ptr<HttpAuthHandlerNegotiate>* handler) { | 177 const std::string& url_string, |
| 178 scoped_ptr<HttpAuthHandlerNegotiate>* handler) { |
179 factory_->set_disable_cname_lookup(disable_cname_lookup); | 179 factory_->set_disable_cname_lookup(disable_cname_lookup); |
180 factory_->set_use_port(use_port); | 180 factory_->set_use_port(use_port); |
181 resolver_->set_synchronous_mode(synchronous_resolve_mode); | 181 resolver_->set_synchronous_mode(synchronous_resolve_mode); |
182 GURL gurl(url_string); | 182 GURL gurl(url_string); |
183 | 183 |
184 // Note: This is a little tricky because CreateAuthHandlerFromString | 184 // Note: This is a little tricky because CreateAuthHandlerFromString |
185 // expects a scoped_ptr<HttpAuthHandler>* rather than a | 185 // expects a scoped_ptr<HttpAuthHandler>* rather than a |
186 // scoped_ptr<HttpAuthHandlerNegotiate>*. This needs to do the cast | 186 // scoped_ptr<HttpAuthHandlerNegotiate>*. This needs to do the cast |
187 // after creating the handler, and make sure that generic_handler | 187 // after creating the handler, and make sure that generic_handler |
188 // no longer holds on to the HttpAuthHandlerNegotiate object. | 188 // no longer holds on to the HttpAuthHandlerNegotiate object. |
(...skipping 20 matching lines...) Expand all Loading... |
209 // |auth_library_| is passed to |factory_|, which assumes ownership of it. | 209 // |auth_library_| is passed to |factory_|, which assumes ownership of it. |
210 MockAuthLibrary* auth_library_; | 210 MockAuthLibrary* auth_library_; |
211 scoped_ptr<MockHostResolver> resolver_; | 211 scoped_ptr<MockHostResolver> resolver_; |
212 scoped_ptr<URLSecurityManager> url_security_manager_; | 212 scoped_ptr<URLSecurityManager> url_security_manager_; |
213 scoped_ptr<HttpAuthHandlerNegotiate::Factory> factory_; | 213 scoped_ptr<HttpAuthHandlerNegotiate::Factory> factory_; |
214 }; | 214 }; |
215 | 215 |
216 TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) { | 216 TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) { |
217 SetupMocks(AuthLibrary()); | 217 SetupMocks(AuthLibrary()); |
218 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 218 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
219 EXPECT_EQ(OK, CreateHandler( | 219 EXPECT_EQ( |
220 true, false, true, "http://alias:500", &auth_handler)); | 220 OK, CreateHandler(true, false, true, "http://alias:500", &auth_handler)); |
221 | 221 |
222 ASSERT_TRUE(auth_handler.get() != NULL); | 222 ASSERT_TRUE(auth_handler.get() != NULL); |
223 TestCompletionCallback callback; | 223 TestCompletionCallback callback; |
224 HttpRequestInfo request_info; | 224 HttpRequestInfo request_info; |
225 std::string token; | 225 std::string token; |
226 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, | 226 EXPECT_EQ(OK, |
227 callback.callback(), &token)); | 227 auth_handler->GenerateAuthToken( |
| 228 NULL, &request_info, callback.callback(), &token)); |
228 #if defined(OS_WIN) | 229 #if defined(OS_WIN) |
229 EXPECT_EQ("HTTP/alias", auth_handler->spn()); | 230 EXPECT_EQ("HTTP/alias", auth_handler->spn()); |
230 #elif defined(OS_POSIX) | 231 #elif defined(OS_POSIX) |
231 EXPECT_EQ("HTTP@alias", auth_handler->spn()); | 232 EXPECT_EQ("HTTP@alias", auth_handler->spn()); |
232 #endif | 233 #endif |
233 } | 234 } |
234 | 235 |
235 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { | 236 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { |
236 SetupMocks(AuthLibrary()); | 237 SetupMocks(AuthLibrary()); |
237 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 238 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
238 EXPECT_EQ(OK, CreateHandler( | 239 EXPECT_EQ(OK, |
239 true, true, true, "http://alias:80", &auth_handler)); | 240 CreateHandler(true, true, true, "http://alias:80", &auth_handler)); |
240 ASSERT_TRUE(auth_handler.get() != NULL); | 241 ASSERT_TRUE(auth_handler.get() != NULL); |
241 TestCompletionCallback callback; | 242 TestCompletionCallback callback; |
242 HttpRequestInfo request_info; | 243 HttpRequestInfo request_info; |
243 std::string token; | 244 std::string token; |
244 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, | 245 EXPECT_EQ(OK, |
245 callback.callback(), &token)); | 246 auth_handler->GenerateAuthToken( |
| 247 NULL, &request_info, callback.callback(), &token)); |
246 #if defined(OS_WIN) | 248 #if defined(OS_WIN) |
247 EXPECT_EQ("HTTP/alias", auth_handler->spn()); | 249 EXPECT_EQ("HTTP/alias", auth_handler->spn()); |
248 #elif defined(OS_POSIX) | 250 #elif defined(OS_POSIX) |
249 EXPECT_EQ("HTTP@alias", auth_handler->spn()); | 251 EXPECT_EQ("HTTP@alias", auth_handler->spn()); |
250 #endif | 252 #endif |
251 } | 253 } |
252 | 254 |
253 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { | 255 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { |
254 SetupMocks(AuthLibrary()); | 256 SetupMocks(AuthLibrary()); |
255 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 257 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
256 EXPECT_EQ(OK, CreateHandler( | 258 EXPECT_EQ(OK, |
257 true, true, true, "http://alias:500", &auth_handler)); | 259 CreateHandler(true, true, true, "http://alias:500", &auth_handler)); |
258 ASSERT_TRUE(auth_handler.get() != NULL); | 260 ASSERT_TRUE(auth_handler.get() != NULL); |
259 TestCompletionCallback callback; | 261 TestCompletionCallback callback; |
260 HttpRequestInfo request_info; | 262 HttpRequestInfo request_info; |
261 std::string token; | 263 std::string token; |
262 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, | 264 EXPECT_EQ(OK, |
263 callback.callback(), &token)); | 265 auth_handler->GenerateAuthToken( |
| 266 NULL, &request_info, callback.callback(), &token)); |
264 #if defined(OS_WIN) | 267 #if defined(OS_WIN) |
265 EXPECT_EQ("HTTP/alias:500", auth_handler->spn()); | 268 EXPECT_EQ("HTTP/alias:500", auth_handler->spn()); |
266 #elif defined(OS_POSIX) | 269 #elif defined(OS_POSIX) |
267 EXPECT_EQ("HTTP@alias:500", auth_handler->spn()); | 270 EXPECT_EQ("HTTP@alias:500", auth_handler->spn()); |
268 #endif | 271 #endif |
269 } | 272 } |
270 | 273 |
271 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { | 274 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { |
272 SetupMocks(AuthLibrary()); | 275 SetupMocks(AuthLibrary()); |
273 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 276 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
274 EXPECT_EQ(OK, CreateHandler( | 277 EXPECT_EQ( |
275 false, false, true, "http://alias:500", &auth_handler)); | 278 OK, CreateHandler(false, false, true, "http://alias:500", &auth_handler)); |
276 ASSERT_TRUE(auth_handler.get() != NULL); | 279 ASSERT_TRUE(auth_handler.get() != NULL); |
277 TestCompletionCallback callback; | 280 TestCompletionCallback callback; |
278 HttpRequestInfo request_info; | 281 HttpRequestInfo request_info; |
279 std::string token; | 282 std::string token; |
280 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info, | 283 EXPECT_EQ(OK, |
281 callback.callback(), &token)); | 284 auth_handler->GenerateAuthToken( |
| 285 NULL, &request_info, callback.callback(), &token)); |
282 #if defined(OS_WIN) | 286 #if defined(OS_WIN) |
283 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); | 287 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); |
284 #elif defined(OS_POSIX) | 288 #elif defined(OS_POSIX) |
285 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); | 289 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); |
286 #endif | 290 #endif |
287 } | 291 } |
288 | 292 |
289 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { | 293 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { |
290 SetupMocks(AuthLibrary()); | 294 SetupMocks(AuthLibrary()); |
291 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 295 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
292 EXPECT_EQ(OK, CreateHandler( | 296 EXPECT_EQ( |
293 false, false, false, "http://alias:500", &auth_handler)); | 297 OK, |
| 298 CreateHandler(false, false, false, "http://alias:500", &auth_handler)); |
294 ASSERT_TRUE(auth_handler.get() != NULL); | 299 ASSERT_TRUE(auth_handler.get() != NULL); |
295 TestCompletionCallback callback; | 300 TestCompletionCallback callback; |
296 HttpRequestInfo request_info; | 301 HttpRequestInfo request_info; |
297 std::string token; | 302 std::string token; |
298 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 303 EXPECT_EQ(ERR_IO_PENDING, |
299 NULL, &request_info, callback.callback(), &token)); | 304 auth_handler->GenerateAuthToken( |
| 305 NULL, &request_info, callback.callback(), &token)); |
300 EXPECT_EQ(OK, callback.WaitForResult()); | 306 EXPECT_EQ(OK, callback.WaitForResult()); |
301 #if defined(OS_WIN) | 307 #if defined(OS_WIN) |
302 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); | 308 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); |
303 #elif defined(OS_POSIX) | 309 #elif defined(OS_POSIX) |
304 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); | 310 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); |
305 #endif | 311 #endif |
306 } | 312 } |
307 | 313 |
308 #if defined(OS_POSIX) | 314 #if defined(OS_POSIX) |
309 | 315 |
310 // This test is only for GSSAPI, as we can't use explicit credentials with | 316 // This test is only for GSSAPI, as we can't use explicit credentials with |
311 // that library. | 317 // that library. |
312 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) { | 318 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) { |
313 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server | 319 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server |
314 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 320 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
315 EXPECT_EQ(OK, CreateHandler( | 321 EXPECT_EQ( |
316 false, false, false, "http://alias:500", &auth_handler)); | 322 OK, |
| 323 CreateHandler(false, false, false, "http://alias:500", &auth_handler)); |
317 ASSERT_TRUE(auth_handler.get() != NULL); | 324 ASSERT_TRUE(auth_handler.get() != NULL); |
318 TestCompletionCallback callback; | 325 TestCompletionCallback callback; |
319 HttpRequestInfo request_info; | 326 HttpRequestInfo request_info; |
320 std::string token; | 327 std::string token; |
321 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 328 EXPECT_EQ(ERR_IO_PENDING, |
322 NULL, &request_info, callback.callback(), &token)); | 329 auth_handler->GenerateAuthToken( |
| 330 NULL, &request_info, callback.callback(), &token)); |
323 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); | 331 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); |
324 } | 332 } |
325 | 333 |
326 // This test is only for GSSAPI, as we can't use explicit credentials with | 334 // This test is only for GSSAPI, as we can't use explicit credentials with |
327 // that library. | 335 // that library. |
328 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) { | 336 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) { |
329 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials | 337 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials |
330 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 338 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
331 EXPECT_EQ(OK, CreateHandler( | 339 EXPECT_EQ( |
332 false, false, false, "http://alias:500", &auth_handler)); | 340 OK, |
| 341 CreateHandler(false, false, false, "http://alias:500", &auth_handler)); |
333 ASSERT_TRUE(auth_handler.get() != NULL); | 342 ASSERT_TRUE(auth_handler.get() != NULL); |
334 TestCompletionCallback callback; | 343 TestCompletionCallback callback; |
335 HttpRequestInfo request_info; | 344 HttpRequestInfo request_info; |
336 std::string token; | 345 std::string token; |
337 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 346 EXPECT_EQ(ERR_IO_PENDING, |
338 NULL, &request_info, callback.callback(), &token)); | 347 auth_handler->GenerateAuthToken( |
| 348 NULL, &request_info, callback.callback(), &token)); |
339 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); | 349 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); |
340 } | 350 } |
341 | 351 |
342 #if defined(DLOPEN_KERBEROS) | 352 #if defined(DLOPEN_KERBEROS) |
343 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) { | 353 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) { |
344 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); | 354 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); |
345 MockAllowURLSecurityManager url_security_manager; | 355 MockAllowURLSecurityManager url_security_manager; |
346 scoped_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory( | 356 scoped_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory( |
347 new HttpAuthHandlerNegotiate::Factory()); | 357 new HttpAuthHandlerNegotiate::Factory()); |
348 negotiate_factory->set_host_resolver(host_resolver.get()); | 358 negotiate_factory->set_host_resolver(host_resolver.get()); |
349 negotiate_factory->set_url_security_manager(&url_security_manager); | 359 negotiate_factory->set_url_security_manager(&url_security_manager); |
350 negotiate_factory->set_library( | 360 negotiate_factory->set_library( |
351 new GSSAPISharedLibrary("/this/library/does/not/exist")); | 361 new GSSAPISharedLibrary("/this/library/does/not/exist")); |
352 | 362 |
353 GURL gurl("http://www.example.com"); | 363 GURL gurl("http://www.example.com"); |
354 scoped_ptr<HttpAuthHandler> generic_handler; | 364 scoped_ptr<HttpAuthHandler> generic_handler; |
355 int rv = negotiate_factory->CreateAuthHandlerFromString( | 365 int rv = negotiate_factory->CreateAuthHandlerFromString("Negotiate", |
356 "Negotiate", | 366 HttpAuth::AUTH_SERVER, |
357 HttpAuth::AUTH_SERVER, | 367 gurl, |
358 gurl, | 368 BoundNetLog(), |
359 BoundNetLog(), | 369 &generic_handler); |
360 &generic_handler); | |
361 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); | 370 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); |
362 EXPECT_TRUE(generic_handler.get() == NULL); | 371 EXPECT_TRUE(generic_handler.get() == NULL); |
363 } | 372 } |
364 #endif // defined(DLOPEN_KERBEROS) | 373 #endif // defined(DLOPEN_KERBEROS) |
365 | 374 |
366 #endif // defined(OS_POSIX) | 375 #endif // defined(OS_POSIX) |
367 | 376 |
368 } // namespace net | 377 } // namespace net |
OLD | NEW |