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

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

Issue 8340026: Use AuthCredentials throughout the network stack instead of username/password. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reduce password zapping Created 9 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_auth_handler.h" 5 #include "net/http/http_auth_handler.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "net/base/capturing_net_log.h" 9 #include "net/base/capturing_net_log.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/base/net_log_unittest.h" 11 #include "net/base/net_log_unittest.h"
12 #include "net/base/test_completion_callback.h" 12 #include "net/base/test_completion_callback.h"
13 #include "net/http/http_auth_handler_mock.h" 13 #include "net/http/http_auth_handler_mock.h"
14 #include "net/http/http_request_info.h" 14 #include "net/http/http_request_info.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 TEST(HttpAuthHandlerTest, NetLog) { 19 TEST(HttpAuthHandlerTest, NetLog) {
20 NetLog::Source source; 20 NetLog::Source source;
21 GURL origin("http://www.example.com"); 21 GURL origin("http://www.example.com");
22 std::string challenge = "Mock asdf"; 22 std::string challenge = "Mock asdf";
23 string16 username = ASCIIToUTF16("user"); 23 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass"));
24 string16 password = ASCIIToUTF16("pass");
25 std::string auth_token; 24 std::string auth_token;
26 HttpRequestInfo request; 25 HttpRequestInfo request;
27 26
28 for (int i = 0; i < 2; ++i) { 27 for (int i = 0; i < 2; ++i) {
29 bool async = (i == 0); 28 bool async = (i == 0);
30 for (int j = 0; j < 2; ++j) { 29 for (int j = 0; j < 2; ++j) {
31 int rv = (j == 0) ? OK : ERR_UNEXPECTED; 30 int rv = (j == 0) ? OK : ERR_UNEXPECTED;
32 for (int k = 0; k < 2; ++k) { 31 for (int k = 0; k < 2; ++k) {
33 TestOldCompletionCallback test_callback; 32 TestOldCompletionCallback test_callback;
34 HttpAuth::Target target = 33 HttpAuth::Target target =
35 (k == 0) ? HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER; 34 (k == 0) ? HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER;
36 NetLog::EventType event_type = 35 NetLog::EventType event_type =
37 (k == 0) ? NetLog::TYPE_AUTH_PROXY : NetLog::TYPE_AUTH_SERVER; 36 (k == 0) ? NetLog::TYPE_AUTH_PROXY : NetLog::TYPE_AUTH_SERVER;
38 HttpAuth::ChallengeTokenizer tokenizer( 37 HttpAuth::ChallengeTokenizer tokenizer(
39 challenge.begin(), challenge.end()); 38 challenge.begin(), challenge.end());
40 HttpAuthHandlerMock mock_handler; 39 HttpAuthHandlerMock mock_handler;
41 CapturingNetLog capturing_net_log(CapturingNetLog::kUnbounded); 40 CapturingNetLog capturing_net_log(CapturingNetLog::kUnbounded);
42 BoundNetLog bound_net_log(source, &capturing_net_log); 41 BoundNetLog bound_net_log(source, &capturing_net_log);
43 42
44 mock_handler.InitFromChallenge(&tokenizer, target, 43 mock_handler.InitFromChallenge(&tokenizer, target,
45 origin, bound_net_log); 44 origin, bound_net_log);
46 mock_handler.SetGenerateExpectation(async, rv); 45 mock_handler.SetGenerateExpectation(async, rv);
47 mock_handler.GenerateAuthToken(&username, &password, &request, 46 mock_handler.GenerateAuthToken(&credentials, &request,
48 &test_callback, &auth_token); 47 &test_callback, &auth_token);
49 if (async) 48 if (async)
50 test_callback.WaitForResult(); 49 test_callback.WaitForResult();
51 50
52 net::CapturingNetLog::EntryList entries; 51 net::CapturingNetLog::EntryList entries;
53 capturing_net_log.GetEntries(&entries); 52 capturing_net_log.GetEntries(&entries);
54 53
55 EXPECT_EQ(2u, entries.size()); 54 EXPECT_EQ(2u, entries.size());
56 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, event_type)); 55 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, event_type));
57 EXPECT_TRUE(LogContainsEndEvent(entries, 1, event_type)); 56 EXPECT_TRUE(LogContainsEndEvent(entries, 1, event_type));
58 } 57 }
59 } 58 }
60 } 59 }
61 } 60 }
62 61
63 } // namespace net 62 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698