Skip to content

Commit

Permalink
Uniform IPAddress::ToSensitiveString() behavior (debug vs release).
Browse files Browse the repository at this point in the history
Having a function that changes its behavior based on the build
flavor (debug vs release) is error prone, especially if considered
that the behavior change invalidates the expectation from the function
name itself.

If this feature is required to improve debugging, it should be behind
a macro (for example WEBRTC_LOG_FULL_IP_ADDRESSES) enabled by an
explicit build configuration which is turned OFF by default.

Bug: None
Change-Id: Id7adafc67d1ae674a3dbb382b16ad9faea59eba6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215064
Reviewed-by: Harald Alvestrand <[email protected]>
Commit-Queue: Mirko Bonadei <[email protected]>
Cr-Commit-Position: refs/heads/master@{#33800}
  • Loading branch information
MirkoBonadei authored and Commit Bot committed Apr 21, 2021
1 parent 48171ec commit 1585587
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 21 deletions.
5 changes: 0 additions & 5 deletions rtc_base/ip_address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ std::string IPAddress::ToString() const {
}

std::string IPAddress::ToSensitiveString() const {
#if !defined(NDEBUG)
// Return non-stripped in debug.
return ToString();
#else
switch (family_) {
case AF_INET: {
std::string address = ToString();
Expand All @@ -176,7 +172,6 @@ std::string IPAddress::ToSensitiveString() const {
}
}
return std::string();
#endif
}

IPAddress IPAddress::Normalized() const {
Expand Down
6 changes: 0 additions & 6 deletions rtc_base/ip_address_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -938,15 +938,9 @@ TEST(IPAddressTest, TestToSensitiveString) {
EXPECT_EQ(kIPv4PublicAddrString, addr_v4.ToString());
EXPECT_EQ(kIPv6PublicAddrString, addr_v6.ToString());
EXPECT_EQ(kIPv6PublicAddr2String, addr_v6_2.ToString());
#if defined(NDEBUG)
EXPECT_EQ(kIPv4PublicAddrAnonymizedString, addr_v4.ToSensitiveString());
EXPECT_EQ(kIPv6PublicAddrAnonymizedString, addr_v6.ToSensitiveString());
EXPECT_EQ(kIPv6PublicAddr2AnonymizedString, addr_v6_2.ToSensitiveString());
#else
EXPECT_EQ(kIPv4PublicAddrString, addr_v4.ToSensitiveString());
EXPECT_EQ(kIPv6PublicAddrString, addr_v6.ToSensitiveString());
EXPECT_EQ(kIPv6PublicAddr2String, addr_v6_2.ToSensitiveString());
#endif // defined(NDEBUG)
}

TEST(IPAddressTest, TestInterfaceAddress) {
Expand Down
10 changes: 0 additions & 10 deletions rtc_base/socket_address_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,15 @@ TEST(SocketAddressTest, TestToSensitiveString) {
EXPECT_EQ("1.2.3.4", addr_v4.HostAsURIString());
EXPECT_EQ("1.2.3.4:5678", addr_v4.ToString());

#if defined(NDEBUG)
EXPECT_EQ("1.2.3.x", addr_v4.HostAsSensitiveURIString());
EXPECT_EQ("1.2.3.x:5678", addr_v4.ToSensitiveString());
#else
EXPECT_EQ("1.2.3.4", addr_v4.HostAsSensitiveURIString());
EXPECT_EQ("1.2.3.4:5678", addr_v4.ToSensitiveString());
#endif // defined(NDEBUG)

SocketAddress addr_v6(kTestV6AddrString, 5678);
EXPECT_EQ("[" + kTestV6AddrString + "]", addr_v6.HostAsURIString());
EXPECT_EQ(kTestV6AddrFullString, addr_v6.ToString());
#if defined(NDEBUG)
EXPECT_EQ("[" + kTestV6AddrAnonymizedString + "]",
addr_v6.HostAsSensitiveURIString());
EXPECT_EQ(kTestV6AddrFullAnonymizedString, addr_v6.ToSensitiveString());
#else
EXPECT_EQ("[" + kTestV6AddrString + "]", addr_v6.HostAsSensitiveURIString());
EXPECT_EQ(kTestV6AddrFullString, addr_v6.ToSensitiveString());
#endif // defined(NDEBUG)
}

} // namespace rtc

0 comments on commit 1585587

Please sign in to comment.