Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphofmann committed Feb 13, 2024
1 parent b56fe6e commit a1bbd7b
Show file tree
Hide file tree
Showing 7 changed files with 953 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

- Finish TTID span when transaction finishes (#3610)
- Dont take screenshot and view hierarchy for app hanging (#3620)
- Remove `free_storage` and `total_storage` from the app context (#3627), because Apple forbids sending
- Remove `free_storage` and `storage_size` from the device context (#3627), because Apple forbids sending
information retrieved via `NSFileSystemFreeSize` and `NSFileSystemSize` off a device; see
[Apple docs](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api?language=objc).

Expand Down
2 changes: 2 additions & 0 deletions Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "NO"
enableThreadSanitizer = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
Expand Down Expand Up @@ -100,6 +101,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableThreadSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
// applicable
[self removeExtraDeviceContextFromEvent:event];
} else if (!isCrashEvent) {
// Store the current free memory, free storage, battery level and more mutable properties,
// Store the current free memory battery level and more mutable properties,
// at the time of this event, but not for crashes as the current data isn't guaranteed to be
// the same as when the app crashed.
[self applyExtraDeviceContextToEvent:event];
Expand Down
40 changes: 39 additions & 1 deletion Sources/Sentry/SentryCrashReportConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ - (SentryEvent *_Nullable)convertReportToEvent

event.dist = self.userContext[@"dist"];
event.environment = self.userContext[@"environment"];
event.context = self.userContext[@"context"];

NSMutableDictionary<NSString *, id> *userContext =
[[NSMutableDictionary alloc] initWithDictionary:self.userContext[@"context"]];
NSMutableDictionary<NSString *, id> *deviceContext =
[[NSMutableDictionary alloc] initWithDictionary:userContext[@"device"]];
[deviceContext removeObjectForKey:@"storage_size"];
[deviceContext removeObjectForKey:@"free_storage"];

event.context = [self filteredUserContextContext];
event.extra = self.userContext[@"extra"];
event.tags = self.userContext[@"tags"];
// event.level we do not set the level here since this always resulted
Expand Down Expand Up @@ -147,6 +155,36 @@ - (SentryEvent *_Nullable)convertReportToEvent
return nil;
}

/**
* storage_size and free_storage used `NSFileSystemFreeSize` and `NSFileSystemSize` internally,
* which Apple forbids sending off device; see
* https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api?language=objc
* While current crash reports no longer include this information, we want to remove it from older
* crash reports to respect Apple's privacy policy, which is mentioned in the link above.
*/
- (NSDictionary<NSString *, id> *)filteredUserContextContext
{
if (self.userContext[@"context"] == nil) {
return nil;
}

NSMutableDictionary<NSString *, id> *context =
[[NSMutableDictionary alloc] initWithDictionary:self.userContext[@"context"]];

if (context[@"device"] == nil) {
return context;
}

NSMutableDictionary<NSString *, id> *deviceContext =
[[NSMutableDictionary alloc] initWithDictionary:context[@"device"]];
[deviceContext removeObjectForKey:@"storage_size"];
[deviceContext removeObjectForKey:@"free_storage"];

context[@"device"] = deviceContext;

return context;
}

- (SentryUser *_Nullable)convertUser
{
SentryUser *user = nil;
Expand Down
Loading

0 comments on commit a1bbd7b

Please sign in to comment.