From c9a8ebc2e62b4f3e12854144dc7faba2f972b002 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 20 Jan 2017 20:15:49 -0800 Subject: [PATCH] Create anonymous hash to detect issue duplication --- src/NzbDrone.Common.Test/HashUtilFixture.cs | 21 +++++++++++++++++++ .../NzbDrone.Common.Test.csproj | 1 + src/NzbDrone.Common/HashUtil.cs | 8 ++++++- .../Sentry/MachineNameUserFactory.cs | 3 +-- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/NzbDrone.Common.Test/HashUtilFixture.cs diff --git a/src/NzbDrone.Common.Test/HashUtilFixture.cs b/src/NzbDrone.Common.Test/HashUtilFixture.cs new file mode 100644 index 000000000..02869fa24 --- /dev/null +++ b/src/NzbDrone.Common.Test/HashUtilFixture.cs @@ -0,0 +1,21 @@ +using FluentAssertions; +using NUnit.Framework; + +namespace NzbDrone.Common.Test +{ + [TestFixture] + public class HashUtilFixture + { + [Test] + public void should_create_anon_id() + { + HashUtil.AnonymousToken().Should().NotBeNullOrEmpty(); + } + + [Test] + public void should_create_the_same_id() + { + HashUtil.AnonymousToken().Should().Be(HashUtil.AnonymousToken()); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index eac513244..bd34c1e63 100644 --- a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -84,6 +84,7 @@ + diff --git a/src/NzbDrone.Common/HashUtil.cs b/src/NzbDrone.Common/HashUtil.cs index 062e561c1..d826324f3 100644 --- a/src/NzbDrone.Common/HashUtil.cs +++ b/src/NzbDrone.Common/HashUtil.cs @@ -24,7 +24,13 @@ public static string CalculateCrc(string input) } } } - return string.Format("{0:x8}", mCrc); + return $"{mCrc:x8}"; + } + + public static string AnonymousToken() + { + var seed = $"{Environment.ProcessorCount}_{Environment.OSVersion.Platform}_{Environment.MachineName}_{Environment.UserName}"; + return HashUtil.CalculateCrc(seed); } } } \ No newline at end of file diff --git a/src/NzbDrone.Common/Instrumentation/Sentry/MachineNameUserFactory.cs b/src/NzbDrone.Common/Instrumentation/Sentry/MachineNameUserFactory.cs index b9c92c880..59e892542 100644 --- a/src/NzbDrone.Common/Instrumentation/Sentry/MachineNameUserFactory.cs +++ b/src/NzbDrone.Common/Instrumentation/Sentry/MachineNameUserFactory.cs @@ -1,4 +1,3 @@ -using System; using SharpRaven.Data; namespace NzbDrone.Common.Instrumentation.Sentry @@ -7,7 +6,7 @@ public class MachineNameUserFactory : ISentryUserFactory { public SentryUser Create() { - return new SentryUser(Environment.MachineName); + return new SentryUser(HashUtil.AnonymousToken()); } } } \ No newline at end of file