| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_log_util.h" | 5 #include "net/http/http_log_util.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace net { | 8 namespace net { |
| 9 | 9 |
| 10 TEST(HttpLogUtilTest, ElideHeaderValueForNetLog) { | 10 TEST(HttpLogUtilTest, ElideHeaderValueForNetLog) { |
| 11 // Only elide for appropriate log level. | 11 // Only elide for appropriate log level. |
| 12 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( | 12 EXPECT_EQ("[10 bytes were stripped]", |
| 13 NetLog::LOG_STRIP_PRIVATE_DATA, "Cookie", "name=value")); | 13 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), "Cookie", |
| 14 "name=value")); |
| 14 EXPECT_EQ("name=value", ElideHeaderValueForNetLog( | 15 EXPECT_EQ("name=value", ElideHeaderValueForNetLog( |
| 15 NetLog::LOG_ALL_BUT_BYTES, "Cookie", "name=value")); | 16 NetLogCaptureMode::IncludeCookiesAndCredentials(), |
| 17 "Cookie", "name=value")); |
| 16 | 18 |
| 17 // Headers are compared case insensitively. | 19 // Headers are compared case insensitively. |
| 18 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( | 20 EXPECT_EQ("[10 bytes were stripped]", |
| 19 NetLog::LOG_STRIP_PRIVATE_DATA, "cOoKiE", "name=value")); | 21 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), "cOoKiE", |
| 22 "name=value")); |
| 20 | 23 |
| 21 // These headers should be completely elided. | 24 // These headers should be completely elided. |
| 22 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( | 25 EXPECT_EQ("[10 bytes were stripped]", |
| 23 NetLog::LOG_STRIP_PRIVATE_DATA, "Set-Cookie", "name=value")); | 26 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 24 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( | 27 "Set-Cookie", "name=value")); |
| 25 NetLog::LOG_STRIP_PRIVATE_DATA, "Set-Cookie2", "name=value")); | 28 EXPECT_EQ("[10 bytes were stripped]", |
| 26 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( | 29 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 27 NetLog::LOG_STRIP_PRIVATE_DATA, "Authorization", "Basic 1234")); | 30 "Set-Cookie2", "name=value")); |
| 28 EXPECT_EQ("[10 bytes were stripped]", ElideHeaderValueForNetLog( | 31 EXPECT_EQ("[10 bytes were stripped]", |
| 29 NetLog::LOG_STRIP_PRIVATE_DATA, "Proxy-Authorization", "Basic 1234")); | 32 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 33 "Authorization", "Basic 1234")); |
| 34 EXPECT_EQ("[10 bytes were stripped]", |
| 35 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 36 "Proxy-Authorization", "Basic 1234")); |
| 30 | 37 |
| 31 // Unknown headers should pass through. | 38 // Unknown headers should pass through. |
| 32 EXPECT_EQ("value", ElideHeaderValueForNetLog( | 39 EXPECT_EQ("value", ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 33 NetLog::LOG_STRIP_PRIVATE_DATA, "Boring", "value")); | 40 "Boring", "value")); |
| 34 | 41 |
| 35 // Basic and Digest auth challenges are public. | 42 // Basic and Digest auth challenges are public. |
| 43 EXPECT_EQ("Basic realm=test", |
| 44 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 45 "WWW-Authenticate", "Basic realm=test")); |
| 46 EXPECT_EQ("Digest realm=test", |
| 47 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 48 "WWW-Authenticate", "Digest realm=test")); |
| 36 EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog( | 49 EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog( |
| 37 NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "Basic realm=test")); | 50 NetLogCaptureMode::Default(), |
| 38 EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog( | 51 "Proxy-Authenticate", "Basic realm=test")); |
| 39 NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "Digest realm=test")); | 52 EXPECT_EQ( |
| 40 EXPECT_EQ("Basic realm=test", ElideHeaderValueForNetLog( | 53 "Digest realm=test", |
| 41 NetLog::LOG_STRIP_PRIVATE_DATA, | 54 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 42 "Proxy-Authenticate", "Basic realm=test")); | 55 "Proxy-Authenticate", "Digest realm=test")); |
| 43 EXPECT_EQ("Digest realm=test", ElideHeaderValueForNetLog( | |
| 44 NetLog::LOG_STRIP_PRIVATE_DATA, | |
| 45 "Proxy-Authenticate", "Digest realm=test")); | |
| 46 | 56 |
| 47 // Multi-round mechanisms partially elided. | 57 // Multi-round mechanisms partially elided. |
| 48 EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog( | 58 EXPECT_EQ("NTLM [4 bytes were stripped]", |
| 49 NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "NTLM 1234")); | 59 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 50 EXPECT_EQ("NTLM [4 bytes were stripped]", ElideHeaderValueForNetLog( | 60 "WWW-Authenticate", "NTLM 1234")); |
| 51 NetLog::LOG_STRIP_PRIVATE_DATA, "Proxy-Authenticate", "NTLM 1234")); | 61 EXPECT_EQ("NTLM [4 bytes were stripped]", |
| 62 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 63 "Proxy-Authenticate", "NTLM 1234")); |
| 52 | 64 |
| 53 // Leave whitespace intact. | 65 // Leave whitespace intact. |
| 54 EXPECT_EQ("NTLM [4 bytes were stripped] ", ElideHeaderValueForNetLog( | 66 EXPECT_EQ("NTLM [4 bytes were stripped] ", |
| 55 NetLog::LOG_STRIP_PRIVATE_DATA, "WWW-Authenticate", "NTLM 1234 ")); | 67 ElideHeaderValueForNetLog(NetLogCaptureMode::Default(), |
| 68 "WWW-Authenticate", "NTLM 1234 ")); |
| 56 } | 69 } |
| 57 | 70 |
| 58 } // namspace net | 71 } // namspace net |
| OLD | NEW |