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

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: Move //base/prefs references out of net - part 1. 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 26 matching lines...) Expand all
37 #include "net/base/test_data_directory.h" 37 #include "net/base/test_data_directory.h"
38 #include "net/base/upload_bytes_element_reader.h" 38 #include "net/base/upload_bytes_element_reader.h"
39 #include "net/base/upload_file_element_reader.h" 39 #include "net/base/upload_file_element_reader.h"
40 #include "net/cert/mock_cert_verifier.h" 40 #include "net/cert/mock_cert_verifier.h"
41 #include "net/dns/host_cache.h" 41 #include "net/dns/host_cache.h"
42 #include "net/dns/mock_host_resolver.h" 42 #include "net/dns/mock_host_resolver.h"
43 #include "net/http/http_auth_challenge_tokenizer.h" 43 #include "net/http/http_auth_challenge_tokenizer.h"
44 #include "net/http/http_auth_handler_digest.h" 44 #include "net/http/http_auth_handler_digest.h"
45 #include "net/http/http_auth_handler_mock.h" 45 #include "net/http/http_auth_handler_mock.h"
46 #include "net/http/http_auth_handler_ntlm.h" 46 #include "net/http/http_auth_handler_ntlm.h"
47 #include "net/http/http_auth_scheme.h"
47 #include "net/http/http_basic_state.h" 48 #include "net/http/http_basic_state.h"
48 #include "net/http/http_basic_stream.h" 49 #include "net/http/http_basic_stream.h"
49 #include "net/http/http_network_session.h" 50 #include "net/http/http_network_session.h"
50 #include "net/http/http_network_session_peer.h" 51 #include "net/http/http_network_session_peer.h"
51 #include "net/http/http_request_headers.h" 52 #include "net/http/http_request_headers.h"
52 #include "net/http/http_server_properties_impl.h" 53 #include "net/http/http_server_properties_impl.h"
53 #include "net/http/http_stream.h" 54 #include "net/http/http_stream.h"
54 #include "net/http/http_stream_factory.h" 55 #include "net/http/http_stream_factory.h"
55 #include "net/http/http_stream_parser.h" 56 #include "net/http/http_stream_parser.h"
56 #include "net/http/http_transaction_test_util.h" 57 #include "net/http/http_transaction_test_util.h"
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 //----------------------------------------------------------------------------- 660 //-----------------------------------------------------------------------------
660 661
661 // Helper functions for validating that AuthChallengeInfo's are correctly 662 // Helper functions for validating that AuthChallengeInfo's are correctly
662 // configured for common cases. 663 // configured for common cases.
663 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { 664 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) {
664 if (!auth_challenge) 665 if (!auth_challenge)
665 return false; 666 return false;
666 EXPECT_FALSE(auth_challenge->is_proxy); 667 EXPECT_FALSE(auth_challenge->is_proxy);
667 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); 668 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString());
668 EXPECT_EQ("MyRealm1", auth_challenge->realm); 669 EXPECT_EQ("MyRealm1", auth_challenge->realm);
669 EXPECT_EQ("basic", auth_challenge->scheme); 670 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme);
670 return true; 671 return true;
671 } 672 }
672 673
673 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { 674 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) {
674 if (!auth_challenge) 675 if (!auth_challenge)
675 return false; 676 return false;
676 EXPECT_TRUE(auth_challenge->is_proxy); 677 EXPECT_TRUE(auth_challenge->is_proxy);
677 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); 678 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString());
678 EXPECT_EQ("MyRealm1", auth_challenge->realm); 679 EXPECT_EQ("MyRealm1", auth_challenge->realm);
679 EXPECT_EQ("basic", auth_challenge->scheme); 680 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme);
680 return true; 681 return true;
681 } 682 }
682 683
683 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { 684 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) {
684 if (!auth_challenge) 685 if (!auth_challenge)
685 return false; 686 return false;
686 EXPECT_FALSE(auth_challenge->is_proxy); 687 EXPECT_FALSE(auth_challenge->is_proxy);
687 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); 688 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString());
688 EXPECT_EQ("digestive", auth_challenge->realm); 689 EXPECT_EQ("digestive", auth_challenge->realm);
689 EXPECT_EQ("digest", auth_challenge->scheme); 690 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme);
690 return true; 691 return true;
691 } 692 }
692 693
693 #if defined(NTLM_PORTABLE) 694 #if defined(NTLM_PORTABLE)
694 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { 695 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) {
695 if (!auth_challenge) 696 if (!auth_challenge)
696 return false; 697 return false;
697 EXPECT_FALSE(auth_challenge->is_proxy); 698 EXPECT_FALSE(auth_challenge->is_proxy);
698 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); 699 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString());
699 EXPECT_EQ(std::string(), auth_challenge->realm); 700 EXPECT_EQ(std::string(), auth_challenge->realm);
700 EXPECT_EQ("ntlm", auth_challenge->scheme); 701 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme);
701 return true; 702 return true;
702 } 703 }
703 #endif // defined(NTLM_PORTABLE) 704 #endif // defined(NTLM_PORTABLE)
704 705
705 } // namespace 706 } // namespace
706 707
707 TEST_P(HttpNetworkTransactionTest, Basic) { 708 TEST_P(HttpNetworkTransactionTest, Basic) {
708 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 709 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
709 scoped_ptr<HttpTransaction> trans( 710 scoped_ptr<HttpTransaction> trans(
710 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 711 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
(...skipping 5804 matching lines...) Expand 10 before | Expand all | Expand 10 after
6515 rv = callback1.WaitForResult(); 6516 rv = callback1.WaitForResult();
6516 EXPECT_EQ(OK, rv); 6517 EXPECT_EQ(OK, rv);
6517 6518
6518 const HttpResponseInfo* response = trans->GetResponseInfo(); 6519 const HttpResponseInfo* response = trans->GetResponseInfo();
6519 ASSERT_TRUE(response != NULL); 6520 ASSERT_TRUE(response != NULL);
6520 ASSERT_TRUE(response->auth_challenge.get()); 6521 ASSERT_TRUE(response->auth_challenge.get());
6521 EXPECT_FALSE(response->auth_challenge->is_proxy); 6522 EXPECT_FALSE(response->auth_challenge->is_proxy);
6522 EXPECT_EQ("www.example.org:80", 6523 EXPECT_EQ("www.example.org:80",
6523 response->auth_challenge->challenger.ToString()); 6524 response->auth_challenge->challenger.ToString());
6524 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); 6525 EXPECT_EQ("MyRealm2", response->auth_challenge->realm);
6525 EXPECT_EQ("basic", response->auth_challenge->scheme); 6526 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme);
6526 6527
6527 TestCompletionCallback callback2; 6528 TestCompletionCallback callback2;
6528 6529
6529 rv = trans->RestartWithAuth( 6530 rv = trans->RestartWithAuth(
6530 AuthCredentials(kFoo2, kBar2), callback2.callback()); 6531 AuthCredentials(kFoo2, kBar2), callback2.callback());
6531 EXPECT_EQ(ERR_IO_PENDING, rv); 6532 EXPECT_EQ(ERR_IO_PENDING, rv);
6532 6533
6533 rv = callback2.WaitForResult(); 6534 rv = callback2.WaitForResult();
6534 EXPECT_EQ(OK, rv); 6535 EXPECT_EQ(OK, rv);
6535 6536
(...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after
9345 EXPECT_EQ(ERR_IO_PENDING, rv); 9346 EXPECT_EQ(ERR_IO_PENDING, rv);
9346 rv = callback1.WaitForResult(); 9347 rv = callback1.WaitForResult();
9347 EXPECT_EQ(OK, rv); 9348 EXPECT_EQ(OK, rv);
9348 const HttpResponseInfo* response = trans->GetResponseInfo(); 9349 const HttpResponseInfo* response = trans->GetResponseInfo();
9349 ASSERT_TRUE(response != NULL); 9350 ASSERT_TRUE(response != NULL);
9350 const AuthChallengeInfo* challenge = response->auth_challenge.get(); 9351 const AuthChallengeInfo* challenge = response->auth_challenge.get();
9351 ASSERT_FALSE(challenge == NULL); 9352 ASSERT_FALSE(challenge == NULL);
9352 EXPECT_FALSE(challenge->is_proxy); 9353 EXPECT_FALSE(challenge->is_proxy);
9353 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9354 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9354 EXPECT_EQ("first_realm", challenge->realm); 9355 EXPECT_EQ("first_realm", challenge->realm);
9355 EXPECT_EQ("basic", challenge->scheme); 9356 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9356 9357
9357 // Issue the second request with an incorrect password. There should be a 9358 // Issue the second request with an incorrect password. There should be a
9358 // password prompt for second_realm waiting to be filled in after the 9359 // password prompt for second_realm waiting to be filled in after the
9359 // transaction completes. 9360 // transaction completes.
9360 TestCompletionCallback callback2; 9361 TestCompletionCallback callback2;
9361 rv = trans->RestartWithAuth( 9362 rv = trans->RestartWithAuth(
9362 AuthCredentials(kFirst, kBaz), callback2.callback()); 9363 AuthCredentials(kFirst, kBaz), callback2.callback());
9363 EXPECT_EQ(ERR_IO_PENDING, rv); 9364 EXPECT_EQ(ERR_IO_PENDING, rv);
9364 rv = callback2.WaitForResult(); 9365 rv = callback2.WaitForResult();
9365 EXPECT_EQ(OK, rv); 9366 EXPECT_EQ(OK, rv);
9366 response = trans->GetResponseInfo(); 9367 response = trans->GetResponseInfo();
9367 ASSERT_TRUE(response != NULL); 9368 ASSERT_TRUE(response != NULL);
9368 challenge = response->auth_challenge.get(); 9369 challenge = response->auth_challenge.get();
9369 ASSERT_FALSE(challenge == NULL); 9370 ASSERT_FALSE(challenge == NULL);
9370 EXPECT_FALSE(challenge->is_proxy); 9371 EXPECT_FALSE(challenge->is_proxy);
9371 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9372 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9372 EXPECT_EQ("second_realm", challenge->realm); 9373 EXPECT_EQ("second_realm", challenge->realm);
9373 EXPECT_EQ("basic", challenge->scheme); 9374 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9374 9375
9375 // Issue the third request with another incorrect password. There should be 9376 // Issue the third request with another incorrect password. There should be
9376 // a password prompt for first_realm waiting to be filled in. If the password 9377 // a password prompt for first_realm waiting to be filled in. If the password
9377 // prompt is not present, it indicates that the HttpAuthCacheEntry for 9378 // prompt is not present, it indicates that the HttpAuthCacheEntry for
9378 // first_realm was not correctly removed. 9379 // first_realm was not correctly removed.
9379 TestCompletionCallback callback3; 9380 TestCompletionCallback callback3;
9380 rv = trans->RestartWithAuth( 9381 rv = trans->RestartWithAuth(
9381 AuthCredentials(kSecond, kFou), callback3.callback()); 9382 AuthCredentials(kSecond, kFou), callback3.callback());
9382 EXPECT_EQ(ERR_IO_PENDING, rv); 9383 EXPECT_EQ(ERR_IO_PENDING, rv);
9383 rv = callback3.WaitForResult(); 9384 rv = callback3.WaitForResult();
9384 EXPECT_EQ(OK, rv); 9385 EXPECT_EQ(OK, rv);
9385 response = trans->GetResponseInfo(); 9386 response = trans->GetResponseInfo();
9386 ASSERT_TRUE(response != NULL); 9387 ASSERT_TRUE(response != NULL);
9387 challenge = response->auth_challenge.get(); 9388 challenge = response->auth_challenge.get();
9388 ASSERT_FALSE(challenge == NULL); 9389 ASSERT_FALSE(challenge == NULL);
9389 EXPECT_FALSE(challenge->is_proxy); 9390 EXPECT_FALSE(challenge->is_proxy);
9390 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9391 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9391 EXPECT_EQ("first_realm", challenge->realm); 9392 EXPECT_EQ("first_realm", challenge->realm);
9392 EXPECT_EQ("basic", challenge->scheme); 9393 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9393 9394
9394 // Issue the fourth request with the correct password and username. 9395 // Issue the fourth request with the correct password and username.
9395 TestCompletionCallback callback4; 9396 TestCompletionCallback callback4;
9396 rv = trans->RestartWithAuth( 9397 rv = trans->RestartWithAuth(
9397 AuthCredentials(kFirst, kBar), callback4.callback()); 9398 AuthCredentials(kFirst, kBar), callback4.callback());
9398 EXPECT_EQ(ERR_IO_PENDING, rv); 9399 EXPECT_EQ(ERR_IO_PENDING, rv);
9399 rv = callback4.WaitForResult(); 9400 rv = callback4.WaitForResult();
9400 EXPECT_EQ(OK, rv); 9401 EXPECT_EQ(OK, rv);
9401 response = trans->GetResponseInfo(); 9402 response = trans->GetResponseInfo();
9402 ASSERT_TRUE(response != NULL); 9403 ASSERT_TRUE(response != NULL);
(...skipping 6051 matching lines...) Expand 10 before | Expand all | Expand 10 after
15454 std::string response_data; 15455 std::string response_data;
15455 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 15456 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data));
15456 15457
15457 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), 15458 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)),
15458 trans->GetTotalSentBytes()); 15459 trans->GetTotalSentBytes());
15459 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), 15460 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)),
15460 trans->GetTotalReceivedBytes()); 15461 trans->GetTotalReceivedBytes());
15461 } 15462 }
15462 15463
15463 } // namespace net 15464 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698