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 @@ namespace NzbDrone.Common } } } - 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 @@ namespace NzbDrone.Common.Instrumentation.Sentry { public SentryUser Create() { - return new SentryUser(Environment.MachineName); + return new SentryUser(HashUtil.AnonymousToken()); } } } \ No newline at end of file