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 <string> | 5 #include <string> |
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 new HttpAuthHandlerDigest::Factory()); | 53 new HttpAuthHandlerDigest::Factory()); |
54 HttpAuthHandlerDigest::NonceGenerator* nonce_generator = | 54 HttpAuthHandlerDigest::NonceGenerator* nonce_generator = |
55 new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce"); | 55 new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce"); |
56 factory->set_nonce_generator(nonce_generator); | 56 factory->set_nonce_generator(nonce_generator); |
57 std::unique_ptr<HttpAuthHandler> handler; | 57 std::unique_ptr<HttpAuthHandler> handler; |
58 | 58 |
59 // Create a handler for a particular challenge. | 59 // Create a handler for a particular challenge. |
60 SSLInfo null_ssl_info; | 60 SSLInfo null_ssl_info; |
61 GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name); | 61 GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name); |
62 int rv_create = factory->CreateAuthHandlerFromString( | 62 int rv_create = factory->CreateAuthHandlerFromString( |
63 challenge, target, null_ssl_info, url_origin.GetOrigin(), BoundNetLog(), | 63 challenge, target, null_ssl_info, url_origin.GetOrigin(), |
64 &handler); | 64 NetLogWithSource(), &handler); |
65 if (rv_create != OK || handler.get() == NULL) { | 65 if (rv_create != OK || handler.get() == NULL) { |
66 ADD_FAILURE() << "Unable to create auth handler."; | 66 ADD_FAILURE() << "Unable to create auth handler."; |
67 return false; | 67 return false; |
68 } | 68 } |
69 | 69 |
70 // Create a token in response to the challenge. | 70 // Create a token in response to the challenge. |
71 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always | 71 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always |
72 // completes synchronously. That's why this test can get away with a | 72 // completes synchronously. That's why this test can get away with a |
73 // TestCompletionCallback without an IO thread. | 73 // TestCompletionCallback without an IO thread. |
74 TestCompletionCallback callback; | 74 TestCompletionCallback callback; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 }; | 355 }; |
356 | 356 |
357 GURL origin("http://www.example.com"); | 357 GURL origin("http://www.example.com"); |
358 std::unique_ptr<HttpAuthHandlerDigest::Factory> factory( | 358 std::unique_ptr<HttpAuthHandlerDigest::Factory> factory( |
359 new HttpAuthHandlerDigest::Factory()); | 359 new HttpAuthHandlerDigest::Factory()); |
360 for (size_t i = 0; i < arraysize(tests); ++i) { | 360 for (size_t i = 0; i < arraysize(tests); ++i) { |
361 SSLInfo null_ssl_info; | 361 SSLInfo null_ssl_info; |
362 std::unique_ptr<HttpAuthHandler> handler; | 362 std::unique_ptr<HttpAuthHandler> handler; |
363 int rv = factory->CreateAuthHandlerFromString( | 363 int rv = factory->CreateAuthHandlerFromString( |
364 tests[i].challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, | 364 tests[i].challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, |
365 BoundNetLog(), &handler); | 365 NetLogWithSource(), &handler); |
366 if (tests[i].parsed_success) { | 366 if (tests[i].parsed_success) { |
367 EXPECT_THAT(rv, IsOk()); | 367 EXPECT_THAT(rv, IsOk()); |
368 } else { | 368 } else { |
369 EXPECT_NE(OK, rv); | 369 EXPECT_NE(OK, rv); |
370 EXPECT_TRUE(handler.get() == NULL); | 370 EXPECT_TRUE(handler.get() == NULL); |
371 continue; | 371 continue; |
372 } | 372 } |
373 ASSERT_TRUE(handler.get() != NULL); | 373 ASSERT_TRUE(handler.get() != NULL); |
374 HttpAuthHandlerDigest* digest = | 374 HttpAuthHandlerDigest* digest = |
375 static_cast<HttpAuthHandlerDigest*>(handler.get()); | 375 static_cast<HttpAuthHandlerDigest*>(handler.get()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 519 } |
520 }; | 520 }; |
521 GURL origin("http://www.example.com"); | 521 GURL origin("http://www.example.com"); |
522 std::unique_ptr<HttpAuthHandlerDigest::Factory> factory( | 522 std::unique_ptr<HttpAuthHandlerDigest::Factory> factory( |
523 new HttpAuthHandlerDigest::Factory()); | 523 new HttpAuthHandlerDigest::Factory()); |
524 for (size_t i = 0; i < arraysize(tests); ++i) { | 524 for (size_t i = 0; i < arraysize(tests); ++i) { |
525 SSLInfo null_ssl_info; | 525 SSLInfo null_ssl_info; |
526 std::unique_ptr<HttpAuthHandler> handler; | 526 std::unique_ptr<HttpAuthHandler> handler; |
527 int rv = factory->CreateAuthHandlerFromString( | 527 int rv = factory->CreateAuthHandlerFromString( |
528 tests[i].challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, | 528 tests[i].challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, |
529 BoundNetLog(), &handler); | 529 NetLogWithSource(), &handler); |
530 EXPECT_THAT(rv, IsOk()); | 530 EXPECT_THAT(rv, IsOk()); |
531 ASSERT_TRUE(handler != NULL); | 531 ASSERT_TRUE(handler != NULL); |
532 | 532 |
533 HttpAuthHandlerDigest* digest = | 533 HttpAuthHandlerDigest* digest = |
534 static_cast<HttpAuthHandlerDigest*>(handler.get()); | 534 static_cast<HttpAuthHandlerDigest*>(handler.get()); |
535 std::string creds = | 535 std::string creds = |
536 digest->AssembleCredentials(tests[i].req_method, | 536 digest->AssembleCredentials(tests[i].req_method, |
537 tests[i].req_path, | 537 tests[i].req_path, |
538 AuthCredentials( | 538 AuthCredentials( |
539 base::ASCIIToUTF16(tests[i].username), | 539 base::ASCIIToUTF16(tests[i].username), |
540 base::ASCIIToUTF16(tests[i].password)), | 540 base::ASCIIToUTF16(tests[i].password)), |
541 tests[i].cnonce, | 541 tests[i].cnonce, |
542 tests[i].nonce_count); | 542 tests[i].nonce_count); |
543 | 543 |
544 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); | 544 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); |
545 } | 545 } |
546 } | 546 } |
547 | 547 |
548 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { | 548 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { |
549 std::unique_ptr<HttpAuthHandlerDigest::Factory> factory( | 549 std::unique_ptr<HttpAuthHandlerDigest::Factory> factory( |
550 new HttpAuthHandlerDigest::Factory()); | 550 new HttpAuthHandlerDigest::Factory()); |
551 std::unique_ptr<HttpAuthHandler> handler; | 551 std::unique_ptr<HttpAuthHandler> handler; |
552 std::string default_challenge = | 552 std::string default_challenge = |
553 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; | 553 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; |
554 GURL origin("intranet.google.com"); | 554 GURL origin("intranet.google.com"); |
555 SSLInfo null_ssl_info; | 555 SSLInfo null_ssl_info; |
556 int rv = factory->CreateAuthHandlerFromString( | 556 int rv = factory->CreateAuthHandlerFromString( |
557 default_challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, | 557 default_challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, |
558 BoundNetLog(), &handler); | 558 NetLogWithSource(), &handler); |
559 EXPECT_THAT(rv, IsOk()); | 559 EXPECT_THAT(rv, IsOk()); |
560 ASSERT_TRUE(handler.get() != NULL); | 560 ASSERT_TRUE(handler.get() != NULL); |
561 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), | 561 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), |
562 default_challenge.end()); | 562 default_challenge.end()); |
563 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 563 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
564 handler->HandleAnotherChallenge(&tok_default)); | 564 handler->HandleAnotherChallenge(&tok_default)); |
565 | 565 |
566 std::string stale_challenge = default_challenge + ", stale=true"; | 566 std::string stale_challenge = default_challenge + ", stale=true"; |
567 HttpAuthChallengeTokenizer tok_stale(stale_challenge.begin(), | 567 HttpAuthChallengeTokenizer tok_stale(stale_challenge.begin(), |
568 stale_challenge.end()); | 568 stale_challenge.end()); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 694 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
695 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 695 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
696 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " | 696 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
697 "opaque=\"opaque text\", " | 697 "opaque=\"opaque text\", " |
698 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", | 698 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
699 auth_token); | 699 auth_token); |
700 } | 700 } |
701 | 701 |
702 | 702 |
703 } // namespace net | 703 } // namespace net |
OLD | NEW |