diff options
Diffstat (limited to 'Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m')
-rw-r--r-- | Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m | 203 |
1 files changed, 195 insertions, 8 deletions
diff --git a/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m b/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m index 98c9d8e..71ab41c 100644 --- a/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m +++ b/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m @@ -16,6 +16,7 @@ #import <XCTest/XCTest.h> +#import "FIRActionCodeSettings.h" #import "FIRAuthErrors.h" #import "FIRAuthBackend.h" #import "FIRGetOOBConfirmationCodeRequest.h" @@ -69,6 +70,23 @@ static NSString *const kInvalidMessagePayloadErrorMessage = @"INVALID_MESSAGE_PA */ static NSString *const kInvalidSenderErrorMessage = @"INVALID_SENDER"; +/** @var kMissingIosBundleIDErrorMessage + @brief This is the error message the server will respond with if iOS bundle ID is missing but + the iOS App store ID is provided. + */ +static NSString *const kMissingIosBundleIDErrorMessage = @"MISSING_IOS_BUNDLE_ID"; + +/** @var kMissingAndroidPackageNameErrorMessage + @brief This is the error message the server will respond with if Android Package Name is missing + but the flag indicating the app should be installed is set to true. + */ +static NSString *const kMissingAndroidPackageNameErrorMessage = @"MISSING_ANDROID_PACKAGE_NAME"; + +/** @var kUnauthorizedDomainErrorMessage + @brief This is the error message the server will respond with if the domain of the continue URL + specified is not whitelisted in the firebase console. + */ +static NSString *const kUnauthorizedDomainErrorMessage = @"ERROR_UNAUTHORIZED_DOMAIN"; /** @var kInvalidRecipientEmailErrorMessage @brief This is the prefix for the error message the server responds with if the recipient email @@ -76,6 +94,23 @@ static NSString *const kInvalidSenderErrorMessage = @"INVALID_SENDER"; */ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_EMAIL"; +/** @var kInvalidContinueURIErrorMessage + @brief This is the error returned by the backend if the continue URL provided in the request + is invalid. + */ +static NSString *const kInvalidContinueURIErrorMessage = @"INVALID_CONTINUE_URI"; + +/** @var kMissingContinueURIErrorMessage + @brief This is the error message the server will respond with if there was no continue URI + present in a request that required one. + */ +static NSString *const kMissingContinueURIErrorMessage = @"MISSING_CONTINUE_URI"; + +/** @var kIosBundleID + @brief Fake iOS bundle ID for testing. + */ +static NSString *const kIosBundleID = @"testBundleID"; + /** @class FIRGetOOBConfirmationCodeResponseTests @brief Tests for @c FIRGetOOBConfirmationCodeResponse. */ @@ -87,6 +122,11 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it. */ FIRFakeBackendRPCIssuer *_RPCIssuer; + + /** @var _requestConfiguration + @brief This is the request configuration used for testing. + */ + FIRAuthRequestConfiguration *_requestConfiguration; } - (void)setUp { @@ -94,9 +134,11 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init]; [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer]; _RPCIssuer = RPCIssuer; + _requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey]; } - (void)tearDown { + _requestConfiguration = nil; _RPCIssuer = nil; [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil]; [super tearDown]; @@ -109,7 +151,8 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ - (void)testSuccessfulPasswordResetResponse { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; @@ -139,7 +182,8 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ - (void)testSuccessfulPasswordResetResponseWithoutOOBCode { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; @@ -167,7 +211,8 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ - (void)testEmailNotFoundError { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; @@ -195,7 +240,8 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ - (void)testInvalidEmailError { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; __block NSError *RPCError; @@ -222,7 +268,8 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ - (void)testInvalidMessagePayloadError { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; __block NSError *RPCError; @@ -246,7 +293,8 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ - (void)testInvalidSenderError { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; @@ -264,13 +312,139 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidSender); } +/** @fn testMissingIosBundleIDError + @brief Tests for @c FIRAuthErrorCodeMissingIosBundleID. + */ +- (void)testMissingIosBundleIDError { + FIRGetOOBConfirmationCodeRequest *request = + [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; + + __block BOOL callbackInvoked; + __block FIRGetOOBConfirmationCodeResponse *RPCResponse; + __block NSError *RPCError; + [FIRAuthBackend getOOBConfirmationCode:request + callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response, + NSError *_Nullable error) { + callbackInvoked = YES; + RPCResponse = response; + RPCError = error; + }]; + [_RPCIssuer respondWithServerErrorMessage:kMissingIosBundleIDErrorMessage]; + XCTAssert(callbackInvoked); + XCTAssertNil(RPCResponse); + XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingIosBundleID); +} + +/** @fn testMissingAndroidPackageNameError + @brief Tests for @c FIRAuthErrorCodeMissingAndroidPackageName. + */ +- (void)testMissingAndroidPackageNameError { + FIRGetOOBConfirmationCodeRequest *request = + [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; + + __block BOOL callbackInvoked; + __block FIRGetOOBConfirmationCodeResponse *RPCResponse; + __block NSError *RPCError; + [FIRAuthBackend getOOBConfirmationCode:request + callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response, + NSError *_Nullable error) { + callbackInvoked = YES; + RPCResponse = response; + RPCError = error; + }]; + [_RPCIssuer respondWithServerErrorMessage:kMissingAndroidPackageNameErrorMessage]; + XCTAssert(callbackInvoked); + XCTAssertNil(RPCResponse); + XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingAndroidPackageName); +} + +/** @fn testUnauthorizedDomainError + @brief Tests for @c FIRAuthErrorCodeUnauthorizedDomain. + */ +- (void)testUnauthorizedDomainError { + FIRGetOOBConfirmationCodeRequest *request = + [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; + + __block BOOL callbackInvoked; + __block FIRGetOOBConfirmationCodeResponse *RPCResponse; + __block NSError *RPCError; + [FIRAuthBackend getOOBConfirmationCode:request + callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response, + NSError *_Nullable error) { + callbackInvoked = YES; + RPCResponse = response; + RPCError = error; + }]; + [_RPCIssuer respondWithServerErrorMessage:kUnauthorizedDomainErrorMessage]; + XCTAssert(callbackInvoked); + XCTAssertNil(RPCResponse); + XCTAssertEqual(RPCError.code, FIRAuthErrorCodeUnauthorizedDomain); +} + +/** @fn testInvalidContinueURIError + @brief Tests for @c FIRAuthErrorCodeInvalidContinueAuthURI. + */ +- (void)testInvalidContinueURIError { + FIRGetOOBConfirmationCodeRequest *request = + [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; + + __block BOOL callbackInvoked; + __block FIRGetOOBConfirmationCodeResponse *RPCResponse; + __block NSError *RPCError; + [FIRAuthBackend getOOBConfirmationCode:request + callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response, + NSError *_Nullable error) { + callbackInvoked = YES; + RPCResponse = response; + RPCError = error; + }]; + [_RPCIssuer respondWithServerErrorMessage:kInvalidContinueURIErrorMessage]; + XCTAssert(callbackInvoked); + XCTAssertNil(RPCResponse); + XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidContinueURI); +} + +/** @fn testMissingContinueURIError + @brief Tests for @c FIRAuthErrorCodeMissingContinueURI. + */ +- (void)testMissingContinueURIError { + FIRGetOOBConfirmationCodeRequest *request = + [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; + + __block BOOL callbackInvoked; + __block FIRGetOOBConfirmationCodeResponse *RPCResponse; + __block NSError *RPCError; + [FIRAuthBackend getOOBConfirmationCode:request + callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response, + NSError *_Nullable error) { + callbackInvoked = YES; + RPCResponse = response; + RPCError = error; + }]; + [_RPCIssuer respondWithServerErrorMessage:kMissingContinueURIErrorMessage]; + XCTAssert(callbackInvoked); + XCTAssertNil(RPCResponse); + XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingContinueURI); +} + /** @fn testInvalidRecipientEmailError @brief Tests for @c FIRAuthErrorCodeInvalidRecipientEmail. */ - (void)testInvalidRecipientEmailError { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; @@ -295,7 +469,8 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ - (void)testSuccessfulEmailVerificationResponse { FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail - APIKey:kTestAPIKey]; + actionCodeSettings:[self fakeActionCodeSettings] + requestConfiguration:_requestConfiguration]; __block BOOL callbackInvoked; __block FIRGetOOBConfirmationCodeResponse *RPCResponse; __block NSError *RPCError; @@ -317,4 +492,16 @@ static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_ XCTAssertEqualObjects(RPCResponse.OOBCode, kTestOOBCode); } +#pragma mark - Helpers + +/** @fn fakeActionCodeSettings + @brief Constructs and returns a fake instance of @c FIRActionCodeSettings for testing. + @return An instance of @c FIRActionCodeSettings for testing. + */ +- (FIRActionCodeSettings *)fakeActionCodeSettings { + FIRActionCodeSettings *actionCodeSettings = [[FIRActionCodeSettings alloc] init]; + [actionCodeSettings setIOSBundleID:kIosBundleID]; + return actionCodeSettings; +} + @end |