Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: net/http/http_auth_handler_digest_unittest.cc

Issue 1151843002: DO NOT LAND Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/base/test_completion_callback.h" 11 #include "net/base/test_completion_callback.h"
12 #include "net/http/http_auth_challenge_tokenizer.h" 12 #include "net/http/http_auth_challenge_tokenizer.h"
13 #include "net/http/http_auth_handler_digest.h" 13 #include "net/http/http_auth_handler_digest.h"
14 #include "net/http/http_request_info.h" 14 #include "net/http/http_request_info.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/origin.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 namespace { 20 namespace {
20 21
21 const char* const kSimpleChallenge = 22 const char* const kSimpleChallenge =
22 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; 23 "Digest realm=\"Oblivion\", nonce=\"nonce-value\"";
23 24
24 // RespondToChallenge creates an HttpAuthHandlerDigest for the specified 25 // RespondToChallenge creates an HttpAuthHandlerDigest for the specified
25 // |challenge|, and generates a response to the challenge which is returned in 26 // |challenge|, and generates a response to the challenge which is returned in
(...skipping 20 matching lines...) Expand all
46 47
47 token->clear(); 48 token->clear();
48 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( 49 scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
49 new HttpAuthHandlerDigest::Factory()); 50 new HttpAuthHandlerDigest::Factory());
50 HttpAuthHandlerDigest::NonceGenerator* nonce_generator = 51 HttpAuthHandlerDigest::NonceGenerator* nonce_generator =
51 new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce"); 52 new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce");
52 factory->set_nonce_generator(nonce_generator); 53 factory->set_nonce_generator(nonce_generator);
53 scoped_ptr<HttpAuthHandler> handler; 54 scoped_ptr<HttpAuthHandler> handler;
54 55
55 // Create a handler for a particular challenge. 56 // Create a handler for a particular challenge.
56 GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name); 57 url::Origin url_origin(target == HttpAuth::AUTH_SERVER ? request_url
58 : proxy_name);
57 int rv_create = factory->CreateAuthHandlerFromString( 59 int rv_create = factory->CreateAuthHandlerFromString(
58 challenge, target, url_origin.GetOrigin(), BoundNetLog(), &handler); 60 challenge, target, url_origin, BoundNetLog(), &handler);
59 if (rv_create != OK || handler.get() == NULL) { 61 if (rv_create != OK || handler.get() == NULL) {
60 ADD_FAILURE() << "Unable to create auth handler."; 62 ADD_FAILURE() << "Unable to create auth handler.";
61 return false; 63 return false;
62 } 64 }
63 65
64 // Create a token in response to the challenge. 66 // Create a token in response to the challenge.
65 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always 67 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always
66 // completes synchronously. That's why this test can get away with a 68 // completes synchronously. That's why this test can get away with a
67 // TestCompletionCallback without an IO thread. 69 // TestCompletionCallback without an IO thread.
68 TestCompletionCallback callback; 70 TestCompletionCallback callback;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 "", 343 "",
342 "", 344 "",
343 "", 345 "",
344 "", 346 "",
345 false, 347 false,
346 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, 348 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED,
347 HttpAuthHandlerDigest::QOP_UNSPECIFIED 349 HttpAuthHandlerDigest::QOP_UNSPECIFIED
348 }, 350 },
349 }; 351 };
350 352
351 GURL origin("http://www.example.com"); 353 url::Origin origin("http://www.example.com");
352 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( 354 scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
353 new HttpAuthHandlerDigest::Factory()); 355 new HttpAuthHandlerDigest::Factory());
354 for (size_t i = 0; i < arraysize(tests); ++i) { 356 for (size_t i = 0; i < arraysize(tests); ++i) {
355 scoped_ptr<HttpAuthHandler> handler; 357 scoped_ptr<HttpAuthHandler> handler;
356 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge, 358 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge,
357 HttpAuth::AUTH_SERVER, 359 HttpAuth::AUTH_SERVER,
358 origin, 360 origin,
359 BoundNetLog(), 361 BoundNetLog(),
360 &handler); 362 &handler);
361 if (tests[i].parsed_success) { 363 if (tests[i].parsed_success) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 "15c07961ed8575c4", // cnonce 508 "15c07961ed8575c4", // cnonce
507 1, // nc 509 1, // nc
508 510
509 // Authorization 511 // Authorization
510 "Digest username=\"USER\", realm=\"Baztastic\", " 512 "Digest username=\"USER\", realm=\"Baztastic\", "
511 "nonce=\"AAAAAAAA\", uri=\"/\", algorithm=MD5-sess, " 513 "nonce=\"AAAAAAAA\", uri=\"/\", algorithm=MD5-sess, "
512 "response=\"cbc1139821ee7192069580570c541a03\", " 514 "response=\"cbc1139821ee7192069580570c541a03\", "
513 "qop=auth, nc=00000001, cnonce=\"15c07961ed8575c4\"" 515 "qop=auth, nc=00000001, cnonce=\"15c07961ed8575c4\""
514 } 516 }
515 }; 517 };
516 GURL origin("http://www.example.com"); 518 url::Origin origin("http://www.example.com");
517 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( 519 scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
518 new HttpAuthHandlerDigest::Factory()); 520 new HttpAuthHandlerDigest::Factory());
519 for (size_t i = 0; i < arraysize(tests); ++i) { 521 for (size_t i = 0; i < arraysize(tests); ++i) {
520 scoped_ptr<HttpAuthHandler> handler; 522 scoped_ptr<HttpAuthHandler> handler;
521 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge, 523 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge,
522 HttpAuth::AUTH_SERVER, 524 HttpAuth::AUTH_SERVER,
523 origin, 525 origin,
524 BoundNetLog(), 526 BoundNetLog(),
525 &handler); 527 &handler);
526 EXPECT_EQ(OK, rv); 528 EXPECT_EQ(OK, rv);
(...skipping 13 matching lines...) Expand all
540 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); 542 EXPECT_STREQ(tests[i].expected_creds, creds.c_str());
541 } 543 }
542 } 544 }
543 545
544 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { 546 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) {
545 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( 547 scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
546 new HttpAuthHandlerDigest::Factory()); 548 new HttpAuthHandlerDigest::Factory());
547 scoped_ptr<HttpAuthHandler> handler; 549 scoped_ptr<HttpAuthHandler> handler;
548 std::string default_challenge = 550 std::string default_challenge =
549 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; 551 "Digest realm=\"Oblivion\", nonce=\"nonce-value\"";
550 GURL origin("intranet.google.com"); 552 url::Origin origin("http://intranet.google.com");
551 int rv = factory->CreateAuthHandlerFromString( 553 int rv = factory->CreateAuthHandlerFromString(
552 default_challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), 554 default_challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(),
553 &handler); 555 &handler);
554 EXPECT_EQ(OK, rv); 556 EXPECT_EQ(OK, rv);
555 ASSERT_TRUE(handler.get() != NULL); 557 ASSERT_TRUE(handler.get() != NULL);
556 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), 558 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(),
557 default_challenge.end()); 559 default_challenge.end());
558 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, 560 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
559 handler->HandleAnotherChallenge(&tok_default)); 561 handler->HandleAnotherChallenge(&tok_default));
560 562
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " 691 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", "
690 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " 692 "nonce=\"nonce-value\", uri=\"/path/to/resource\", "
691 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " 693 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", "
692 "opaque=\"opaque text\", " 694 "opaque=\"opaque text\", "
693 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", 695 "qop=auth, nc=00000001, cnonce=\"client_nonce\"",
694 auth_token); 696 auth_token);
695 } 697 }
696 698
697 699
698 } // namespace net 700 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698