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

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

Issue 1414313002: Allow dynamic updating of authentication policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missing Chromeos includes Created 5 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 //----------------------------------------------------------------------------- 634 //-----------------------------------------------------------------------------
635 635
636 // Helper functions for validating that AuthChallengeInfo's are correctly 636 // Helper functions for validating that AuthChallengeInfo's are correctly
637 // configured for common cases. 637 // configured for common cases.
638 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { 638 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) {
639 if (!auth_challenge) 639 if (!auth_challenge)
640 return false; 640 return false;
641 EXPECT_FALSE(auth_challenge->is_proxy); 641 EXPECT_FALSE(auth_challenge->is_proxy);
642 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); 642 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString());
643 EXPECT_EQ("MyRealm1", auth_challenge->realm); 643 EXPECT_EQ("MyRealm1", auth_challenge->realm);
644 EXPECT_EQ("basic", auth_challenge->scheme); 644 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme);
645 return true; 645 return true;
646 } 646 }
647 647
648 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { 648 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) {
649 if (!auth_challenge) 649 if (!auth_challenge)
650 return false; 650 return false;
651 EXPECT_TRUE(auth_challenge->is_proxy); 651 EXPECT_TRUE(auth_challenge->is_proxy);
652 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); 652 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString());
653 EXPECT_EQ("MyRealm1", auth_challenge->realm); 653 EXPECT_EQ("MyRealm1", auth_challenge->realm);
654 EXPECT_EQ("basic", auth_challenge->scheme); 654 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme);
655 return true; 655 return true;
656 } 656 }
657 657
658 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { 658 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) {
659 if (!auth_challenge) 659 if (!auth_challenge)
660 return false; 660 return false;
661 EXPECT_FALSE(auth_challenge->is_proxy); 661 EXPECT_FALSE(auth_challenge->is_proxy);
662 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); 662 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString());
663 EXPECT_EQ("digestive", auth_challenge->realm); 663 EXPECT_EQ("digestive", auth_challenge->realm);
664 EXPECT_EQ("digest", auth_challenge->scheme); 664 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme);
665 return true; 665 return true;
666 } 666 }
667 667
668 #if defined(NTLM_PORTABLE) 668 #if defined(NTLM_PORTABLE)
669 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { 669 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) {
670 if (!auth_challenge) 670 if (!auth_challenge)
671 return false; 671 return false;
672 EXPECT_FALSE(auth_challenge->is_proxy); 672 EXPECT_FALSE(auth_challenge->is_proxy);
673 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); 673 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString());
674 EXPECT_EQ(std::string(), auth_challenge->realm); 674 EXPECT_EQ(std::string(), auth_challenge->realm);
675 EXPECT_EQ("ntlm", auth_challenge->scheme); 675 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme);
676 return true; 676 return true;
677 } 677 }
678 #endif // defined(NTLM_PORTABLE) 678 #endif // defined(NTLM_PORTABLE)
679 679
680 } // namespace 680 } // namespace
681 681
682 TEST_P(HttpNetworkTransactionTest, Basic) { 682 TEST_P(HttpNetworkTransactionTest, Basic) {
683 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 683 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
684 scoped_ptr<HttpTransaction> trans( 684 scoped_ptr<HttpTransaction> trans(
685 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 685 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
(...skipping 5816 matching lines...) Expand 10 before | Expand all | Expand 10 after
6502 rv = callback1.WaitForResult(); 6502 rv = callback1.WaitForResult();
6503 EXPECT_EQ(OK, rv); 6503 EXPECT_EQ(OK, rv);
6504 6504
6505 const HttpResponseInfo* response = trans->GetResponseInfo(); 6505 const HttpResponseInfo* response = trans->GetResponseInfo();
6506 ASSERT_TRUE(response != NULL); 6506 ASSERT_TRUE(response != NULL);
6507 ASSERT_TRUE(response->auth_challenge.get()); 6507 ASSERT_TRUE(response->auth_challenge.get());
6508 EXPECT_FALSE(response->auth_challenge->is_proxy); 6508 EXPECT_FALSE(response->auth_challenge->is_proxy);
6509 EXPECT_EQ("www.example.org:80", 6509 EXPECT_EQ("www.example.org:80",
6510 response->auth_challenge->challenger.ToString()); 6510 response->auth_challenge->challenger.ToString());
6511 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); 6511 EXPECT_EQ("MyRealm2", response->auth_challenge->realm);
6512 EXPECT_EQ("basic", response->auth_challenge->scheme); 6512 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme);
6513 6513
6514 TestCompletionCallback callback2; 6514 TestCompletionCallback callback2;
6515 6515
6516 rv = trans->RestartWithAuth( 6516 rv = trans->RestartWithAuth(
6517 AuthCredentials(kFoo2, kBar2), callback2.callback()); 6517 AuthCredentials(kFoo2, kBar2), callback2.callback());
6518 EXPECT_EQ(ERR_IO_PENDING, rv); 6518 EXPECT_EQ(ERR_IO_PENDING, rv);
6519 6519
6520 rv = callback2.WaitForResult(); 6520 rv = callback2.WaitForResult();
6521 EXPECT_EQ(OK, rv); 6521 EXPECT_EQ(OK, rv);
6522 6522
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after
9342 EXPECT_EQ(ERR_IO_PENDING, rv); 9342 EXPECT_EQ(ERR_IO_PENDING, rv);
9343 rv = callback1.WaitForResult(); 9343 rv = callback1.WaitForResult();
9344 EXPECT_EQ(OK, rv); 9344 EXPECT_EQ(OK, rv);
9345 const HttpResponseInfo* response = trans->GetResponseInfo(); 9345 const HttpResponseInfo* response = trans->GetResponseInfo();
9346 ASSERT_TRUE(response != NULL); 9346 ASSERT_TRUE(response != NULL);
9347 const AuthChallengeInfo* challenge = response->auth_challenge.get(); 9347 const AuthChallengeInfo* challenge = response->auth_challenge.get();
9348 ASSERT_FALSE(challenge == NULL); 9348 ASSERT_FALSE(challenge == NULL);
9349 EXPECT_FALSE(challenge->is_proxy); 9349 EXPECT_FALSE(challenge->is_proxy);
9350 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9350 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9351 EXPECT_EQ("first_realm", challenge->realm); 9351 EXPECT_EQ("first_realm", challenge->realm);
9352 EXPECT_EQ("basic", challenge->scheme); 9352 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9353 9353
9354 // Issue the second request with an incorrect password. There should be a 9354 // Issue the second request with an incorrect password. There should be a
9355 // password prompt for second_realm waiting to be filled in after the 9355 // password prompt for second_realm waiting to be filled in after the
9356 // transaction completes. 9356 // transaction completes.
9357 TestCompletionCallback callback2; 9357 TestCompletionCallback callback2;
9358 rv = trans->RestartWithAuth( 9358 rv = trans->RestartWithAuth(
9359 AuthCredentials(kFirst, kBaz), callback2.callback()); 9359 AuthCredentials(kFirst, kBaz), callback2.callback());
9360 EXPECT_EQ(ERR_IO_PENDING, rv); 9360 EXPECT_EQ(ERR_IO_PENDING, rv);
9361 rv = callback2.WaitForResult(); 9361 rv = callback2.WaitForResult();
9362 EXPECT_EQ(OK, rv); 9362 EXPECT_EQ(OK, rv);
9363 response = trans->GetResponseInfo(); 9363 response = trans->GetResponseInfo();
9364 ASSERT_TRUE(response != NULL); 9364 ASSERT_TRUE(response != NULL);
9365 challenge = response->auth_challenge.get(); 9365 challenge = response->auth_challenge.get();
9366 ASSERT_FALSE(challenge == NULL); 9366 ASSERT_FALSE(challenge == NULL);
9367 EXPECT_FALSE(challenge->is_proxy); 9367 EXPECT_FALSE(challenge->is_proxy);
9368 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9368 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9369 EXPECT_EQ("second_realm", challenge->realm); 9369 EXPECT_EQ("second_realm", challenge->realm);
9370 EXPECT_EQ("basic", challenge->scheme); 9370 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9371 9371
9372 // Issue the third request with another incorrect password. There should be 9372 // Issue the third request with another incorrect password. There should be
9373 // a password prompt for first_realm waiting to be filled in. If the password 9373 // a password prompt for first_realm waiting to be filled in. If the password
9374 // prompt is not present, it indicates that the HttpAuthCacheEntry for 9374 // prompt is not present, it indicates that the HttpAuthCacheEntry for
9375 // first_realm was not correctly removed. 9375 // first_realm was not correctly removed.
9376 TestCompletionCallback callback3; 9376 TestCompletionCallback callback3;
9377 rv = trans->RestartWithAuth( 9377 rv = trans->RestartWithAuth(
9378 AuthCredentials(kSecond, kFou), callback3.callback()); 9378 AuthCredentials(kSecond, kFou), callback3.callback());
9379 EXPECT_EQ(ERR_IO_PENDING, rv); 9379 EXPECT_EQ(ERR_IO_PENDING, rv);
9380 rv = callback3.WaitForResult(); 9380 rv = callback3.WaitForResult();
9381 EXPECT_EQ(OK, rv); 9381 EXPECT_EQ(OK, rv);
9382 response = trans->GetResponseInfo(); 9382 response = trans->GetResponseInfo();
9383 ASSERT_TRUE(response != NULL); 9383 ASSERT_TRUE(response != NULL);
9384 challenge = response->auth_challenge.get(); 9384 challenge = response->auth_challenge.get();
9385 ASSERT_FALSE(challenge == NULL); 9385 ASSERT_FALSE(challenge == NULL);
9386 EXPECT_FALSE(challenge->is_proxy); 9386 EXPECT_FALSE(challenge->is_proxy);
9387 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9387 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9388 EXPECT_EQ("first_realm", challenge->realm); 9388 EXPECT_EQ("first_realm", challenge->realm);
9389 EXPECT_EQ("basic", challenge->scheme); 9389 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9390 9390
9391 // Issue the fourth request with the correct password and username. 9391 // Issue the fourth request with the correct password and username.
9392 TestCompletionCallback callback4; 9392 TestCompletionCallback callback4;
9393 rv = trans->RestartWithAuth( 9393 rv = trans->RestartWithAuth(
9394 AuthCredentials(kFirst, kBar), callback4.callback()); 9394 AuthCredentials(kFirst, kBar), callback4.callback());
9395 EXPECT_EQ(ERR_IO_PENDING, rv); 9395 EXPECT_EQ(ERR_IO_PENDING, rv);
9396 rv = callback4.WaitForResult(); 9396 rv = callback4.WaitForResult();
9397 EXPECT_EQ(OK, rv); 9397 EXPECT_EQ(OK, rv);
9398 response = trans->GetResponseInfo(); 9398 response = trans->GetResponseInfo();
9399 ASSERT_TRUE(response != NULL); 9399 ASSERT_TRUE(response != NULL);
(...skipping 5967 matching lines...) Expand 10 before | Expand all | Expand 10 after
15367 std::string response_data; 15367 std::string response_data;
15368 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 15368 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data));
15369 15369
15370 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), 15370 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)),
15371 trans->GetTotalSentBytes()); 15371 trans->GetTotalSentBytes());
15372 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), 15372 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)),
15373 trans->GetTotalReceivedBytes()); 15373 trans->GetTotalReceivedBytes());
15374 } 15374 }
15375 15375
15376 } // namespace net 15376 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698