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

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

Issue 10416044: Merge 138264 - Re-enable embedded identities in URLs for HTTP authentication. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1084/src/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 3707 matching lines...) Expand 10 before | Expand all | Expand 10 after
3718 3718
3719 std::string response_data; 3719 std::string response_data;
3720 rv = ReadTransaction(trans.get(), &response_data); 3720 rv = ReadTransaction(trans.get(), &response_data);
3721 EXPECT_EQ(OK, rv); 3721 EXPECT_EQ(OK, rv);
3722 EXPECT_EQ(kExpectedResponseData[i], response_data); 3722 EXPECT_EQ(kExpectedResponseData[i], response_data);
3723 } 3723 }
3724 } 3724 }
3725 3725
3726 // Test the request-challenge-retry sequence for basic auth when there is 3726 // Test the request-challenge-retry sequence for basic auth when there is
3727 // an identity in the URL. The request should be sent as normal, but when 3727 // an identity in the URL. The request should be sent as normal, but when
3728 // it fails the identity from the URL is no longer used. 3728 // it fails the identity from the URL is used to answer the challenge.
3729 TEST_F(HttpNetworkTransactionSpdy3Test, IgnoreAuthIdentityInURL) { 3729 TEST_F(HttpNetworkTransactionSpdy3Test, AuthIdentityInURL) {
3730 HttpRequestInfo request; 3730 HttpRequestInfo request;
3731 request.method = "GET"; 3731 request.method = "GET";
3732 request.url = GURL("http://foo:b@r@www.google.com/"); 3732 request.url = GURL("http://foo:b@r@www.google.com/");
3733 request.load_flags = LOAD_NORMAL; 3733 request.load_flags = LOAD_NORMAL;
3734 3734
3735 SessionDependencies session_deps; 3735 SessionDependencies session_deps;
3736 scoped_ptr<HttpTransaction> trans( 3736 scoped_ptr<HttpTransaction> trans(
3737 new HttpNetworkTransaction(CreateSession(&session_deps))); 3737 new HttpNetworkTransaction(CreateSession(&session_deps)));
3738 3738
3739 // The password contains an escaped character -- for this test to pass it 3739 // The password contains an escaped character -- for this test to pass it
3740 // will need to be unescaped by HttpNetworkTransaction. 3740 // will need to be unescaped by HttpNetworkTransaction.
3741 EXPECT_EQ("b%40r", request.url.password()); 3741 EXPECT_EQ("b%40r", request.url.password());
3742 3742
3743 MockWrite data_writes1[] = { 3743 MockWrite data_writes1[] = {
3744 MockWrite("GET / HTTP/1.1\r\n" 3744 MockWrite("GET / HTTP/1.1\r\n"
3745 "Host: www.google.com\r\n" 3745 "Host: www.google.com\r\n"
3746 "Connection: keep-alive\r\n\r\n"), 3746 "Connection: keep-alive\r\n\r\n"),
3747 }; 3747 };
3748 3748
3749 MockRead data_reads1[] = { 3749 MockRead data_reads1[] = {
3750 MockRead("HTTP/1.0 401 Unauthorized\r\n"), 3750 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
3751 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), 3751 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3752 MockRead("Content-Length: 10\r\n\r\n"), 3752 MockRead("Content-Length: 10\r\n\r\n"),
3753 MockRead(SYNCHRONOUS, ERR_FAILED), 3753 MockRead(SYNCHRONOUS, ERR_FAILED),
3754 }; 3754 };
3755 3755
3756 // After the challenge above, the transaction will be restarted using the
3757 // identity from the url (foo, b@r) to answer the challenge.
3758 MockWrite data_writes2[] = {
3759 MockWrite("GET / HTTP/1.1\r\n"
3760 "Host: www.google.com\r\n"
3761 "Connection: keep-alive\r\n"
3762 "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"),
3763 };
3764
3765 MockRead data_reads2[] = {
3766 MockRead("HTTP/1.0 200 OK\r\n"),
3767 MockRead("Content-Length: 100\r\n\r\n"),
3768 MockRead(SYNCHRONOUS, OK),
3769 };
3770
3756 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), 3771 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
3757 data_writes1, arraysize(data_writes1)); 3772 data_writes1, arraysize(data_writes1));
3773 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
3774 data_writes2, arraysize(data_writes2));
3758 session_deps.socket_factory.AddSocketDataProvider(&data1); 3775 session_deps.socket_factory.AddSocketDataProvider(&data1);
3776 session_deps.socket_factory.AddSocketDataProvider(&data2);
3759 3777
3760 TestCompletionCallback callback1; 3778 TestCompletionCallback callback1;
3761 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); 3779 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
3762 EXPECT_EQ(ERR_IO_PENDING, rv); 3780 EXPECT_EQ(ERR_IO_PENDING, rv);
3763 rv = callback1.WaitForResult(); 3781 rv = callback1.WaitForResult();
3764 EXPECT_EQ(OK, rv); 3782 EXPECT_EQ(OK, rv);
3783 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
3784
3785 TestCompletionCallback callback2;
3786 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
3787 EXPECT_EQ(ERR_IO_PENDING, rv);
3788 rv = callback2.WaitForResult();
3789 EXPECT_EQ(OK, rv);
3765 EXPECT_FALSE(trans->IsReadyToRestartForAuth()); 3790 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
3766 3791
3792 const HttpResponseInfo* response = trans->GetResponseInfo();
3793 ASSERT_TRUE(response != NULL);
3794
3795 // There is no challenge info, since the identity in URL worked.
3796 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3797
3798 EXPECT_EQ(100, response->headers->GetContentLength());
3799
3800 // Empty the current queue.
3801 MessageLoop::current()->RunAllPending();
3802 }
3803
3804 // Test the request-challenge-retry sequence for basic auth when there is an
3805 // incorrect identity in the URL. The identity from the URL should be used only
3806 // once.
3807 TEST_F(HttpNetworkTransactionSpdy3Test, WrongAuthIdentityInURL) {
3808 HttpRequestInfo request;
3809 request.method = "GET";
3810 // Note: the URL has a username:password in it. The password "baz" is
3811 // wrong (should be "bar").
3812 request.url = GURL("http://foo:baz@www.google.com/");
3813
3814 request.load_flags = LOAD_NORMAL;
3815
3816 SessionDependencies session_deps;
3817 scoped_ptr<HttpTransaction> trans(
3818 new HttpNetworkTransaction(CreateSession(&session_deps)));
3819
3820 MockWrite data_writes1[] = {
3821 MockWrite("GET / HTTP/1.1\r\n"
3822 "Host: www.google.com\r\n"
3823 "Connection: keep-alive\r\n\r\n"),
3824 };
3825
3826 MockRead data_reads1[] = {
3827 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
3828 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3829 MockRead("Content-Length: 10\r\n\r\n"),
3830 MockRead(SYNCHRONOUS, ERR_FAILED),
3831 };
3832
3833 // After the challenge above, the transaction will be restarted using the
3834 // identity from the url (foo, baz) to answer the challenge.
3835 MockWrite data_writes2[] = {
3836 MockWrite("GET / HTTP/1.1\r\n"
3837 "Host: www.google.com\r\n"
3838 "Connection: keep-alive\r\n"
3839 "Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
3840 };
3841
3842 MockRead data_reads2[] = {
3843 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
3844 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3845 MockRead("Content-Length: 10\r\n\r\n"),
3846 MockRead(SYNCHRONOUS, ERR_FAILED),
3847 };
3848
3849 // After the challenge above, the transaction will be restarted using the
3850 // identity supplied by the user (foo, bar) to answer the challenge.
3851 MockWrite data_writes3[] = {
3852 MockWrite("GET / HTTP/1.1\r\n"
3853 "Host: www.google.com\r\n"
3854 "Connection: keep-alive\r\n"
3855 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
3856 };
3857
3858 MockRead data_reads3[] = {
3859 MockRead("HTTP/1.0 200 OK\r\n"),
3860 MockRead("Content-Length: 100\r\n\r\n"),
3861 MockRead(SYNCHRONOUS, OK),
3862 };
3863
3864 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
3865 data_writes1, arraysize(data_writes1));
3866 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
3867 data_writes2, arraysize(data_writes2));
3868 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
3869 data_writes3, arraysize(data_writes3));
3870 session_deps.socket_factory.AddSocketDataProvider(&data1);
3871 session_deps.socket_factory.AddSocketDataProvider(&data2);
3872 session_deps.socket_factory.AddSocketDataProvider(&data3);
3873
3874 TestCompletionCallback callback1;
3875
3876 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
3877 EXPECT_EQ(ERR_IO_PENDING, rv);
3878
3879 rv = callback1.WaitForResult();
3880 EXPECT_EQ(OK, rv);
3881
3882 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
3883 TestCompletionCallback callback2;
3884 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
3885 EXPECT_EQ(ERR_IO_PENDING, rv);
3886 rv = callback2.WaitForResult();
3887 EXPECT_EQ(OK, rv);
3888 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
3889
3890 const HttpResponseInfo* response = trans->GetResponseInfo();
3891 ASSERT_TRUE(response != NULL);
3892 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
3893
3894 TestCompletionCallback callback3;
3895 rv = trans->RestartWithAuth(
3896 AuthCredentials(kFoo, kBar), callback3.callback());
3897 EXPECT_EQ(ERR_IO_PENDING, rv);
3898 rv = callback3.WaitForResult();
3899 EXPECT_EQ(OK, rv);
3900 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
3901
3902 response = trans->GetResponseInfo();
3903 ASSERT_TRUE(response != NULL);
3904
3905 // There is no challenge info, since the identity worked.
3906 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3907
3908 EXPECT_EQ(100, response->headers->GetContentLength());
3909
3767 // Empty the current queue. 3910 // Empty the current queue.
3768 MessageLoop::current()->RunAllPending(); 3911 MessageLoop::current()->RunAllPending();
3769 } 3912 }
3770 3913
3771 // Test that previously tried username/passwords for a realm get re-used. 3914 // Test that previously tried username/passwords for a realm get re-used.
3772 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthCacheAndPreauth) { 3915 TEST_F(HttpNetworkTransactionSpdy3Test, BasicAuthCacheAndPreauth) {
3773 SessionDependencies session_deps; 3916 SessionDependencies session_deps;
3774 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 3917 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3775 3918
3776 // Transaction 1: authenticate (foo, bar) on MyRealm1 3919 // Transaction 1: authenticate (foo, bar) on MyRealm1
(...skipping 5592 matching lines...) Expand 10 before | Expand all | Expand 10 after
9369 StaticSocketDataProvider* data[] = { &data1, &data2 }; 9512 StaticSocketDataProvider* data[] = { &data1, &data2 };
9370 9513
9371 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); 9514 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
9372 9515
9373 EXPECT_EQ(OK, out.rv); 9516 EXPECT_EQ(OK, out.rv);
9374 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 9517 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
9375 EXPECT_EQ("hello world", out.response_data); 9518 EXPECT_EQ("hello world", out.response_data);
9376 } 9519 }
9377 9520
9378 } // namespace net 9521 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_spdy2_unittest.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698