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" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 SetupMocks(AuthLibrary()); | 235 SetupMocks(AuthLibrary()); |
236 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 236 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
237 EXPECT_EQ(OK, CreateHandler( | 237 EXPECT_EQ(OK, CreateHandler( |
238 true, false, true, "http://alias:500", &auth_handler)); | 238 true, false, true, "http://alias:500", &auth_handler)); |
239 | 239 |
240 ASSERT_TRUE(auth_handler.get() != NULL); | 240 ASSERT_TRUE(auth_handler.get() != NULL); |
241 TestCompletionCallback callback; | 241 TestCompletionCallback callback; |
242 HttpRequestInfo request_info; | 242 HttpRequestInfo request_info; |
243 std::string token; | 243 std::string token; |
244 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( | 244 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( |
245 NULL, &request_info, callback.callback(), &token))); | 245 NULL, request_info, callback.callback(), &token))); |
246 #if defined(OS_WIN) | 246 #if defined(OS_WIN) |
247 EXPECT_EQ("HTTP/alias", auth_handler->spn()); | 247 EXPECT_EQ("HTTP/alias", auth_handler->spn()); |
248 #elif defined(OS_POSIX) | 248 #elif defined(OS_POSIX) |
249 EXPECT_EQ("HTTP@alias", auth_handler->spn()); | 249 EXPECT_EQ("HTTP@alias", auth_handler->spn()); |
250 #endif | 250 #endif |
251 } | 251 } |
252 | 252 |
253 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { | 253 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { |
254 SetupMocks(AuthLibrary()); | 254 SetupMocks(AuthLibrary()); |
255 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 255 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
256 EXPECT_EQ(OK, CreateHandler( | 256 EXPECT_EQ(OK, CreateHandler( |
257 true, true, true, "http://alias:80", &auth_handler)); | 257 true, true, true, "http://alias:80", &auth_handler)); |
258 ASSERT_TRUE(auth_handler.get() != NULL); | 258 ASSERT_TRUE(auth_handler.get() != NULL); |
259 TestCompletionCallback callback; | 259 TestCompletionCallback callback; |
260 HttpRequestInfo request_info; | 260 HttpRequestInfo request_info; |
261 std::string token; | 261 std::string token; |
262 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( | 262 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( |
263 NULL, &request_info, callback.callback(), &token))); | 263 NULL, request_info, callback.callback(), &token))); |
264 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
265 EXPECT_EQ("HTTP/alias", auth_handler->spn()); | 265 EXPECT_EQ("HTTP/alias", auth_handler->spn()); |
266 #elif defined(OS_POSIX) | 266 #elif defined(OS_POSIX) |
267 EXPECT_EQ("HTTP@alias", auth_handler->spn()); | 267 EXPECT_EQ("HTTP@alias", auth_handler->spn()); |
268 #endif | 268 #endif |
269 } | 269 } |
270 | 270 |
271 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { | 271 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { |
272 SetupMocks(AuthLibrary()); | 272 SetupMocks(AuthLibrary()); |
273 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 273 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
274 EXPECT_EQ(OK, CreateHandler( | 274 EXPECT_EQ(OK, CreateHandler( |
275 true, true, true, "http://alias:500", &auth_handler)); | 275 true, true, true, "http://alias:500", &auth_handler)); |
276 ASSERT_TRUE(auth_handler.get() != NULL); | 276 ASSERT_TRUE(auth_handler.get() != NULL); |
277 TestCompletionCallback callback; | 277 TestCompletionCallback callback; |
278 HttpRequestInfo request_info; | 278 HttpRequestInfo request_info; |
279 std::string token; | 279 std::string token; |
280 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( | 280 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( |
281 NULL, &request_info, callback.callback(), &token))); | 281 NULL, request_info, callback.callback(), &token))); |
282 #if defined(OS_WIN) | 282 #if defined(OS_WIN) |
283 EXPECT_EQ("HTTP/alias:500", auth_handler->spn()); | 283 EXPECT_EQ("HTTP/alias:500", auth_handler->spn()); |
284 #elif defined(OS_POSIX) | 284 #elif defined(OS_POSIX) |
285 EXPECT_EQ("HTTP@alias:500", auth_handler->spn()); | 285 EXPECT_EQ("HTTP@alias:500", auth_handler->spn()); |
286 #endif | 286 #endif |
287 } | 287 } |
288 | 288 |
289 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { | 289 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { |
290 SetupMocks(AuthLibrary()); | 290 SetupMocks(AuthLibrary()); |
291 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 291 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
292 EXPECT_EQ(OK, CreateHandler( | 292 EXPECT_EQ(OK, CreateHandler( |
293 false, false, true, "http://alias:500", &auth_handler)); | 293 false, false, true, "http://alias:500", &auth_handler)); |
294 ASSERT_TRUE(auth_handler.get() != NULL); | 294 ASSERT_TRUE(auth_handler.get() != NULL); |
295 TestCompletionCallback callback; | 295 TestCompletionCallback callback; |
296 HttpRequestInfo request_info; | 296 HttpRequestInfo request_info; |
297 std::string token; | 297 std::string token; |
298 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( | 298 EXPECT_EQ(OK, callback.GetResult(auth_handler->GenerateAuthToken( |
299 NULL, &request_info, callback.callback(), &token))); | 299 NULL, request_info, callback.callback(), &token))); |
300 #if defined(OS_WIN) | 300 #if defined(OS_WIN) |
301 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); | 301 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); |
302 #elif defined(OS_POSIX) | 302 #elif defined(OS_POSIX) |
303 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); | 303 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); |
304 #endif | 304 #endif |
305 } | 305 } |
306 | 306 |
307 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { | 307 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { |
308 SetupMocks(AuthLibrary()); | 308 SetupMocks(AuthLibrary()); |
309 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 309 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
310 EXPECT_EQ(OK, CreateHandler( | 310 EXPECT_EQ(OK, CreateHandler( |
311 false, false, false, "http://alias:500", &auth_handler)); | 311 false, false, false, "http://alias:500", &auth_handler)); |
312 ASSERT_TRUE(auth_handler.get() != NULL); | 312 ASSERT_TRUE(auth_handler.get() != NULL); |
313 TestCompletionCallback callback; | 313 TestCompletionCallback callback; |
314 HttpRequestInfo request_info; | 314 HttpRequestInfo request_info; |
315 std::string token; | 315 std::string token; |
316 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 316 EXPECT_EQ(ERR_IO_PENDING, |
317 NULL, &request_info, callback.callback(), &token)); | 317 auth_handler->GenerateAuthToken(NULL, request_info, |
| 318 callback.callback(), &token)); |
318 EXPECT_EQ(OK, callback.WaitForResult()); | 319 EXPECT_EQ(OK, callback.WaitForResult()); |
319 #if defined(OS_WIN) | 320 #if defined(OS_WIN) |
320 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); | 321 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); |
321 #elif defined(OS_POSIX) | 322 #elif defined(OS_POSIX) |
322 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); | 323 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); |
323 #endif | 324 #endif |
324 } | 325 } |
325 | 326 |
326 #if defined(OS_POSIX) | 327 #if defined(OS_POSIX) |
327 | 328 |
328 // This test is only for GSSAPI, as we can't use explicit credentials with | 329 // This test is only for GSSAPI, as we can't use explicit credentials with |
329 // that library. | 330 // that library. |
330 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) { | 331 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) { |
331 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server | 332 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server |
332 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 333 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
333 EXPECT_EQ(OK, CreateHandler( | 334 EXPECT_EQ(OK, CreateHandler( |
334 false, false, false, "http://alias:500", &auth_handler)); | 335 false, false, false, "http://alias:500", &auth_handler)); |
335 ASSERT_TRUE(auth_handler.get() != NULL); | 336 ASSERT_TRUE(auth_handler.get() != NULL); |
336 TestCompletionCallback callback; | 337 TestCompletionCallback callback; |
337 HttpRequestInfo request_info; | 338 HttpRequestInfo request_info; |
338 std::string token; | 339 std::string token; |
339 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 340 EXPECT_EQ(ERR_IO_PENDING, |
340 NULL, &request_info, callback.callback(), &token)); | 341 auth_handler->GenerateAuthToken(NULL, request_info, |
| 342 callback.callback(), &token)); |
341 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); | 343 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); |
342 } | 344 } |
343 | 345 |
344 // This test is only for GSSAPI, as we can't use explicit credentials with | 346 // This test is only for GSSAPI, as we can't use explicit credentials with |
345 // that library. | 347 // that library. |
346 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) { | 348 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) { |
347 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials | 349 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials |
348 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; | 350 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; |
349 EXPECT_EQ(OK, CreateHandler( | 351 EXPECT_EQ(OK, CreateHandler( |
350 false, false, false, "http://alias:500", &auth_handler)); | 352 false, false, false, "http://alias:500", &auth_handler)); |
351 ASSERT_TRUE(auth_handler.get() != NULL); | 353 ASSERT_TRUE(auth_handler.get() != NULL); |
352 TestCompletionCallback callback; | 354 TestCompletionCallback callback; |
353 HttpRequestInfo request_info; | 355 HttpRequestInfo request_info; |
354 std::string token; | 356 std::string token; |
355 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 357 EXPECT_EQ(ERR_IO_PENDING, |
356 NULL, &request_info, callback.callback(), &token)); | 358 auth_handler->GenerateAuthToken(NULL, request_info, |
| 359 callback.callback(), &token)); |
357 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); | 360 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); |
358 } | 361 } |
359 | 362 |
360 #if defined(DLOPEN_KERBEROS) | 363 #if defined(DLOPEN_KERBEROS) |
361 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) { | 364 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) { |
362 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); | 365 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); |
363 MockAllowURLSecurityManager url_security_manager; | 366 MockAllowURLSecurityManager url_security_manager; |
364 scoped_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory( | 367 scoped_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory( |
365 new HttpAuthHandlerNegotiate::Factory()); | 368 new HttpAuthHandlerNegotiate::Factory()); |
366 negotiate_factory->set_host_resolver(host_resolver.get()); | 369 negotiate_factory->set_host_resolver(host_resolver.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
377 BoundNetLog(), | 380 BoundNetLog(), |
378 &generic_handler); | 381 &generic_handler); |
379 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); | 382 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); |
380 EXPECT_TRUE(generic_handler.get() == NULL); | 383 EXPECT_TRUE(generic_handler.get() == NULL); |
381 } | 384 } |
382 #endif // defined(DLOPEN_KERBEROS) | 385 #endif // defined(DLOPEN_KERBEROS) |
383 | 386 |
384 #endif // defined(OS_POSIX) | 387 #endif // defined(OS_POSIX) |
385 | 388 |
386 } // namespace net | 389 } // namespace net |
OLD | NEW |