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

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

Issue 1381493004: [net/http auth] Generalize HttpAuthHandlerMock. Base URL: https://chromium.googlesource.com/chromium/src.git@http-auth-scheme-properties
Patch Set: Created 5 years, 2 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
« no previous file with comments | « net/http/http_auth_handler_mock.cc ('k') | net/http/http_network_transaction_unittest.cc » ('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 (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"
(...skipping 11 matching lines...) Expand all
22 #include "net/http/mock_allow_url_security_manager.h" 22 #include "net/http/mock_allow_url_security_manager.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 namespace net { 25 namespace net {
26 26
27 namespace { 27 namespace {
28 28
29 HttpAuthHandlerMock* CreateMockHandler(bool expect_multiple_challenges) { 29 HttpAuthHandlerMock* CreateMockHandler(bool expect_multiple_challenges) {
30 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); 30 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock();
31 auth_handler->set_expect_multiple_challenges(expect_multiple_challenges); 31 auth_handler->set_expect_multiple_challenges(expect_multiple_challenges);
32 std::string challenge_text = "Basic"; 32 std::string challenge_text = "Mock";
33 HttpAuthChallengeTokenizer challenge(challenge_text.begin(), 33 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
34 challenge_text.end()); 34 challenge_text.end());
35 GURL origin("www.example.com"); 35 GURL origin("www.example.com");
36 EXPECT_TRUE(auth_handler->InitFromChallenge(&challenge, 36 EXPECT_TRUE(auth_handler->InitFromChallenge(&challenge, HttpAuth::AUTH_SERVER,
37 HttpAuth::AUTH_SERVER, 37 origin, BoundNetLog()));
38 origin,
39 BoundNetLog()));
40 return auth_handler; 38 return auth_handler;
41 } 39 }
42 40
43 HttpResponseHeaders* HeadersFromResponseText(const std::string& response) { 41 HttpResponseHeaders* HeadersFromResponseText(const std::string& response) {
44 return new HttpResponseHeaders( 42 return new HttpResponseHeaders(
45 HttpUtil::AssembleRawHeaders(response.c_str(), response.length())); 43 HttpUtil::AssembleRawHeaders(response.c_str(), response.length()));
46 } 44 }
47 45
48 HttpAuth::AuthorizationResult HandleChallengeResponse( 46 HttpAuth::AuthorizationResult HandleChallengeResponse(
49 bool expect_multiple_challenges, 47 bool expect_multiple_challenges,
50 const std::string& headers_text, 48 const std::string& headers_text,
51 std::string* challenge_used) { 49 std::string* challenge_used) {
52 scoped_ptr<HttpAuthHandlerMock> mock_handler( 50 scoped_ptr<HttpAuthHandlerMock> mock_handler(
53 CreateMockHandler(expect_multiple_challenges)); 51 CreateMockHandler(expect_multiple_challenges));
54 HttpAuthSchemeSet disabled_schemes; 52 HttpAuthSchemeSet disabled_schemes;
55 scoped_refptr<HttpResponseHeaders> headers( 53 scoped_refptr<HttpResponseHeaders> headers(
56 HeadersFromResponseText(headers_text)); 54 HeadersFromResponseText(headers_text));
57 return HttpAuth::HandleChallengeResponse( 55 return HttpAuth::HandleChallengeResponse(mock_handler.get(), headers.get(),
58 mock_handler.get(), 56 HttpAuth::AUTH_SERVER,
59 headers.get(), 57 disabled_schemes, challenge_used);
60 HttpAuth::AUTH_SERVER,
61 disabled_schemes,
62 challenge_used);
63 } 58 }
64 59
65 } // namespace 60 } // namespace
66 61
67 TEST(HttpAuthTest, ChooseBestChallenge) { 62 TEST(HttpAuthTest, ChooseBestChallenge) {
68 static const struct { 63 static const struct {
69 const char* headers; 64 const char* headers;
70 const char* challenge_scheme; 65 const char* challenge_scheme;
71 const char* challenge_realm; 66 const char* challenge_realm;
72 } tests[] = { 67 } tests[] = {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 std::string name; 254 std::string name;
260 255
261 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER); 256 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER);
262 EXPECT_STREQ("Authorization", name.c_str()); 257 EXPECT_STREQ("Authorization", name.c_str());
263 258
264 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY); 259 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY);
265 EXPECT_STREQ("Proxy-Authorization", name.c_str()); 260 EXPECT_STREQ("Proxy-Authorization", name.c_str());
266 } 261 }
267 262
268 } // namespace net 263 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_mock.cc ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698