diff --git a/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs b/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs index 60f7b0c86..fb8870dc3 100644 --- a/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs +++ b/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs @@ -51,5 +51,26 @@ namespace NzbDrone.Common.Test.InstrumentationTests cleansedMessage.Should().NotContain("mySecret"); cleansedMessage.Should().NotContain("01233210"); } + + [TestCase(@"Some message (from 32.2.3.5 user agent)")] + [TestCase(@"Auth-Invalidated ip 32.2.3.5")] + [TestCase(@"Auth-Success ip 32.2.3.5")] + [TestCase(@"Auth-Logout ip 32.2.3.5")] + public void should_clean_ipaddress(string message) + { + var cleansedMessage = CleanseLogMessage.Cleanse(message); + + cleansedMessage.Should().NotContain(".2.3."); + } + + [TestCase(@"Some message (from 10.2.3.2 user agent)")] + [TestCase(@"Auth-Unauthorized ip 32.2.3.5")] + [TestCase(@"Auth-Failure ip 32.2.3.5")] + public void should_not_clean_ipaddress(string message) + { + var cleansedMessage = CleanseLogMessage.Cleanse(message); + + cleansedMessage.Should().Be(message); + } } } diff --git a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs index c7788f31d..42a540b49 100644 --- a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs +++ b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Linq; +using System.Net; using System.Text.RegularExpressions; using NzbDrone.Common.Extensions; @@ -41,6 +43,8 @@ namespace NzbDrone.Common.Instrumentation new Regex(@"(?<=\?|&)(authkey|torrent_pass)=(?[^&=]+?)(?=""|&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase) }; + private static readonly Regex CleanseRemoteIPRegex = new Regex(@"(?:Auth-\w+(?