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

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

Issue 1408433006: Support tls-server-end-point channel bindings for HTTP authentication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Narrower dependencies, update comments, address review comments. Created 4 years, 9 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/dns/mock_host_resolver.h" 12 #include "net/dns/mock_host_resolver.h"
13 #include "net/http/http_auth.h" 13 #include "net/http/http_auth.h"
14 #include "net/http/http_auth_challenge_tokenizer.h" 14 #include "net/http/http_auth_challenge_tokenizer.h"
15 #include "net/http/http_auth_filter.h" 15 #include "net/http/http_auth_filter.h"
16 #include "net/http/http_auth_handler.h" 16 #include "net/http/http_auth_handler.h"
17 #include "net/http/http_auth_handler_factory.h" 17 #include "net/http/http_auth_handler_factory.h"
18 #include "net/http/http_auth_handler_mock.h" 18 #include "net/http/http_auth_handler_mock.h"
19 #include "net/http/http_auth_scheme.h" 19 #include "net/http/http_auth_scheme.h"
20 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
21 #include "net/http/http_util.h" 21 #include "net/http/http_util.h"
22 #include "net/http/mock_allow_http_auth_preferences.h" 22 #include "net/http/mock_allow_http_auth_preferences.h"
23 #include "net/ssl/ssl_info.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace net { 26 namespace net {
26 27
27 namespace { 28 namespace {
28 29
29 HttpAuthHandlerMock* CreateMockHandler(bool connection_based) { 30 HttpAuthHandlerMock* CreateMockHandler(bool connection_based) {
30 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); 31 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock();
31 auth_handler->set_connection_based(connection_based); 32 auth_handler->set_connection_based(connection_based);
32 std::string challenge_text = "Basic"; 33 std::string challenge_text = "Basic";
33 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), 34 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
34 challenge_text.end()); 35 challenge_text.end());
35 GURL origin("www.example.com"); 36 GURL origin("www.example.com");
36 EXPECT_TRUE(auth_handler->InitFromChallenge(&challenge, 37 SSLInfo null_ssl_info;
37 HttpAuth::AUTH_SERVER, 38 EXPECT_TRUE(auth_handler->InitFromChallenge(
38 origin, 39 &challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, BoundNetLog()));
39 BoundNetLog()));
40 return auth_handler; 40 return auth_handler;
41 } 41 }
42 42
43 HttpResponseHeaders* HeadersFromResponseText(const std::string& response) { 43 HttpResponseHeaders* HeadersFromResponseText(const std::string& response) {
44 return new HttpResponseHeaders( 44 return new HttpResponseHeaders(
45 HttpUtil::AssembleRawHeaders(response.c_str(), response.length())); 45 HttpUtil::AssembleRawHeaders(response.c_str(), response.length()));
46 } 46 }
47 47
48 HttpAuth::AuthorizationResult HandleChallengeResponse( 48 HttpAuth::AuthorizationResult HandleChallengeResponse(
49 bool connection_based, 49 bool connection_based,
50 const std::string& headers_text, 50 const std::string& headers_text,
51 std::string* challenge_used) { 51 std::string* challenge_used) {
52 scoped_ptr<HttpAuthHandlerMock> mock_handler( 52 scoped_ptr<HttpAuthHandlerMock> mock_handler(
53 CreateMockHandler(connection_based)); 53 CreateMockHandler(connection_based));
54 std::set<HttpAuth::Scheme> disabled_schemes; 54 std::set<HttpAuth::Scheme> disabled_schemes;
55 scoped_refptr<HttpResponseHeaders> headers( 55 scoped_refptr<HttpResponseHeaders> headers(
56 HeadersFromResponseText(headers_text)); 56 HeadersFromResponseText(headers_text));
57 return HttpAuth::HandleChallengeResponse( 57 return HttpAuth::HandleChallengeResponse(mock_handler.get(), *headers,
58 mock_handler.get(), 58 HttpAuth::AUTH_SERVER,
59 headers.get(), 59 disabled_schemes, challenge_used);
60 HttpAuth::AUTH_SERVER,
61 disabled_schemes,
62 challenge_used);
63 } 60 }
64 61
65 } // namespace 62 } // namespace
66 63
67 TEST(HttpAuthTest, ChooseBestChallenge) { 64 TEST(HttpAuthTest, ChooseBestChallenge) {
68 static const struct { 65 static const struct {
69 const char* headers; 66 const char* headers;
70 HttpAuth::Scheme challenge_scheme; 67 HttpAuth::Scheme challenge_scheme;
71 const char* challenge_realm; 68 const char* challenge_realm;
72 } tests[] = { 69 } tests[] = {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 http_auth_handler_factory->SetHttpAuthPreferences(kNegotiateAuthScheme, 126 http_auth_handler_factory->SetHttpAuthPreferences(kNegotiateAuthScheme,
130 &http_auth_preferences); 127 &http_auth_preferences);
131 128
132 for (size_t i = 0; i < arraysize(tests); ++i) { 129 for (size_t i = 0; i < arraysize(tests); ++i) {
133 // Make a HttpResponseHeaders object. 130 // Make a HttpResponseHeaders object.
134 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n"); 131 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
135 headers_with_status_line += tests[i].headers; 132 headers_with_status_line += tests[i].headers;
136 scoped_refptr<HttpResponseHeaders> headers( 133 scoped_refptr<HttpResponseHeaders> headers(
137 HeadersFromResponseText(headers_with_status_line)); 134 HeadersFromResponseText(headers_with_status_line));
138 135
136 SSLInfo null_ssl_info;
139 scoped_ptr<HttpAuthHandler> handler; 137 scoped_ptr<HttpAuthHandler> handler;
140 HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(), 138 HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(), *headers,
141 headers.get(), 139 null_ssl_info, HttpAuth::AUTH_SERVER, origin,
142 HttpAuth::AUTH_SERVER, 140 disabled_schemes, BoundNetLog(), &handler);
143 origin,
144 disabled_schemes,
145 BoundNetLog(),
146 &handler);
147 141
148 if (handler.get()) { 142 if (handler.get()) {
149 EXPECT_EQ(tests[i].challenge_scheme, handler->auth_scheme()); 143 EXPECT_EQ(tests[i].challenge_scheme, handler->auth_scheme());
150 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str()); 144 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
151 } else { 145 } else {
152 EXPECT_EQ(HttpAuth::AUTH_SCHEME_MAX, tests[i].challenge_scheme); 146 EXPECT_EQ(HttpAuth::AUTH_SCHEME_MAX, tests[i].challenge_scheme);
153 EXPECT_STREQ("", tests[i].challenge_realm); 147 EXPECT_STREQ("", tests[i].challenge_realm);
154 } 148 }
155 } 149 }
156 } 150 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 std::string name; 254 std::string name;
261 255
262 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER); 256 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER);
263 EXPECT_STREQ("Authorization", name.c_str()); 257 EXPECT_STREQ("Authorization", name.c_str());
264 258
265 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY); 259 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY);
266 EXPECT_STREQ("Proxy-Authorization", name.c_str()); 260 EXPECT_STREQ("Proxy-Authorization", name.c_str());
267 } 261 }
268 262
269 } // namespace net 263 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698