-
Notifications
You must be signed in to change notification settings - Fork 130
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
Enforce requiring API key to initialise notifier #280
Changes from 7 commits
084e88c
1200634
71032ed
ce966a6
47a3426
2638a69
1f6c4f3
8a91bf8
3102f15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
#import "BSG_RFC3339DateTool.h" | ||
#import "BugsnagUser.h" | ||
#import "BugsnagSessionTracker.h" | ||
#import "BugsnagLogger.h" | ||
|
||
static NSString *const kHeaderApiPayloadVersion = @"Bugsnag-Payload-Version"; | ||
static NSString *const kHeaderApiKey = @"Bugsnag-Api-Key"; | ||
|
@@ -199,6 +200,20 @@ - (void)setAppVersion:(NSString *)newVersion { | |
} | ||
} | ||
|
||
@synthesize apiKey = _apiKey; | ||
|
||
- (NSString *)apiKey { | ||
return _apiKey; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we remove this as it is just the default generated by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it needs to be specified since |
||
|
||
- (void)setApiKey:(NSString *)apiKey { | ||
if ([apiKey length] > 0) { | ||
_apiKey = apiKey; | ||
} else { | ||
bsg_log_err(@"Attempted to override non-null API key with nil - ignoring."); | ||
} | ||
} | ||
|
||
@synthesize shouldAutoCaptureSessions = _shouldAutoCaptureSessions; | ||
|
||
- (BOOL)shouldAutoCaptureSessions { | ||
|
@@ -231,4 +246,9 @@ - (NSDictionary *)sessionApiHeaders { | |
kHeaderApiSentAt: [BSG_RFC3339DateTool stringFromDate:[NSDate new]] | ||
}; | ||
} | ||
|
||
- (BOOL)hasValidApiKey { | ||
return [_apiKey length] > 0; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,4 +99,31 @@ - (void)testUser { | |
|
||
} | ||
|
||
- (void)testApiKeySetter { | ||
BugsnagConfiguration *config = [BugsnagConfiguration new]; | ||
XCTAssertEqualObjects(@"", config.apiKey); | ||
|
||
config.apiKey = @"test"; | ||
XCTAssertEqualObjects(@"test", config.apiKey); | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wnonnull" | ||
config.apiKey = nil; | ||
#pragma clang diagnostic pop | ||
|
||
XCTAssertEqualObjects(@"test", config.apiKey); | ||
} | ||
|
||
- (void)testHasValidApiKey { | ||
BugsnagConfiguration *config = nil; | ||
XCTAssertFalse([config hasValidApiKey]); | ||
|
||
config = [BugsnagConfiguration new]; | ||
XCTAssertFalse([config hasValidApiKey]); | ||
|
||
config.apiKey = @"5adf89e0aaa"; | ||
XCTAssertTrue([config hasValidApiKey]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's covered by L122, as config defaults to |
||
} | ||
|
||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle the notifier being
nil
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as nil will be coerced to false.