-
-
Notifications
You must be signed in to change notification settings - Fork 396
feat(network-details): New swizzling to capture response bodies for session replay #7584
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eeba025
feat(network-details): Add (simplified) URLSession swizzling for respβ¦
43jay 389a27c
review-feedback: Remove redundant and possibly flakey tests
43jay 22e2b20
feat(network-details): [swizzle] Gate swizzling based on SDKOptions#nβ¦
43jay c166d2e
fix(network-details): Gate swizzling with !SENTRY_NO_UI_FRAMEWORK
43jay 780abbb
fix(network-details): make format
43jay dc934e5
chore(api): Regenerate sdk_api.json
43jay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 70 additions & 3 deletions
73
Tests/SentryTests/Integrations/Performance/Network/SentryNSURLSessionTaskSearchTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,80 @@ | ||
| import XCTest | ||
|
|
||
| // We need to know whether Apple changes the NSURLSessionTask implementation. | ||
| class SentryNSURLSessionTaskSearchTests: XCTestCase { | ||
|
|
||
| // We need to know whether Apple changes the NSURLSessionTask implementation. | ||
| func test_URLSessionTask_ByIosVersion() { | ||
| func test_URLSessionTask_ByIosVersion() { | ||
| let classes = SentryNSURLSessionTaskSearch.urlSessionTaskClassesToTrack() | ||
|
|
||
| XCTAssertEqual(classes.count, 1) | ||
| XCTAssertTrue(classes.first === URLSessionTask.self) | ||
| } | ||
|
|
||
| // MARK: - NSURLSession class hierarchy validation tests | ||
| // | ||
| // Based on testing, NSURLSession implements dataTaskWithRequest:completionHandler: | ||
| // and dataTaskWithURL:completionHandler: directly on the base class. | ||
| // | ||
| // The swizzling code relies on this by swizzling [NSURLSession class] directly | ||
| // rather than doing runtime discovery. These tests verify that assumption | ||
| // still holds β if Apple ever moves these methods, these tests | ||
| // will fail and we'll know to update the swizzling approach. | ||
|
|
||
| func test_URLSessionDataTaskWithRequest_ByIosVersion() { | ||
| let selector = #selector(URLSession.dataTask(with:completionHandler:) | ||
| as (URLSession) -> (URLRequest, @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask) | ||
| assertNSURLSessionImplementsDirectly(selector: selector, selectorName: "dataTaskWithRequest:completionHandler:") | ||
| } | ||
|
43jay marked this conversation as resolved.
|
||
|
|
||
| func test_URLSessionDataTaskWithURL_ByIosVersion() { | ||
| let selector = #selector(URLSession.dataTask(with:completionHandler:) | ||
| as (URLSession) -> (URL, @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask) | ||
| assertNSURLSessionImplementsDirectly(selector: selector, selectorName: "dataTaskWithURL:completionHandler:") | ||
| } | ||
|
|
||
| // MARK: - Helper | ||
|
|
||
| /// Walks the class hierarchy for sessions created with default and ephemeral | ||
| /// configurations and asserts that no subclass overrides `selector`. | ||
| private func assertNSURLSessionImplementsDirectly(selector: Selector, selectorName: String) { | ||
| let baseClass: AnyClass = URLSession.self | ||
|
|
||
| // The base class must implement the method. | ||
| XCTAssertNotNil( | ||
| class_getInstanceMethod(baseClass, selector), | ||
| "URLSession should implement \(selectorName)" | ||
| ) | ||
|
|
||
| // Check sessions created with each relevant configuration. | ||
| let configs: [URLSessionConfiguration] = [ | ||
| .default, | ||
| .ephemeral | ||
| ] | ||
|
|
||
| for config in configs { | ||
| let session = URLSession(configuration: config) | ||
| let sessionClass: AnyClass = type(of: session) | ||
|
|
||
| defer { session.invalidateAndCancel() } | ||
|
|
||
| if sessionClass === baseClass { | ||
| continue | ||
| } | ||
|
|
||
| // If Apple returns a subclass, it must NOT provide its own | ||
| // implementation β it should inherit from URLSession. | ||
| let subMethod = class_getInstanceMethod(sessionClass, selector) | ||
| let baseMethod = class_getInstanceMethod(baseClass, selector) | ||
|
|
||
| if let subMethod, let baseMethod { | ||
| let subIMP = method_getImplementation(subMethod) | ||
| let baseIMP = method_getImplementation(baseMethod) | ||
| XCTAssertEqual( | ||
| subIMP, baseIMP, | ||
| "\(NSStringFromClass(sessionClass)) overrides \(selectorName) with an unexpected IMP β " | ||
| + "Verify swizzling in SentrySwizzleWrapperHelper is correct for dataTasks." | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.