diff --git a/Classes/BITAuthenticator.m b/Classes/BITAuthenticator.m index 28e1e3bf12..dc5dd99a7b 100644 --- a/Classes/BITAuthenticator.m +++ b/Classes/BITAuthenticator.m @@ -576,6 +576,13 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato } } +- (void)applicationWillResignActive:(NSNotification *)note { + if(BITAuthenticatorValidationTypeOnAppActive == self.validationType) { + self.installationIdentificationValidated = NO; + } +} + +#pragma mark - - (tValidationCompletion) defaultValidationCompletionBlock { return ^(BOOL validated, NSError *error) { switch (self.validationType) { @@ -584,15 +591,11 @@ static NSString* const kBITAuthenticatorDidSkipOptionalLogin = @"BITAuthenticato break; case BITAuthenticatorValidationTypeOnAppActive: case BITAuthenticatorValidationTypeOnFirstLaunch: - [self authenticateWithCompletion:nil]; + if(!validated) { + [self authenticateWithCompletion:nil]; + } break; } }; }; -- (void)applicationWillResignActive:(NSNotification *)note { - if(BITAuthenticatorValidationTypeOnAppActive == self.validationType) { - self.installationIdentificationValidated = NO; - } -} - @end diff --git a/Support/HockeySDKTests/BITAuthenticatorTests.m b/Support/HockeySDKTests/BITAuthenticatorTests.m index 47d252e20e..f97add3d4e 100644 --- a/Support/HockeySDKTests/BITAuthenticatorTests.m +++ b/Support/HockeySDKTests/BITAuthenticatorTests.m @@ -335,6 +335,26 @@ static void *kInstallationIdentification = &kInstallationIdentification; assertThat(error, notNilValue()); } +- (void) testThatFailedRequiredValidationShowsAuthenticationViewController { + id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate)); + _sut.delegate = delegateMock; + _sut.validationType = BITAuthenticatorValidationTypeOnAppActive; + + [_sut validationFailedWithError:[NSError errorWithDomain:kBITAuthenticatorErrorDomain code:0 userInfo:nil] + completion:nil]; + [verifyCount(delegateMock, times(1)) authenticator:_sut willShowAuthenticationController:(id)anything()]; +} + +- (void) testThatFailedOptionalValidationDoesNotShowAuthenticationViewController { + id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate)); + _sut.delegate = delegateMock; + _sut.validationType = BITAuthenticatorValidationTypeOptional; + + [_sut validationFailedWithError:nil + completion:nil]; + [verifyCount(delegateMock, never()) authenticator:_sut willShowAuthenticationController:(id)anything()]; +} + - (void) testThatSuccessValidationCallsTheCompletionBlock { id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate)); _sut.delegate = delegateMock;