123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// found in the LICENSE file.
423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "net/http/http_log_util.h"
623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)namespace net {
923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
1023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)TEST(HttpLogUtilTest, ElideHeaderValueForNetLog) {
1123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Only elide for appropriate log level.
1223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "Cookie", "name=value"));
1423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("name=value", ElideHeaderValueForNetLog(
15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_ALL_BUT_BYTES, "Cookie", "name=value"));
1623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
1723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Headers are compared case insensitively.
1823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "cOoKiE", "name=value"));
2023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
2123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // These headers should be completely elided.
2223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "Set-Cookie", "name=value"));
2423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "Set-Cookie2", "name=value"));
2623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "Authorization", "Basic 1234"));
2823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "Proxy-Authorization", "Basic 1234"));
3023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
3123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Unknown headers should pass through.
3223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("value", ElideHeaderValueForNetLog(
33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "Boring", "value"));
3423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
3523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Basic and Digest auth challenges are public.
3623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog(
37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "Basic realm=test"));
3823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog(
39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "Digest realm=test"));
4023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog(
41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA,
4223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      "Proxy-Authenticate", "Basic realm=test"));
4323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog(
44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA,
4523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      "Proxy-Authenticate", "Digest realm=test"));
4623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
4723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Multi-round mechanisms partially elided.
4823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog(
49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "NTLM 1234"));
5023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog(
51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "Proxy-Authenticate", "NTLM 1234"));
5223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
5323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Leave whitespace intact.
5423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  EXPECT_EQ("NTLM  [4 bytes were stripped] ", ElideHeaderValueForNetLog(
55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "NTLM  1234 "));
5623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)}
5723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
5823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)}  // namspace net
59