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

internal(hybrid): Add Replay Mask options to dict init #4492

Merged
merged 7 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Improve frames tracker performance (#4469)
- Log a warning when dropping envelopes due to rate-limiting (#4463)
- Expose `SentrySessionReplayIntegration-Hybrid.h` as `private` (#4486)
- Add `maskedViewClasses` and `unmaskedViewClasses` to SentryReplayOptions init via dict (#4492)

## 8.39.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,11 @@ public class SentryReplayOptions: NSObject, SentryRedactOptions {
let maskAllText = (dictionary["maskAllText"] as? NSNumber)?.boolValue ?? true
let maskAllImages = (dictionary["maskAllImages"] as? NSNumber)?.boolValue ?? true
self.init(sessionSampleRate: sessionSampleRate, onErrorSampleRate: onErrorSampleRate, maskAllText: maskAllText, maskAllImages: maskAllImages)
self.maskedViewClasses = ((dictionary["maskedViewClasses"] as? NSArray) ?? []).compactMap({ element in
NSClassFromString((element as? String) ?? "")
})
self.unmaskedViewClasses = ((dictionary["unmaskedViewClasses"] as? NSArray) ?? []).compactMap({ element in
NSClassFromString((element as? String) ?? "")
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,155 @@ class SentryReplayOptionsTests: XCTestCase {
XCTAssertEqual(options.replayBitRate, 60_000)
XCTAssertEqual(options.sizeScale, 1.0)
}


func testInitFromDictOnErrorSampleRateAsDouble() {
let options = SentryReplayOptions(dictionary: [
"errorSampleRate": 0.44
])

XCTAssertEqual(options.onErrorSampleRate, 0.44)
}

func testInitFromDictOnErrorSampleRateMissing() {
let options = SentryReplayOptions(dictionary: [:])

XCTAssertEqual(options.onErrorSampleRate, 0)
}

func testInitFromDictOnErrorSampleRateAsString() {
let options = SentryReplayOptions(dictionary: [
"onErrorSampleRate": "0.44"
])

XCTAssertEqual(options.onErrorSampleRate, 0)
}

func testInitFromDictSessionSampleRateAsDouble() {
let options = SentryReplayOptions(dictionary: [
"sessionSampleRate": 0.44
])

XCTAssertEqual(options.sessionSampleRate, 0.44)
}

func testInitFromDictSessionSampleRateMissing() {
let options = SentryReplayOptions(dictionary: [:])

XCTAssertEqual(options.sessionSampleRate, 0)
}

func testInitFromDictSessionSampleRateAsString() {
let options = SentryReplayOptions(dictionary: [
"sessionSampleRate": "0.44"
])

XCTAssertEqual(options.sessionSampleRate, 0)
}

func testInitFromDictMaskedViewClasses() {
let options = SentryReplayOptions(dictionary: [
"maskedViewClasses": ["NSString"]
])

XCTAssertEqual(options.maskedViewClasses.count, 1)
XCTAssertEqual(ObjectIdentifier(options.maskedViewClasses.first!), ObjectIdentifier(NSString.self))
}

func testInitFromDictMaskedViewClassesAsString() {
let options = SentryReplayOptions(dictionary: [
"maskedViewClasses": "ExampleView1"
])

XCTAssertEqual(options.maskedViewClasses.count, 0)
}

func testInitFromDictMaskedViewClassesWithNumber() {
let options = SentryReplayOptions(dictionary: [
"maskedViewClasses": [123]
])

XCTAssertEqual(options.maskedViewClasses.count, 0)
}

func testInitFromDictUnmaskedViewClasses() {
let options = SentryReplayOptions(dictionary: [
"unmaskedViewClasses": ["NSString"]
])

XCTAssertEqual(options.unmaskedViewClasses.count, 1)
XCTAssertEqual(ObjectIdentifier(options.unmaskedViewClasses.first!), ObjectIdentifier(NSString.self))
}

func testInitFromDictUnmaskedViewClassesAsString() {
let options = SentryReplayOptions(dictionary: [
"unmaskedViewClasses": "invalid_value"
])

XCTAssertEqual(options.unmaskedViewClasses.count, 0)
}

func testInitFromDictUnmaskedViewClassesWithInvalidValues() {
let options = SentryReplayOptions(dictionary: [
"unmaskedViewClasses": [123, "not.class"] as [Any]
])

XCTAssertEqual(options.unmaskedViewClasses.count, 0)
}

func testInitFromDictMaskAllTextWithBool() {
let options = SentryReplayOptions(dictionary: [
"maskAllText": true
])
XCTAssertTrue(options.maskAllText)

let options2 = SentryReplayOptions(dictionary: [
"maskAllText": false
])
XCTAssertFalse(options2.maskAllText)
}

func testInitFromDictMaskAllTextWithString() {
let options = SentryReplayOptions(dictionary: [
"maskAllText": "invalid_value"
])
XCTAssertTrue(options.maskAllText)
}

func testInitFromDictMaskAllImagesWithBool() {
let options = SentryReplayOptions(dictionary: [
"maskAllImages": true
])
XCTAssertTrue(options.maskAllImages)

let options2 = SentryReplayOptions(dictionary: [
"maskAllImages": false
])
XCTAssertFalse(options2.maskAllImages)
}

func testInitFromDictMaskAllImagesWithString() {
let options = SentryReplayOptions(dictionary: [
"maskAllImages": "invalid_value"
])
XCTAssertTrue(options.maskAllImages)
}

func testInitFromDictWithMultipleOptions() {
let options = SentryReplayOptions(dictionary: [
"sessionSampleRate": 0.5,
"errorSampleRate": 0.8,
"maskAllText": false,
"maskedViewClasses": ["NSString", "not.a.class", 123] as [Any],
"unmaskedViewClasses": ["NSNumber", "invalid", true] as [Any]
])

XCTAssertEqual(options.sessionSampleRate, 0.5)
XCTAssertEqual(options.onErrorSampleRate, 0.8)
XCTAssertFalse(options.maskAllText)
XCTAssertTrue(options.maskAllImages)
XCTAssertEqual(options.maskedViewClasses.count, 1)
XCTAssertEqual(ObjectIdentifier(options.maskedViewClasses.first!), ObjectIdentifier(NSString.self))
XCTAssertEqual(options.unmaskedViewClasses.count, 1)
XCTAssertEqual(ObjectIdentifier(options.unmaskedViewClasses.first!), ObjectIdentifier(NSNumber.self))
}
}
Loading