1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/http/http_log_util.h"
6 #include "testing/gtest/include/gtest/gtest.h"
10 TEST(HttpLogUtilTest
, ElideHeaderValueForNetLog
) {
11 // Only elide for appropriate log level.
12 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
13 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "Cookie", "name=value"));
14 EXPECT_EQ("name=value", ElideHeaderValueForNetLog(
15 net::NetLog::LOG_ALL_BUT_BYTES
, "Cookie", "name=value"));
17 // Headers are compared case insensitively.
18 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
19 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "cOoKiE", "name=value"));
21 // These headers should be completely elided.
22 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
23 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "Set-Cookie", "name=value"));
24 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
25 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "Set-Cookie2", "name=value"));
26 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
27 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "Authorization", "Basic 1234"));
28 #if !defined(SPDY_PROXY_AUTH_ORIGIN)
29 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog(
30 net::NetLog::LOG_STRIP_PRIVATE_DATA
,
31 "Proxy-Authorization", "Basic 1234"));
34 // Unknown headers should pass through.
35 EXPECT_EQ("value", ElideHeaderValueForNetLog(
36 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "Boring", "value"));
38 // Basic and Digest auth challenges are public.
39 EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog(
40 net::NetLog::LOG_STRIP_PRIVATE_DATA
,
41 "WWW-Authenticate", "Basic realm=test"));
42 EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog(
43 net::NetLog::LOG_STRIP_PRIVATE_DATA
,
44 "WWW-Authenticate", "Digest realm=test"));
45 #if !defined(SPDY_PROXY_AUTH_ORIGIN)
46 EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog(
47 net::NetLog::LOG_STRIP_PRIVATE_DATA
,
48 "Proxy-Authenticate", "Basic realm=test"));
49 EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog(
50 net::NetLog::LOG_STRIP_PRIVATE_DATA
,
51 "Proxy-Authenticate", "Digest realm=test"));
54 // Multi-round mechanisms partially elided.
55 EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog(
56 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "WWW-Authenticate", "NTLM 1234"));
57 #if !defined(SPDY_PROXY_AUTH_ORIGIN)
58 EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog(
59 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "Proxy-Authenticate", "NTLM 1234"));
62 // Leave whitespace intact.
63 EXPECT_EQ("NTLM [4 bytes were stripped] ", ElideHeaderValueForNetLog(
64 net::NetLog::LOG_STRIP_PRIVATE_DATA
, "WWW-Authenticate", "NTLM 1234 "));
66 // Extra elisions for SPDY_PROXY_AUTH_ORIGIN.
67 #if defined(SPDY_PROXY_AUTH_ORIGIN)
68 EXPECT_EQ("[elided]", ElideHeaderValueForNetLog(
69 net::NetLog::LOG_ALL_BUT_BYTES
,
70 "Proxy-Authenticate", "Basic realm=test"));
71 EXPECT_EQ("[elided]", ElideHeaderValueForNetLog(
72 net::NetLog::LOG_ALL_BUT_BYTES
, "Proxy-Authorization", "Basic 1234"));