diff options
Diffstat (limited to 'Example/Auth/Tests')
-rw-r--r-- | Example/Auth/Tests/FIRAuthTests.m | 43 | ||||
-rw-r--r-- | Example/Auth/Tests/FIRUserTests.m | 53 |
2 files changed, 60 insertions, 36 deletions
diff --git a/Example/Auth/Tests/FIRAuthTests.m b/Example/Auth/Tests/FIRAuthTests.m index 93d6074..b8d04f5 100644 --- a/Example/Auth/Tests/FIRAuthTests.m +++ b/Example/Auth/Tests/FIRAuthTests.m @@ -20,7 +20,6 @@ #import "EmailPassword/FIREmailAuthProvider.h" #import "Google/FIRGoogleAuthProvider.h" #import "Phone/FIRPhoneAuthCredential.h" -#import "Phone/FIRPhoneAuthProvider.h" #import "FIRAdditionalUserInfo.h" #import "FIRAuth_Internal.h" #import "FIRAuthErrorUtils.h" @@ -54,6 +53,10 @@ #import "OCMStubRecorder+FIRAuthUnitTests.h" #import <OCMock/OCMock.h> +#if TARGET_OS_IOS +#import "Phone/FIRPhoneAuthProvider.h" +#endif + /** @var kFirebaseAppName1 @brief A fake Firebase app name. */ @@ -99,10 +102,10 @@ static NSString *const kRefreshToken = @"REFRESH_TOKEN"; */ static NSString *const kEmail = @"user@company.com"; -/** @var kPassword +/** @var kFakePassword @brief The fake user password. */ -static NSString *const kPassword = @"!@#$%^"; +static NSString *const kFakePassword = @"!@#$%^"; /** @var kPasswordHash @brief The fake user password hash. @@ -408,6 +411,7 @@ static const NSTimeInterval kWaitInterval = .5; OCMVerifyAll(_mockBackend); } +#if TARGET_OS_IOS /** @fn testPhoneAuthSuccess @brief Tests the flow of a successful @c signInWithCredential:completion for phone auth. */ @@ -485,6 +489,7 @@ static const NSTimeInterval kWaitInterval = .5; }]; [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; } +#endif /** @fn testSignInWithEmailPasswordSuccess @brief Tests the flow of a successful @c signInWithEmail:password:completion: call. @@ -495,7 +500,7 @@ static const NSTimeInterval kWaitInterval = .5; FIRVerifyPasswordResponseCallback callback) { XCTAssertEqualObjects(request.APIKey, kAPIKey); XCTAssertEqualObjects(request.email, kEmail); - XCTAssertEqualObjects(request.password, kPassword); + XCTAssertEqualObjects(request.password, kFakePassword); XCTAssertTrue(request.returnSecureToken); dispatch_async(FIRAuthGlobalWorkQueue(), ^() { id mockVerifyPasswordResponse = OCMClassMock([FIRVerifyPasswordResponse class]); @@ -506,8 +511,8 @@ static const NSTimeInterval kWaitInterval = .5; [self expectGetAccountInfo]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInWithEmail:kEmail password:kPassword completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUser:user]; XCTAssertNil(error); @@ -526,8 +531,8 @@ static const NSTimeInterval kWaitInterval = .5; .andDispatchError2([FIRAuthErrorUtils wrongPasswordErrorWithMessage:nil]); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInWithEmail:kEmail password:kPassword completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(user); XCTAssertEqual(error.code, FIRAuthErrorCodeWrongPassword); @@ -764,7 +769,7 @@ static const NSTimeInterval kWaitInterval = .5; FIRVerifyPasswordResponseCallback callback) { XCTAssertEqualObjects(request.APIKey, kAPIKey); XCTAssertEqualObjects(request.email, kEmail); - XCTAssertEqualObjects(request.password, kPassword); + XCTAssertEqualObjects(request.password, kFakePassword); XCTAssertTrue(request.returnSecureToken); dispatch_async(FIRAuthGlobalWorkQueue(), ^() { id mockVeriyPasswordResponse = OCMClassMock([FIRVerifyPasswordResponse class]); @@ -776,7 +781,7 @@ static const NSTimeInterval kWaitInterval = .5; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *emailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); @@ -799,7 +804,7 @@ static const NSTimeInterval kWaitInterval = .5; FIRVerifyPasswordResponseCallback callback) { XCTAssertEqualObjects(request.APIKey, kAPIKey); XCTAssertEqualObjects(request.email, kEmail); - XCTAssertEqualObjects(request.password, kPassword); + XCTAssertEqualObjects(request.password, kFakePassword); XCTAssertTrue(request.returnSecureToken); dispatch_async(FIRAuthGlobalWorkQueue(), ^() { id mockVeriyPasswordResponse = OCMClassMock([FIRVerifyPasswordResponse class]); @@ -813,7 +818,7 @@ static const NSTimeInterval kWaitInterval = .5; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" FIRAuthCredential *emailCredential = - [FIREmailPasswordAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailPasswordAuthProvider credentialWithEmail:kEmail password:kFakePassword]; #pragma clang diagnostic pop [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { @@ -837,7 +842,7 @@ static const NSTimeInterval kWaitInterval = .5; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *emailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [[FIRAuth auth] signInWithCredential:emailCredential completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); @@ -1133,7 +1138,7 @@ static const NSTimeInterval kWaitInterval = .5; FIRSignupNewUserCallback callback) { XCTAssertEqualObjects(request.APIKey, kAPIKey); XCTAssertEqualObjects(request.email, kEmail); - XCTAssertEqualObjects(request.password, kPassword); + XCTAssertEqualObjects(request.password, kFakePassword); XCTAssertTrue(request.returnSecureToken); dispatch_async(FIRAuthGlobalWorkQueue(), ^() { id mockSignUpNewUserResponse = OCMClassMock([FIRSignUpNewUserResponse class]); @@ -1145,7 +1150,7 @@ static const NSTimeInterval kWaitInterval = .5; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; [[FIRAuth auth] createUserWithEmail:kEmail - password:kPassword + password:kFakePassword completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUser:user]; @@ -1167,7 +1172,7 @@ static const NSTimeInterval kWaitInterval = .5; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; [[FIRAuth auth] createUserWithEmail:kEmail - password:kPassword + password:kFakePassword completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(user); @@ -1495,6 +1500,7 @@ static const NSTimeInterval kWaitInterval = .5; OCMVerifyAll(_mockBackend); } +#if TARGET_OS_IOS /** @fn testAutomaticTokenRefreshInvalidTokenFailure @brief Tests that app foreground notification triggers the scheduling of an automatic token refresh task. @@ -1530,6 +1536,7 @@ static const NSTimeInterval kWaitInterval = .5; XCTAssertEqualObjects(kNewAccessToken, [FIRAuth auth].currentUser.rawAccessToken); OCMVerifyAll(_mockBackend); } +#endif #pragma mark - Helpers @@ -1733,8 +1740,8 @@ static const NSTimeInterval kWaitInterval = .5; }); [self expectGetAccountInfo]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; - [[FIRAuth auth] signInWithEmail:kEmail password:kPassword completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user, + NSError *_Nullable error) { [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; diff --git a/Example/Auth/Tests/FIRUserTests.m b/Example/Auth/Tests/FIRUserTests.m index 5a4c00a..c90da44 100644 --- a/Example/Auth/Tests/FIRUserTests.m +++ b/Example/Auth/Tests/FIRUserTests.m @@ -20,7 +20,6 @@ #import "Facebook/FIRFacebookAuthProvider.h" #import "Google/FIRGoogleAuthProvider.h" #import "Phone/FIRPhoneAuthCredential_Internal.h" -#import "Phone/FIRPhoneAuthProvider.h" #import "FIRAdditionalUserInfo.h" #import "FIRAuth.h" #import "FIRAuthErrorUtils.h" @@ -42,6 +41,10 @@ #import "OCMStubRecorder+FIRAuthUnitTests.h" #import <OCMock/OCMock.h> +#if TARGET_OS_IOS +#import "Phone/FIRPhoneAuthProvider.h" +#endif + NS_ASSUME_NONNULL_BEGIN /** @var kAPIKey @@ -139,10 +142,10 @@ static NSString *const kPhotoURL = @"https://host.domain/image"; */ static NSString *const kNewPhotoURL = @"https://host.domain/new/image"; -/** @var kPassword +/** @var kFakePassword @brief The fake user password. */ -static NSString *const kPassword = @"123456"; +static NSString *const kFakePassword = @"123456"; /** @var kNewPassword @brief The fake new user password. @@ -276,10 +279,12 @@ static const NSTimeInterval kExpectationTimeout = 1; OCMStub([mockFacebookUserInfo federatedID]).andReturn(kFacebookID); OCMStub([mockFacebookUserInfo email]).andReturn(kFacebookEmail); + #if TARGET_OS_IOS // Mock auth provider user info from Phone auth provider for GetAccountInfo. id mockPhoneUserInfo = OCMClassMock([FIRGetAccountInfoResponseProviderUserInfo class]); OCMStub([mockPhoneUserInfo providerID]).andReturn(FIRPhoneAuthProviderID); OCMStub([mockPhoneUserInfo phoneNumber]).andReturn(kPhoneNumber); + #endif // Mock the root user info object for GetAccountInfo. id mockGetAccountInfoResponseUser = OCMClassMock([FIRGetAccountInfoResponseUser class]); @@ -288,11 +293,15 @@ static const NSTimeInterval kExpectationTimeout = 1; OCMStub([mockGetAccountInfoResponseUser emailVerified]).andReturn(YES); OCMStub([mockGetAccountInfoResponseUser displayName]).andReturn(kGoogleDisplayName); OCMStub([mockGetAccountInfoResponseUser photoURL]).andReturn([NSURL URLWithString:kPhotoURL]); - OCMStub([mockGetAccountInfoResponseUser providerUserInfo]) - .andReturn((@[ mockPasswordUserInfo, - mockGoogleUserInfo, - mockFacebookUserInfo, - mockPhoneUserInfo ])); + NSArray *providerUserInfos = @[ + #if TARGET_OS_IOS + mockPhoneUserInfo, + #endif + mockPasswordUserInfo, + mockGoogleUserInfo, + mockFacebookUserInfo + ]; + OCMStub([mockGetAccountInfoResponseUser providerUserInfo]).andReturn(providerUserInfos); OCMStub([mockGetAccountInfoResponseUser passwordHash]).andReturn(kPasswordHash); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; @@ -309,7 +318,7 @@ static const NSTimeInterval kExpectationTimeout = 1; XCTAssertFalse(user.anonymous); XCTAssertTrue(user.emailVerified); XCTAssertEqualObjects(user.refreshToken, kRefreshToken); - XCTAssertEqual(user.providerData.count, 4u); + XCTAssertEqual(user.providerData.count, providerUserInfos.count); NSDictionary<NSString *, id<FIRUserInfo>> *providerMap = [self dictionaryWithUserInfoArray:user.providerData]; @@ -338,10 +347,12 @@ static const NSTimeInterval kExpectationTimeout = 1; XCTAssertNil(facebookUserInfo.photoURL); XCTAssertEqualObjects(facebookUserInfo.email, kFacebookEmail); + #if TARGET_OS_IOS // Verify FIRUserInfo properties from the phone auth provider. id<FIRUserInfo> phoneUserInfo = providerMap[FIRPhoneAuthProviderID]; XCTAssertNotNil(phoneUserInfo); XCTAssertEqualObjects(phoneUserInfo.phoneNumber, kPhoneNumber); + #endif [expectation fulfill]; }]; @@ -425,6 +436,7 @@ static const NSTimeInterval kExpectationTimeout = 1; OCMVerifyAll(_mockBackend); } +#if TARGET_OS_IOS /** @fn testUpdatePhoneSuccess @brief Tests the flow of a successful @c updatePhoneNumberCredential:completion: call. */ @@ -487,6 +499,7 @@ static const NSTimeInterval kExpectationTimeout = 1; [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; OCMVerifyAll(_mockBackend); } +#endif /** @fn testUpdatePasswordSuccess @brief Tests the flow of a successful @c updatePassword:completion: call. @@ -737,7 +750,7 @@ static const NSTimeInterval kExpectationTimeout = 1; }); }); FIRAuthCredential *emailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [user reauthenticateWithCredential:emailCredential completion:^(NSError *_Nullable error) { XCTAssertNil(error); // Verify that the current user is unchanged. @@ -851,7 +864,7 @@ static const NSTimeInterval kExpectationTimeout = 1; }); }); FIRAuthCredential *emailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [user reauthenticateWithCredential:emailCredential completion:^(NSError *_Nullable error) { // Verify user mismatch error. XCTAssertEqual(error.code, FIRAuthErrorCodeUserMismatch); @@ -1087,7 +1100,7 @@ static const NSTimeInterval kExpectationTimeout = 1; FIRSetAccountInfoResponseCallback callback) { XCTAssertEqualObjects(request.APIKey, kAPIKey); XCTAssertEqualObjects(request.accessToken, kAccessToken); - XCTAssertEqualObjects(request.password, kPassword); + XCTAssertEqualObjects(request.password, kFakePassword); XCTAssertNil(request.localID); XCTAssertNil(request.displayName); dispatch_async(FIRAuthGlobalWorkQueue(), ^() { @@ -1097,7 +1110,7 @@ static const NSTimeInterval kExpectationTimeout = 1; }); FIRAuthCredential *linkEmailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential completion:^(FIRAuthDataResult *_Nullable linkAuthResult, @@ -1154,7 +1167,7 @@ static const NSTimeInterval kExpectationTimeout = 1; FIRSetAccountInfoResponseCallback callback) { XCTAssertEqualObjects(request.APIKey, kAPIKey); XCTAssertEqualObjects(request.accessToken, kAccessToken); - XCTAssertEqualObjects(request.password, kPassword); + XCTAssertEqualObjects(request.password, kFakePassword); XCTAssertNil(request.localID); XCTAssertNil(request.displayName); dispatch_async(FIRAuthGlobalWorkQueue(), ^() { @@ -1164,7 +1177,7 @@ static const NSTimeInterval kExpectationTimeout = 1; }); FIRAuthCredential *linkEmailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential completion:^(FIRAuthDataResult *_Nullable linkAuthResult, @@ -1226,7 +1239,7 @@ static const NSTimeInterval kExpectationTimeout = 1; }); FIRAuthCredential *linkEmailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential completion:^(FIRAuthDataResult *_Nullable linkAuthResult, @@ -1378,6 +1391,7 @@ static const NSTimeInterval kExpectationTimeout = 1; OCMVerifyAll(_mockBackend); } +#if TARGET_OS_IOS /** @fn testlinkPhoneAuthCredentialSuccess @brief Tests the flow of a successful @c linkAndRetrieveDataWithCredential:completion: call using a phoneAuthCredential. @@ -1593,6 +1607,7 @@ static const NSTimeInterval kExpectationTimeout = 1; [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; OCMVerifyAll(_mockBackend); } +#endif #pragma mark - Helpers @@ -1618,8 +1633,8 @@ static const NSTimeInterval kExpectationTimeout = 1; }); [self expectGetAccountInfoWithMockUserInfoResponse:mockUserInfoResponse]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInWithEmail:kEmail password:kPassword completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user, + NSError *_Nullable error) { XCTAssertNotNil(user); XCTAssertNil(error); completion(user); @@ -1770,6 +1785,7 @@ static const NSTimeInterval kExpectationTimeout = 1; [self expectGetAccountInfo:providerId federatedID:federatedID displayName:displayName]; } +#if TARGET_OS_IOS /** @fn expectVerifyPhoneNumberRequestWithPhoneNumber:error: @brief Expects a verify phone numner request on the mock backend and calls back with fake account data or an error. @@ -1795,6 +1811,7 @@ static const NSTimeInterval kExpectationTimeout = 1; }); }); } +#endif @end |