blob: 5757bb65c84d37411ae2720df16c6dbcdf95fa47 [file] [log] [blame]
[email protected]fba65f7b2012-03-15 05:22:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7775c7d2010-06-21 17:50:212// 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]125ef482013-06-11 18:32:477#include "base/strings/string_util.h"
[email protected]750b2f3c2013-06-07 18:41:058#include "base/strings/utf_string_conversions.h"
[email protected]7775c7d2010-06-21 17:50:219#include "net/base/net_errors.h"
[email protected]7775c7d2010-06-21 17:50:2110#include "net/base/test_completion_callback.h"
[email protected]df41d0d82014-03-13 00:43:2411#include "net/http/http_auth_challenge_tokenizer.h"
[email protected]7775c7d2010-06-21 17:50:2112#include "net/http/http_auth_handler_mock.h"
13#include "net/http/http_request_info.h"
vishal.b62985ca92015-04-17 08:45:5114#include "net/log/test_net_log.h"
mmenke43758e62015-05-04 21:09:4615#include "net/log/test_net_log_entry.h"
16#include "net/log/test_net_log_util.h"
[email protected]7775c7d2010-06-21 17:50:2117#include "testing/gtest/include/gtest/gtest.h"
18
19namespace net {
20
21TEST(HttpAuthHandlerTest, NetLog) {
[email protected]7775c7d2010-06-21 17:50:2122 GURL origin("http://www.example.com");
23 std::string challenge = "Mock asdf";
[email protected]ad65a3e2013-12-25 18:18:0124 AuthCredentials credentials(base::ASCIIToUTF16("user"),
25 base::ASCIIToUTF16("pass"));
[email protected]7775c7d2010-06-21 17:50:2126 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]49639fa2011-12-20 23:22:4134 TestCompletionCallback test_callback;
[email protected]7775c7d2010-06-21 17:50:2135 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]df41d0d82014-03-13 00:43:2439 HttpAuthChallengeTokenizer tokenizer(
[email protected]7775c7d2010-06-21 17:50:2140 challenge.begin(), challenge.end());
41 HttpAuthHandlerMock mock_handler;
mmenke43758e62015-05-04 21:09:4642 TestNetLog test_net_log;
ttuttle859dc7a2015-04-23 19:42:2943 BoundNetLog bound_net_log(
mmenke43758e62015-05-04 21:09:4644 BoundNetLog::Make(&test_net_log, NetLog::SOURCE_NONE));
[email protected]7775c7d2010-06-21 17:50:2145
46 mock_handler.InitFromChallenge(&tokenizer, target,
47 origin, bound_net_log);
48 mock_handler.SetGenerateExpectation(async, rv);
[email protected]f3cf9802011-10-28 18:44:5849 mock_handler.GenerateAuthToken(&credentials, &request,
[email protected]49639fa2011-12-20 23:22:4150 test_callback.callback(), &auth_token);
[email protected]7775c7d2010-06-21 17:50:2151 if (async)
52 test_callback.WaitForResult();
53
mmenke43758e62015-05-04 21:09:4654 TestNetLogEntry::List entries;
55 test_net_log.GetEntries(&entries);
[email protected]b2fcd0e2010-12-01 15:19:4056
57 EXPECT_EQ(2u, entries.size());
58 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, event_type));
59 EXPECT_TRUE(LogContainsEndEvent(entries, 1, event_type));
[email protected]7775c7d2010-06-21 17:50:2160 }
61 }
62 }
63}
64
65} // namespace net