Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added UI Test to check invalid envelope is handled correct #4312

Merged
merged 9 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 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,15 @@ class LaunchUITests: BaseUITest {
XCTAssertTrue(0.5 > frozenFramesPercentage, "Too many frozen frames.")
}

func testCorruptEnvelope() {
brustolin marked this conversation as resolved.
Show resolved Hide resolved
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
Loading