From 89401b05e24d5fda0423512e2eaeef511842bd7b Mon Sep 17 00:00:00 2001 From: Rad Azzouz Date: Tue, 12 Aug 2014 19:15:13 -0700 Subject: [PATCH 1/3] [IMPROVEMENT] We now make sure that all parameneters are non nil. --- OnePasswordExtension.m | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index 5daf532..83af557 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -77,6 +77,14 @@ - (BOOL)isAppExtensionAvailable { - (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewController *)viewController completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion { + if (!URLString) { + [NSException raise:@"Invalid Argument exception" format:@"URLString must not be nil"]; + } + + if (!viewController) { + [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; + } + if (![self isSystemAppExtensionAPIAvailable]) { NSLog(@"Failed to findLoginForURLString, system API is not available"); if (completion) { @@ -124,6 +132,18 @@ - (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewCon - (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDict passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion; { + if (!URLString) { + [NSException raise:@"Invalid Argument exception" format:@"URLString must not be nil"]; + } + + if (!loginDetailsDict) { + [NSException raise:@"Invalid Argument exception" format:@"loginDetailsDict must not be nil"]; + } + + if (!viewController) { + [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; + } + if (![self isSystemAppExtensionAPIAvailable]) { NSLog(@"Failed to storeLoginForURLString, system API is not available"); if (completion) { @@ -175,6 +195,18 @@ - (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary - (void)changePasswordForLoginWithUsername:(NSString *)username andURLString:(NSString *)URLString passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController completion:(void (^)(NSDictionary *loginDict, NSError *error))completion { + if (!username) { + [NSException raise:@"Invalid Argument exception" format:@"username must not be nil"]; + } + + if (!URLString) { + [NSException raise:@"Invalid Argument exception" format:@"URLString must not be nil"]; + } + + if (!viewController) { + [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; + } + if (![self isSystemAppExtensionAPIAvailable]) { NSLog(@"Failed to changePasswordForLoginWithUsername, system API is not available"); if (completion) { @@ -225,6 +257,14 @@ - (void)changePasswordForLoginWithUsername:(NSString *)username andURLString:(NS - (void)fillLoginIntoWebView:(id)webView forViewController:(UIViewController *)viewController completion:(void (^)(BOOL success, NSError *error))completion { + if (!webView) { + [NSException raise:@"Invalid Argument exception" format:@"webView must not be nil"]; + } + + if (!viewController) { + [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; + } + #ifdef __IPHONE_8_0 if ([webView isKindOfClass:[UIWebView class]]) { [self fillLoginIntoUIWebView:webView webViewController:viewController completion:^(BOOL success, NSError *error) { From 19ae960be20146ca6b572c9d2609fd899030b9f5 Mon Sep 17 00:00:00 2001 From: Rad Azzouz Date: Tue, 12 Aug 2014 20:22:50 -0700 Subject: [PATCH 2/3] NSAssert is sooo much better. --- OnePasswordExtension.m | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index 83af557..199816a 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -77,13 +77,8 @@ - (BOOL)isAppExtensionAvailable { - (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewController *)viewController completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion { - if (!URLString) { - [NSException raise:@"Invalid Argument exception" format:@"URLString must not be nil"]; - } - - if (!viewController) { - [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; - } + NSAssert(URLString != nil, @"URLString must not be nil"); + NSAssert(viewController != nil, @"viewController must not be nil"); if (![self isSystemAppExtensionAPIAvailable]) { NSLog(@"Failed to findLoginForURLString, system API is not available"); @@ -132,17 +127,9 @@ - (void)findLoginForURLString:(NSString *)URLString forViewController:(UIViewCon - (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary *)loginDetailsDict passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController completion:(void (^)(NSDictionary *loginDictionary, NSError *error))completion; { - if (!URLString) { - [NSException raise:@"Invalid Argument exception" format:@"URLString must not be nil"]; - } - - if (!loginDetailsDict) { - [NSException raise:@"Invalid Argument exception" format:@"loginDetailsDict must not be nil"]; - } - - if (!viewController) { - [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; - } + NSAssert(URLString != nil, @"URLString must not be nil"); + NSAssert(loginDetailsDict != nil, @"loginDetailsDict must not be nil"); + NSAssert(viewController != nil, @"viewController must not be nil"); if (![self isSystemAppExtensionAPIAvailable]) { NSLog(@"Failed to storeLoginForURLString, system API is not available"); @@ -195,17 +182,9 @@ - (void)storeLoginForURLString:(NSString *)URLString loginDetails:(NSDictionary - (void)changePasswordForLoginWithUsername:(NSString *)username andURLString:(NSString *)URLString passwordGenerationOptions:(NSDictionary *)passwordGenerationOptions forViewController:(UIViewController *)viewController completion:(void (^)(NSDictionary *loginDict, NSError *error))completion { - if (!username) { - [NSException raise:@"Invalid Argument exception" format:@"username must not be nil"]; - } - - if (!URLString) { - [NSException raise:@"Invalid Argument exception" format:@"URLString must not be nil"]; - } - - if (!viewController) { - [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; - } + NSAssert(username != nil, @"username must not be nil"); + NSAssert(URLString != nil, @"URLString must not be nil"); + NSAssert(viewController != nil, @"viewController must not be nil"); if (![self isSystemAppExtensionAPIAvailable]) { NSLog(@"Failed to changePasswordForLoginWithUsername, system API is not available"); From 6abce0e0b8c6aae85a5de13145d602cd933c8064 Mon Sep 17 00:00:00 2001 From: Rad Azzouz Date: Tue, 12 Aug 2014 20:24:36 -0700 Subject: [PATCH 3/3] `fillLoginIntoWebView` was left out. Now it has `NSAssert` too :-) --- OnePasswordExtension.m | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index 199816a..7677e82 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -236,13 +236,8 @@ - (void)changePasswordForLoginWithUsername:(NSString *)username andURLString:(NS - (void)fillLoginIntoWebView:(id)webView forViewController:(UIViewController *)viewController completion:(void (^)(BOOL success, NSError *error))completion { - if (!webView) { - [NSException raise:@"Invalid Argument exception" format:@"webView must not be nil"]; - } - - if (!viewController) { - [NSException raise:@"Invalid Argument exception" format:@"viewController must not be nil"]; - } + NSAssert(webView != nil, @"webView must not be nil"); + NSAssert(viewController != nil, @"viewController must not be nil"); #ifdef __IPHONE_8_0 if ([webView isKindOfClass:[UIWebView class]]) {