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

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: Respond to cbentzel@'s comments. Created 5 years 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
« no previous file with comments | « net/http/http_log_util.cc ('k') | net/http/mock_allow_http_auth_preferences.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25 matching lines...) Expand all
36 #include "net/base/test_data_directory.h" 36 #include "net/base/test_data_directory.h"
37 #include "net/base/upload_bytes_element_reader.h" 37 #include "net/base/upload_bytes_element_reader.h"
38 #include "net/base/upload_file_element_reader.h" 38 #include "net/base/upload_file_element_reader.h"
39 #include "net/cert/mock_cert_verifier.h" 39 #include "net/cert/mock_cert_verifier.h"
40 #include "net/dns/host_cache.h" 40 #include "net/dns/host_cache.h"
41 #include "net/dns/mock_host_resolver.h" 41 #include "net/dns/mock_host_resolver.h"
42 #include "net/http/http_auth_challenge_tokenizer.h" 42 #include "net/http/http_auth_challenge_tokenizer.h"
43 #include "net/http/http_auth_handler_digest.h" 43 #include "net/http/http_auth_handler_digest.h"
44 #include "net/http/http_auth_handler_mock.h" 44 #include "net/http/http_auth_handler_mock.h"
45 #include "net/http/http_auth_handler_ntlm.h" 45 #include "net/http/http_auth_handler_ntlm.h"
46 #include "net/http/http_auth_scheme.h"
46 #include "net/http/http_basic_state.h" 47 #include "net/http/http_basic_state.h"
47 #include "net/http/http_basic_stream.h" 48 #include "net/http/http_basic_stream.h"
48 #include "net/http/http_network_session.h" 49 #include "net/http/http_network_session.h"
49 #include "net/http/http_network_session_peer.h" 50 #include "net/http/http_network_session_peer.h"
50 #include "net/http/http_request_headers.h" 51 #include "net/http/http_request_headers.h"
51 #include "net/http/http_server_properties_impl.h" 52 #include "net/http/http_server_properties_impl.h"
52 #include "net/http/http_stream.h" 53 #include "net/http/http_stream.h"
53 #include "net/http/http_stream_factory.h" 54 #include "net/http/http_stream_factory.h"
54 #include "net/http/http_stream_parser.h" 55 #include "net/http/http_stream_parser.h"
55 #include "net/http/http_transaction_test_util.h" 56 #include "net/http/http_transaction_test_util.h"
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 //----------------------------------------------------------------------------- 661 //-----------------------------------------------------------------------------
661 662
662 // Helper functions for validating that AuthChallengeInfo's are correctly 663 // Helper functions for validating that AuthChallengeInfo's are correctly
663 // configured for common cases. 664 // configured for common cases.
664 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { 665 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) {
665 if (!auth_challenge) 666 if (!auth_challenge)
666 return false; 667 return false;
667 EXPECT_FALSE(auth_challenge->is_proxy); 668 EXPECT_FALSE(auth_challenge->is_proxy);
668 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); 669 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString());
669 EXPECT_EQ("MyRealm1", auth_challenge->realm); 670 EXPECT_EQ("MyRealm1", auth_challenge->realm);
670 EXPECT_EQ("basic", auth_challenge->scheme); 671 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme);
671 return true; 672 return true;
672 } 673 }
673 674
674 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { 675 bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) {
675 if (!auth_challenge) 676 if (!auth_challenge)
676 return false; 677 return false;
677 EXPECT_TRUE(auth_challenge->is_proxy); 678 EXPECT_TRUE(auth_challenge->is_proxy);
678 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); 679 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString());
679 EXPECT_EQ("MyRealm1", auth_challenge->realm); 680 EXPECT_EQ("MyRealm1", auth_challenge->realm);
680 EXPECT_EQ("basic", auth_challenge->scheme); 681 EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme);
681 return true; 682 return true;
682 } 683 }
683 684
684 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { 685 bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) {
685 if (!auth_challenge) 686 if (!auth_challenge)
686 return false; 687 return false;
687 EXPECT_FALSE(auth_challenge->is_proxy); 688 EXPECT_FALSE(auth_challenge->is_proxy);
688 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); 689 EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString());
689 EXPECT_EQ("digestive", auth_challenge->realm); 690 EXPECT_EQ("digestive", auth_challenge->realm);
690 EXPECT_EQ("digest", auth_challenge->scheme); 691 EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme);
691 return true; 692 return true;
692 } 693 }
693 694
694 #if defined(NTLM_PORTABLE) 695 #if defined(NTLM_PORTABLE)
695 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { 696 bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) {
696 if (!auth_challenge) 697 if (!auth_challenge)
697 return false; 698 return false;
698 EXPECT_FALSE(auth_challenge->is_proxy); 699 EXPECT_FALSE(auth_challenge->is_proxy);
699 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); 700 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString());
700 EXPECT_EQ(std::string(), auth_challenge->realm); 701 EXPECT_EQ(std::string(), auth_challenge->realm);
701 EXPECT_EQ("ntlm", auth_challenge->scheme); 702 EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme);
702 return true; 703 return true;
703 } 704 }
704 #endif // defined(NTLM_PORTABLE) 705 #endif // defined(NTLM_PORTABLE)
705 706
706 } // namespace 707 } // namespace
707 708
708 TEST_P(HttpNetworkTransactionTest, Basic) { 709 TEST_P(HttpNetworkTransactionTest, Basic) {
709 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 710 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
710 scoped_ptr<HttpTransaction> trans( 711 scoped_ptr<HttpTransaction> trans(
711 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 712 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
(...skipping 5806 matching lines...) Expand 10 before | Expand all | Expand 10 after
6518 rv = callback1.WaitForResult(); 6519 rv = callback1.WaitForResult();
6519 EXPECT_EQ(OK, rv); 6520 EXPECT_EQ(OK, rv);
6520 6521
6521 const HttpResponseInfo* response = trans->GetResponseInfo(); 6522 const HttpResponseInfo* response = trans->GetResponseInfo();
6522 ASSERT_TRUE(response != NULL); 6523 ASSERT_TRUE(response != NULL);
6523 ASSERT_TRUE(response->auth_challenge.get()); 6524 ASSERT_TRUE(response->auth_challenge.get());
6524 EXPECT_FALSE(response->auth_challenge->is_proxy); 6525 EXPECT_FALSE(response->auth_challenge->is_proxy);
6525 EXPECT_EQ("www.example.org:80", 6526 EXPECT_EQ("www.example.org:80",
6526 response->auth_challenge->challenger.ToString()); 6527 response->auth_challenge->challenger.ToString());
6527 EXPECT_EQ("MyRealm2", response->auth_challenge->realm); 6528 EXPECT_EQ("MyRealm2", response->auth_challenge->realm);
6528 EXPECT_EQ("basic", response->auth_challenge->scheme); 6529 EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme);
6529 6530
6530 TestCompletionCallback callback2; 6531 TestCompletionCallback callback2;
6531 6532
6532 rv = trans->RestartWithAuth( 6533 rv = trans->RestartWithAuth(
6533 AuthCredentials(kFoo2, kBar2), callback2.callback()); 6534 AuthCredentials(kFoo2, kBar2), callback2.callback());
6534 EXPECT_EQ(ERR_IO_PENDING, rv); 6535 EXPECT_EQ(ERR_IO_PENDING, rv);
6535 6536
6536 rv = callback2.WaitForResult(); 6537 rv = callback2.WaitForResult();
6537 EXPECT_EQ(OK, rv); 6538 EXPECT_EQ(OK, rv);
6538 6539
(...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after
9348 EXPECT_EQ(ERR_IO_PENDING, rv); 9349 EXPECT_EQ(ERR_IO_PENDING, rv);
9349 rv = callback1.WaitForResult(); 9350 rv = callback1.WaitForResult();
9350 EXPECT_EQ(OK, rv); 9351 EXPECT_EQ(OK, rv);
9351 const HttpResponseInfo* response = trans->GetResponseInfo(); 9352 const HttpResponseInfo* response = trans->GetResponseInfo();
9352 ASSERT_TRUE(response != NULL); 9353 ASSERT_TRUE(response != NULL);
9353 const AuthChallengeInfo* challenge = response->auth_challenge.get(); 9354 const AuthChallengeInfo* challenge = response->auth_challenge.get();
9354 ASSERT_FALSE(challenge == NULL); 9355 ASSERT_FALSE(challenge == NULL);
9355 EXPECT_FALSE(challenge->is_proxy); 9356 EXPECT_FALSE(challenge->is_proxy);
9356 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9357 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9357 EXPECT_EQ("first_realm", challenge->realm); 9358 EXPECT_EQ("first_realm", challenge->realm);
9358 EXPECT_EQ("basic", challenge->scheme); 9359 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9359 9360
9360 // Issue the second request with an incorrect password. There should be a 9361 // Issue the second request with an incorrect password. There should be a
9361 // password prompt for second_realm waiting to be filled in after the 9362 // password prompt for second_realm waiting to be filled in after the
9362 // transaction completes. 9363 // transaction completes.
9363 TestCompletionCallback callback2; 9364 TestCompletionCallback callback2;
9364 rv = trans->RestartWithAuth( 9365 rv = trans->RestartWithAuth(
9365 AuthCredentials(kFirst, kBaz), callback2.callback()); 9366 AuthCredentials(kFirst, kBaz), callback2.callback());
9366 EXPECT_EQ(ERR_IO_PENDING, rv); 9367 EXPECT_EQ(ERR_IO_PENDING, rv);
9367 rv = callback2.WaitForResult(); 9368 rv = callback2.WaitForResult();
9368 EXPECT_EQ(OK, rv); 9369 EXPECT_EQ(OK, rv);
9369 response = trans->GetResponseInfo(); 9370 response = trans->GetResponseInfo();
9370 ASSERT_TRUE(response != NULL); 9371 ASSERT_TRUE(response != NULL);
9371 challenge = response->auth_challenge.get(); 9372 challenge = response->auth_challenge.get();
9372 ASSERT_FALSE(challenge == NULL); 9373 ASSERT_FALSE(challenge == NULL);
9373 EXPECT_FALSE(challenge->is_proxy); 9374 EXPECT_FALSE(challenge->is_proxy);
9374 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9375 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9375 EXPECT_EQ("second_realm", challenge->realm); 9376 EXPECT_EQ("second_realm", challenge->realm);
9376 EXPECT_EQ("basic", challenge->scheme); 9377 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9377 9378
9378 // Issue the third request with another incorrect password. There should be 9379 // Issue the third request with another incorrect password. There should be
9379 // a password prompt for first_realm waiting to be filled in. If the password 9380 // a password prompt for first_realm waiting to be filled in. If the password
9380 // prompt is not present, it indicates that the HttpAuthCacheEntry for 9381 // prompt is not present, it indicates that the HttpAuthCacheEntry for
9381 // first_realm was not correctly removed. 9382 // first_realm was not correctly removed.
9382 TestCompletionCallback callback3; 9383 TestCompletionCallback callback3;
9383 rv = trans->RestartWithAuth( 9384 rv = trans->RestartWithAuth(
9384 AuthCredentials(kSecond, kFou), callback3.callback()); 9385 AuthCredentials(kSecond, kFou), callback3.callback());
9385 EXPECT_EQ(ERR_IO_PENDING, rv); 9386 EXPECT_EQ(ERR_IO_PENDING, rv);
9386 rv = callback3.WaitForResult(); 9387 rv = callback3.WaitForResult();
9387 EXPECT_EQ(OK, rv); 9388 EXPECT_EQ(OK, rv);
9388 response = trans->GetResponseInfo(); 9389 response = trans->GetResponseInfo();
9389 ASSERT_TRUE(response != NULL); 9390 ASSERT_TRUE(response != NULL);
9390 challenge = response->auth_challenge.get(); 9391 challenge = response->auth_challenge.get();
9391 ASSERT_FALSE(challenge == NULL); 9392 ASSERT_FALSE(challenge == NULL);
9392 EXPECT_FALSE(challenge->is_proxy); 9393 EXPECT_FALSE(challenge->is_proxy);
9393 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); 9394 EXPECT_EQ("www.example.org:80", challenge->challenger.ToString());
9394 EXPECT_EQ("first_realm", challenge->realm); 9395 EXPECT_EQ("first_realm", challenge->realm);
9395 EXPECT_EQ("basic", challenge->scheme); 9396 EXPECT_EQ(kBasicAuthScheme, challenge->scheme);
9396 9397
9397 // Issue the fourth request with the correct password and username. 9398 // Issue the fourth request with the correct password and username.
9398 TestCompletionCallback callback4; 9399 TestCompletionCallback callback4;
9399 rv = trans->RestartWithAuth( 9400 rv = trans->RestartWithAuth(
9400 AuthCredentials(kFirst, kBar), callback4.callback()); 9401 AuthCredentials(kFirst, kBar), callback4.callback());
9401 EXPECT_EQ(ERR_IO_PENDING, rv); 9402 EXPECT_EQ(ERR_IO_PENDING, rv);
9402 rv = callback4.WaitForResult(); 9403 rv = callback4.WaitForResult();
9403 EXPECT_EQ(OK, rv); 9404 EXPECT_EQ(OK, rv);
9404 response = trans->GetResponseInfo(); 9405 response = trans->GetResponseInfo();
9405 ASSERT_TRUE(response != NULL); 9406 ASSERT_TRUE(response != NULL);
(...skipping 6087 matching lines...) Expand 10 before | Expand all | Expand 10 after
15493 15494
15494 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15495 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15495 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15496 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15496 15497
15497 EXPECT_THAT(trans.server_ssl_config_.alpn_protos, 15498 EXPECT_THAT(trans.server_ssl_config_.alpn_protos,
15498 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); 15499 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11));
15499 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); 15500 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty());
15500 } 15501 }
15501 15502
15502 } // namespace net 15503 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_log_util.cc ('k') | net/http/mock_allow_http_auth_preferences.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698