-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from bugsnag/PLAT-11750-null-url-crash
[PLAT-11750] Handle edge case when capturing a URL request with a null URL before Bugsnag is initialized
- Loading branch information
Showing
8 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
43 changes: 43 additions & 0 deletions
43
features/fixtures/ios/Scenarios/AutoInstrumentNetworkNullURLScenario.swift
This file contains 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// AutoInstrumentNetworkNullURLScenario.swift | ||
// Fixture | ||
// | ||
// Created by Karl Stenerud on 12.03.24. | ||
// | ||
|
||
import Foundation | ||
|
||
@objcMembers | ||
class AutoInstrumentNetworkNullURLScenario: Scenario { | ||
|
||
override func configure() { | ||
// Early phase span. Make sure it doesn't crash or generate a span | ||
ObjCURLSession.dataTask(with: nil).resume() | ||
|
||
super.configure() | ||
config.autoInstrumentNetworkRequests = true | ||
config.networkRequestCallback = { (info: BugsnagPerformanceNetworkRequestInfo) -> BugsnagPerformanceNetworkRequestInfo in | ||
super.ignoreInternalRequests(info: info) | ||
let testUrl = info.url | ||
if (testUrl == nil) { | ||
return info | ||
} | ||
if (self.isMazeRunnerAdministrationURL(url: testUrl!)) { | ||
info.url = nil | ||
} | ||
return info | ||
} | ||
} | ||
|
||
func query(string: String) { | ||
let url = URL(string: string, relativeTo: fixtureConfig.reflectURL)! | ||
URLSession.shared.dataTask(with: url).resume() | ||
} | ||
|
||
override func run() { | ||
// Force the automatic spans to be sent in a separate trace that we will discard | ||
waitForCurrentBatch() | ||
// Send an actual request to be captured | ||
query(string: "?status=200") | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// ObjCURLSession.h | ||
// Fixture | ||
// | ||
// Created by Karl Stenerud on 12.03.24. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
// Wrapper so that we can pass in nil arguments | ||
@interface ObjCURLSession : NSObject | ||
|
||
+ (NSURLSessionDataTask *)dataTaskWithURL:(NSURL *)url; | ||
|
||
@end |
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// ObjCURLSession.m | ||
// Fixture | ||
// | ||
// Created by Karl Stenerud on 12.03.24. | ||
// | ||
|
||
#import "ObjCURLSession.h" | ||
|
||
@implementation ObjCURLSession | ||
|
||
+ (NSURLSessionDataTask *)dataTaskWithURL:(NSURL *)url { | ||
return [[NSURLSession sharedSession] dataTaskWithURL:url]; | ||
} | ||
|
||
@end |