Skip to content

Commit

Permalink
Merge 137f007 into 8b1c6a9
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin authored Sep 4, 2024
2 parents 8b1c6a9 + 137f007 commit 79cfb9b
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 15 deletions.
14 changes: 14 additions & 0 deletions Samples/iOS-Swift/iOS-Swift-UITests/LaunchUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ class LaunchUITests: BaseUITest {
XCTAssertTrue(0.5 > frozenFramesPercentage, "Too many frozen frames.")
}

func testCorruptEnvelope() {
// This is to prevent https://github.com/getsentry/sentry-cocoa/issues/4280
// Tapping "Corrupt Envelope" will try to capture an envelope but it closes the app
// in the middle of the process. For 8.33.0 this would generate a corrupted envelope.
// 8.35.0 does not write the envelope to disk at all.
// By opening the app again we can check whether the SDK can handle such scenario.
app.buttons["Corrupt Envelope"].tap()
XCTAssertEqual(app.state, .notRunning)

app.launch()
XCTAssertEqual(app.state, .runningForeground)
app.tabBars.firstMatch.waitForExistence("App did not open again")
}

func testCheckTotalFrames() {
app.buttons["Extra"].tap()

Expand Down
2 changes: 2 additions & 0 deletions Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
D8269A42274C095F00BD5BD5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
D8269A49274C096000BD5BD5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D8269A5C274C108100BD5BD5 /* iOS13-Swift.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "iOS13-Swift.entitlements"; sourceTree = "<group>"; };
D82915932C889F1800A6CDD4 /* SentryCocoaPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SentryCocoaPrivate.h; sourceTree = "<group>"; };
D83A30DF279F1F5C00372D0A /* fatal-error-binary-images-message2.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "fatal-error-binary-images-message2.json"; path = "../../../Tests/Resources/fatal-error-binary-images-message2.json"; sourceTree = "<group>"; };
D840D520273A07F400CDF142 /* iOS-SwiftClip.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS-SwiftClip.app"; sourceTree = BUILT_PRODUCTS_DIR; };
D840D522273A07F400CDF142 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -608,6 +609,7 @@
D8F01DF02A1377D0008F4996 /* SentryExposure.h */,
D8832B192AF4FE2000C522B0 /* SentryUIApplication.h */,
629EC8AC2B0B537400858855 /* TriggerAppHang.swift */,
D82915932C889F1800A6CDD4 /* SentryCocoaPrivate.h */,
);
path = Tools;
sourceTree = "<group>";
Expand Down
32 changes: 20 additions & 12 deletions Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,13 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="40A-vG-dFA">
<rect key="frame" x="0.0" y="64" width="320" height="246.5"/>
<rect key="frame" x="0.0" y="64" width="320" height="268"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="fn9-mQ-2PY">
<rect key="frame" x="0.0" y="0.0" width="320" height="118.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="140"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" translatesAutoresizingMaskIntoConstraints="NO" id="Q2k-6Y-RnD">
<rect key="frame" x="0.0" y="0.0" width="160" height="118.5"/>
<rect key="frame" x="0.0" y="0.0" width="160" height="140"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NFC-V3-lgW">
<rect key="frame" x="0.0" y="0.0" width="160" height="28"/>
Expand All @@ -728,33 +728,41 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Llv-Yz-cwF">
<rect key="frame" x="0.0" y="30" width="160" height="28"/>
<rect key="frame" x="0.0" y="28" width="160" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Capture NSException"/>
<connections>
<action selector="captureNSException:" destination="QmU-DD-itF" eventType="touchUpInside" id="Gdl-wk-dUU"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wJ4-gS-64G" userLabel="fatalError">
<rect key="frame" x="0.0" y="60.5" width="160" height="28"/>
<rect key="frame" x="0.0" y="56" width="160" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Throw FatalError"/>
<connections>
<action selector="captureFatalError:" destination="QmU-DD-itF" eventType="touchUpInside" id="dM5-xq-lrm"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NYx-6R-0bb">
<rect key="frame" x="0.0" y="90.5" width="160" height="28"/>
<rect key="frame" x="0.0" y="84" width="160" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="OOM crash"/>
<connections>
<action selector="oomCrash:" destination="QmU-DD-itF" eventType="touchUpInside" id="U4n-XL-dJf"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rJk-dh-q7U">
<rect key="frame" x="0.0" y="112" width="160" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Corrupt Envelope"/>
<connections>
<action selector="corruptEnvelope:" destination="QmU-DD-itF" eventType="touchUpInside" id="5hY-Uf-cey"/>
</connections>
</button>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" translatesAutoresizingMaskIntoConstraints="NO" id="2CV-VI-MDY">
<rect key="frame" x="160" y="0.0" width="160" height="118.5"/>
<rect key="frame" x="160" y="0.0" width="160" height="140"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Zbo-2T-1Zm">
<rect key="frame" x="0.0" y="0.0" width="160" height="28"/>
Expand All @@ -766,15 +774,15 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="s6w-E3-5yE" userLabel="DiskWriteException">
<rect key="frame" x="0.0" y="28" width="160" height="28"/>
<rect key="frame" x="0.0" y="35" width="160" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="DiskWriteException"/>
<connections>
<action selector="diskWriteException:" destination="QmU-DD-itF" eventType="touchUpInside" id="p74-qC-kH7"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NNd-Ec-zXw">
<rect key="frame" x="0.0" y="56" width="160" height="28"/>
<rect key="frame" x="0.0" y="70.5" width="160" height="28"/>
<accessibility key="accessibilityConfiguration" label="crashTheApp"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<state key="normal" title="Crash the app"/>
Expand All @@ -783,7 +791,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wJs-Av-cg2">
<rect key="frame" x="0.0" y="84" width="160" height="34.5"/>
<rect key="frame" x="0.0" y="105.5" width="160" height="34.5"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Use-after-free"/>
<connections>
Expand All @@ -795,7 +803,7 @@
</subviews>
</stackView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="1zm-ho-TCr">
<rect key="frame" x="0.0" y="118.5" width="320" height="128"/>
<rect key="frame" x="0.0" y="140" width="320" height="128"/>
<constraints>
<constraint firstAttribute="height" constant="128" id="lc6-97-p3W"/>
</constraints>
Expand Down Expand Up @@ -1170,7 +1178,7 @@
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemGray5Color">
<color red="0.8980392157" green="0.8980392157" blue="0.91764705879999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.89803921568627454" green="0.89803921568627454" blue="0.91764705882352937" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
16 changes: 16 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,20 @@ class ErrorsViewController: UIViewController {
}
}
}

@IBAction func corruptEnvelope(_ sender: UIButton) {
class TestSentryEnvelopeItem: SentryEnvelopeItem {
override var header: SentryEnvelopeItemHeader {
SentryEnvelopeItemHeader(type: "test", length: 50)
}

override var data: Data {
defer { exit(0) }
return Data(repeating: 1, count: 100_000_000)
}
}

let envelope = SentryEnvelope(id: SentryId(uuid: UUID()), singleItem: TestSentryEnvelopeItem())
SentrySDK.capture(envelope)
}
}
32 changes: 32 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/Tools/SentryCocoaPrivate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#import <Foundation/Foundation.h>
#import <Sentry/Sentry.h>

NS_ASSUME_NONNULL_BEGIN

@interface SentryEnvelopeHeader : NSObject

- (instancetype)initWithId:(SentryId *_Nullable)eventId;

@property (nullable, nonatomic, copy) NSDate *sentAt;
@property (nullable, nonatomic, readonly, copy) SentryId *eventId;

@end

@interface SentryEnvelopeItem : NSObject

- (instancetype)initWithEvent:(SentryEvent *)event;

@property (nonatomic, readonly, strong) SentryEnvelopeItemHeader *header;
@property (nonatomic, readonly, strong) NSData *data;

@end

@interface SentryEnvelope : NSObject

@property (nonatomic, readonly, strong) SentryEnvelopeHeader *header;
@property (nonatomic, readonly, strong) NSArray<SentryEnvelopeItem *> *items;

- (instancetype)initWithId:(SentryId *_Nullable)id singleItem:(SentryEnvelopeItem *)item;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentryBenchmarking.h"
#import "SentryCocoaPrivate.h"
#import "SentryExposure.h"
#import "SentryUIApplication.h"
#import <Sentry/PrivateSentrySDKOnly.h>
Expand Down
4 changes: 2 additions & 2 deletions Samples/iOS-Swift/iOS13-Swift/SwiftUI.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SentrySwiftUI
import SwiftUI

struct SwiftUI: View {
struct SwiftUIView: View {
var body: some View {
SentryTracedView("SwiftUI View") {
Text("SwiftUI!")
Expand All @@ -11,6 +11,6 @@ struct SwiftUI: View {

struct SwiftUI_Previews: PreviewProvider {
static var previews: some View {
SwiftUI()
SwiftUIView()
}
}
2 changes: 1 addition & 1 deletion Samples/iOS-Swift/iOS13-Swift/SwiftUIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import UIKit

class SwiftUIViewController: UIViewController {

let swiftUIView = UIHostingController(rootView: SwiftUI())
let swiftUIView = UIHostingController(rootView: SwiftUIView())

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
2 changes: 2 additions & 0 deletions Samples/iOS-Swift/iOS13-Swift/iOS13-Swift-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import "SentryBenchmarking.h"
#import "SentryCocoaPrivate.h"
#import "SentryUIApplication.h"
#import <Sentry/PrivateSentrySDKOnly.h>
#import <Sentry/SentrySDK+Private.h>

0 comments on commit 79cfb9b

Please sign in to comment.