[email protected] | fba65f7b | 2012-03-15 05:22:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/http/http_auth_handler.h" |
| 6 | |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 7 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 8 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 9 | #include "net/base/net_errors.h" |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 10 | #include "net/base/test_completion_callback.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 12 | #include "net/http/http_auth_handler_mock.h" |
| 13 | #include "net/http/http_request_info.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 15 | #include "net/log/test_net_log_entry.h" |
| 16 | #include "net/log/test_net_log_util.h" |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 17 | #include "testing/gtest/include/gtest/gtest.h" |
| 18 | |
| 19 | namespace net { |
| 20 | |
| 21 | TEST(HttpAuthHandlerTest, NetLog) { |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 22 | GURL origin("http://www.example.com"); |
| 23 | std::string challenge = "Mock asdf"; |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 24 | AuthCredentials credentials(base::ASCIIToUTF16("user"), |
| 25 | base::ASCIIToUTF16("pass")); |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 26 | std::string auth_token; |
| 27 | HttpRequestInfo request; |
| 28 | |
| 29 | for (int i = 0; i < 2; ++i) { |
| 30 | bool async = (i == 0); |
| 31 | for (int j = 0; j < 2; ++j) { |
| 32 | int rv = (j == 0) ? OK : ERR_UNEXPECTED; |
| 33 | for (int k = 0; k < 2; ++k) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 34 | TestCompletionCallback test_callback; |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 35 | HttpAuth::Target target = |
| 36 | (k == 0) ? HttpAuth::AUTH_PROXY : HttpAuth::AUTH_SERVER; |
| 37 | NetLog::EventType event_type = |
| 38 | (k == 0) ? NetLog::TYPE_AUTH_PROXY : NetLog::TYPE_AUTH_SERVER; |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 39 | HttpAuthChallengeTokenizer tokenizer( |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 40 | challenge.begin(), challenge.end()); |
| 41 | HttpAuthHandlerMock mock_handler; |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 42 | TestNetLog test_net_log; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 43 | BoundNetLog bound_net_log( |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 44 | BoundNetLog::Make(&test_net_log, NetLog::SOURCE_NONE)); |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 45 | |
| 46 | mock_handler.InitFromChallenge(&tokenizer, target, |
| 47 | origin, bound_net_log); |
| 48 | mock_handler.SetGenerateExpectation(async, rv); |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 49 | mock_handler.GenerateAuthToken(&credentials, &request, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 50 | test_callback.callback(), &auth_token); |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 51 | if (async) |
| 52 | test_callback.WaitForResult(); |
| 53 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 54 | TestNetLogEntry::List entries; |
| 55 | test_net_log.GetEntries(&entries); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 56 | |
| 57 | EXPECT_EQ(2u, entries.size()); |
| 58 | EXPECT_TRUE(LogContainsBeginEvent(entries, 0, event_type)); |
| 59 | EXPECT_TRUE(LogContainsEndEvent(entries, 1, event_type)); |
[email protected] | 7775c7d | 2010-06-21 17:50:21 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | } // namespace net |