diff --git a/Classes/BITAuthenticator.m b/Classes/BITAuthenticator.m index 2019bc1427..e444f7fe25 100644 --- a/Classes/BITAuthenticator.m +++ b/Classes/BITAuthenticator.m @@ -201,6 +201,15 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe BITHockeyLog(@"Already authenticating. Ignoring request"); return; } + if(_authenticationType == BITAuthenticatorAuthTypeEmail && (nil == _authenticationSecret || !_authenticationSecret.length)) { + if(completion) { + NSError *error = [NSError errorWithDomain:kBITAuthenticatorErrorDomain + code:BITAuthenticatorAuthorizationSecretMissing + userInfo:@{NSLocalizedDescriptionKey: @"Authentication secret is not set but required."}]; + completion(nil, error); + } + return; + } BITAuthenticationViewController *viewController = [[BITAuthenticationViewController alloc] initWithDelegate:self]; switch (self.authenticationType) { diff --git a/Classes/HockeySDK.h b/Classes/HockeySDK.h index a76689a769..15d77c4929 100644 --- a/Classes/HockeySDK.h +++ b/Classes/HockeySDK.h @@ -94,6 +94,7 @@ typedef NS_ENUM(NSInteger, BITAuthenticatorReason) { BITAuthenticatorAPIServerReturnedInvalidRespone, BITAuthenticatorNotAuthorized, BITAuthenticatorAuthenticationCancelled, + BITAuthenticatorAuthorizationSecretMissing, }; extern NSString *const __attribute__((unused)) kBITAuthenticatorErrorDomain; diff --git a/Support/HockeySDKTests/BITAuthenticatorTests.m b/Support/HockeySDKTests/BITAuthenticatorTests.m index 71bcf03208..7405b51630 100644 --- a/Support/HockeySDKTests/BITAuthenticatorTests.m +++ b/Support/HockeySDKTests/BITAuthenticatorTests.m @@ -56,6 +56,7 @@ static void *kInstallationIdentification = &kInstallationIdentification; [super setUp]; _sut = [[BITAuthenticator alloc] initWithAppIdentifier:nil isAppStoreEnvironemt:NO]; + _sut.authenticationType = BITAuthenticatorAuthTypeEmailAndPassword; } - (void)tearDown { @@ -129,6 +130,7 @@ static void *kInstallationIdentification = &kInstallationIdentification; - (void) testThatAuthenticateWithTypeEmailShowsAViewController { id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate)); _sut.delegate = delegateMock; + _sut.authenticationSecret = @"myscret"; _sut.authenticationType = BITAuthenticatorAuthTypeEmail; [_sut authenticateWithCompletion:nil]; @@ -136,6 +138,18 @@ static void *kInstallationIdentification = &kInstallationIdentification; [verifyCount(delegateMock, times(1)) authenticator:_sut willShowAuthenticationController:(id)anything()]; } +- (void) testThatAuthenticateWithTypeEmailShowsAViewControllerOnlyIfAuthenticationSecretIsSet { + id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate)); + _sut.delegate = delegateMock; + _sut.authenticationSecret = nil; + _sut.authenticationType = BITAuthenticatorAuthTypeEmail; + + [_sut authenticateWithCompletion:nil]; + + [verifyCount(delegateMock, times(0)) authenticator:_sut willShowAuthenticationController:(id)anything()]; +} + + - (void) testThatAuthenticateWithTypeEmailAndPasswordShowsAViewController { id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate)); _sut.delegate = delegateMock;