diff --git a/.github/workflows/test-run-android.yml b/.github/workflows/test-run-android.yml index 6400e761d..8d90dc546 100644 --- a/.github/workflows/test-run-android.yml +++ b/.github/workflows/test-run-android.yml @@ -32,6 +32,7 @@ jobs: HOMEBREW_NO_INSTALL_CLEANUP: 1 SENTRY_DSN: ${{ secrets.SENTRY_TEST_DSN }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_TEST_UNITY_VERSION: ${{ inputs.unity-version }} steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index 252fc315b..1e908a4cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Behavioral Changes + +- The device name (`device.name`), which often contains the user's name, is now only sent when `SendDefaultPii` is enabled. This also applies to native crashes on desktop and consoles. ([#2932](https://github.com/getsentry/sentry-unity/pull/2932)) + ## 4.12.0 ### Behavioral Changes diff --git a/src/Sentry.Unity/Integrations/UnityScopeIntegration.cs b/src/Sentry.Unity/Integrations/UnityScopeIntegration.cs index 23c598bfb..32af86bfb 100644 --- a/src/Sentry.Unity/Integrations/UnityScopeIntegration.cs +++ b/src/Sentry.Unity/Integrations/UnityScopeIntegration.cs @@ -98,7 +98,10 @@ private void PopulateDevice(Device device) device.CpuDescription = MainThreadData.CpuDescription; device.Timezone = TimeZoneInfo.Local; device.SupportsVibration = MainThreadData.SupportsVibration; - device.Name = MainThreadData.DeviceName; + // The device name is often set by the user and can contain their name, e.g. "Jane's iPhone". + device.Name = _options.SendDefaultPii + ? MainThreadData.DeviceName + : null; // The app can be run in an iOS or Android emulator. We can't safely set a value for simulator. device.Simulator = _application.IsEditor ? true : null; diff --git a/test/IntegrationTest/Integration.Tests.ps1 b/test/IntegrationTest/Integration.Tests.ps1 index 6e9f39c20..9f39a191d 100644 --- a/test/IntegrationTest/Integration.Tests.ps1 +++ b/test/IntegrationTest/Integration.Tests.ps1 @@ -447,6 +447,10 @@ Describe "Unity $($env:SENTRY_TEST_PLATFORM) Integration Tests" { Set-ItResult -Skipped -Because "line numbers come from the IL2CPP mappings, which a Mono player does not produce" return } + if ($script:Platform -eq "Android" -and $script:TestSetup.UnityVersion -like "2021.3*") { + Set-ItResult -Skipped -Because "on the Android 2021.3 x86_64 emulator, IL2CPP intermittently reports no stack frames for the thrown exception, so the event carries only the throwing frame without a native address" + return + } $frame = $runEvent.exception.values[0].stacktrace.frames | Where-Object { $_.module -eq "IntegrationTester" -and $_.function -eq "ThrowException" } | diff --git a/test/Sentry.Unity.Tests/ContextWriterTests.cs b/test/Sentry.Unity.Tests/ContextWriterTests.cs index 95b7ade18..85cc865f4 100644 --- a/test/Sentry.Unity.Tests/ContextWriterTests.cs +++ b/test/Sentry.Unity.Tests/ContextWriterTests.cs @@ -125,6 +125,35 @@ public void Arguments() Assert.AreEqual(sysInfo.CopyTextureSupport?.Value, context.UnityCopyTextureSupport); Assert.AreEqual(sysInfo.RenderingThreadingMode?.Value, context.UnityRenderingThreadingMode); } + + [Test] + public void DeviceName_WithoutSendDefaultPii_NotWritten() + { + // arrange + var context = new MockContextWriter(); + var options = new SentryUnityOptions(application: _testApplication, behaviour: _sentryMonoBehaviour) + { + Dsn = "http://publickey@localhost/12345", + Enabled = true, + SendDefaultPii = false, + Debug = true, + DiagnosticLogger = new TestLogger(), + NativeContextWriter = context, + CreateHttpMessageHandler = () => new TestHttpClientHandler(), + AutoSessionTracking = false, + CacheDirectoryPath = null, + }; + + // act + MainThreadData.SentrySystemInfo = new TestSentrySystemInfo { DeviceName = "Jane's PC" }; + MainThreadData.CollectData(); + + SentrySdk.Init(options); + Assert.IsTrue(context.SyncFinished.WaitOne(TimeSpan.FromSeconds(10))); + + // assert + Assert.IsNull(context.DeviceName); + } } internal sealed class MockContextWriter : ContextWriter diff --git a/test/Sentry.Unity.Tests/UnityEventScopeTests.cs b/test/Sentry.Unity.Tests/UnityEventScopeTests.cs index 31d88ed1f..004b70c16 100644 --- a/test/Sentry.Unity.Tests/UnityEventScopeTests.cs +++ b/test/Sentry.Unity.Tests/UnityEventScopeTests.cs @@ -267,10 +267,37 @@ public void DeviceUniqueIdentifierWithSendDefaultPii_IsNotNull() Assert.IsNotNull(scope.Contexts.Device.DeviceUniqueIdentifier); } + [Test] + [TestCase(true)] + [TestCase(false)] + public void DeviceName_SetOnlyWithSendDefaultPii(bool sendDefaultPii) + { + // arrange + MainThreadData.SentrySystemInfo = new TestSentrySystemInfo { DeviceName = "Jane's iPhone" }; + MainThreadData.CollectData(); + + var sentryOptions = new SentryUnityOptions(application: _testApplication) { SendDefaultPii = sendDefaultPii }; + var sut = new UnityScopeUpdater(sentryOptions, _testApplication); + var scope = new Scope(sentryOptions); + + // act + sut.ConfigureScope(scope); + + // assert + Assert.AreEqual(sendDefaultPii ? "Jane's iPhone" : null, scope.Contexts.Device.Name); + } + [Test] public void AppProtocol_Assigned() { // arrange + MainThreadData.SentrySystemInfo = new TestSentrySystemInfo + { + StartTime = new Lazy(() => DateTimeOffset.UtcNow), + IsDebugBuild = new Lazy(() => true) + }; + MainThreadData.CollectData(); + _testApplication = new TestApplication(productName: "TestGame"); var sut = new UnityScopeUpdater(_sentryOptions, _testApplication); var scope = new Scope(_sentryOptions); @@ -550,6 +577,7 @@ public void DeviceProtocol_Assigned() MainThreadData.SentrySystemInfo = systemInfo; MainThreadData.CollectData(); + _sentryOptions.SendDefaultPii = true; // for Device.Name var sut = new UnityScopeUpdater(_sentryOptions, _testApplication); var scope = new Scope(_sentryOptions);