Skip to content

Commit

Permalink
fix: validate that breadcrumbs must be between 0-100
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Mar 30, 2020
1 parent 3d5639a commit 8e1febb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Source/BugsnagConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ typedef NS_OPTIONS(NSUInteger, BSGErrorType) {
@property(retain, nullable) NSString *appType;

/**
* The maximum number of breadcrumbs to keep and sent to Bugsnag.
* By default, we'll keep and send the 25 most recent breadcrumb log
* messages.
* Sets the maximum number of breadcrumbs which will be stored. Once the threshold is reached,
* the oldest breadcrumbs will be deleted.
*
* By default, 25 breadcrumbs are stored: this can be amended up to a maximum of 100.
*/
@property NSUInteger maxBreadcrumbs;

Expand Down
7 changes: 6 additions & 1 deletion Source/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,12 @@ - (NSUInteger)maxBreadcrumbs {
}

- (void)setMaxBreadcrumbs:(NSUInteger)capacity {
self.breadcrumbs.capacity = capacity;
if (capacity >= 0 && capacity <= 100) {
self.breadcrumbs.capacity = capacity;
} else {
bsg_log_err(@"Invalid configuration value detected. Option maxBreadcrumbs "
"should be an integer between 0-100. Supplied value is %lu", capacity);
}
}

/**
Expand Down
30 changes: 30 additions & 0 deletions Tests/BugsnagConfigurationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,36 @@ - (void)testSettingPersistUser {
XCTAssertTrue(config.persistUser);
}

// =============================================================================
// MARK: - Max Breadcrumb
// =============================================================================

- (void)testMaxBreadcrumb {
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
XCTAssertEqual(25, config.maxBreadcrumbs);

// alter to valid value
config.maxBreadcrumbs = 10;
XCTAssertEqual(10, config.maxBreadcrumbs);

// alter to max value
config.maxBreadcrumbs = 100;
XCTAssertEqual(100, config.maxBreadcrumbs);

// alter to min value
config.maxBreadcrumbs = 0;
XCTAssertEqual(0, config.maxBreadcrumbs);

// alter to negative value
config.maxBreadcrumbs = -1;
XCTAssertEqual(0, config.maxBreadcrumbs);

// alter to negative value (overflows)
config.maxBreadcrumbs = 500;
XCTAssertEqual(0, config.maxBreadcrumbs);
}


// =============================================================================
// MARK: - Other tests
// =============================================================================
Expand Down

0 comments on commit 8e1febb

Please sign in to comment.