diff options
-rw-r--r-- | Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m | 35 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRAuth.m | 2 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRAuthErrorUtils.h | 5 | ||||
-rw-r--r-- | Firebase/Auth/Source/FIRAuthErrorUtils.m | 6 | ||||
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRAuthBackend.m | 10 |
5 files changed, 52 insertions, 6 deletions
diff --git a/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m b/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m index e722c9d..1cac822 100644 --- a/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m +++ b/Example/Auth/Tests/FIRGetOOBConfirmationCodeResponseTests.m @@ -53,6 +53,11 @@ static NSString *const kTestOOBCode = @"OOBCode"; */ static NSString *const kEmailNotFoundMessage = @"EMAIL_NOT_FOUND: fake custom message"; +/** @var kMissingEmailErrorMessage + @brief The value of the "message" field returned for a "missing email" error. + */ +static NSString *const kMissingEmailErrorMessage = @"MISSING_EMAIL"; + /** @var kInvalidEmailErrorMessage @brief The error returned by the server if the email is invalid. */ @@ -234,6 +239,36 @@ static NSString *const kIosBundleID = @"testBundleID"; XCTAssertNil(RPCResponse); } +/** @fn testMissingEmailError + @brief This test checks for missing email responses, and makes sure they are decoded to the + correct error response. + */ +- (void)testMissingEmailError { + FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest + verifyEmailRequestWithAccessToken:kTestAccessToken + 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:kMissingEmailErrorMessage]; + + XCTAssert(callbackInvoked); + XCTAssertNotNil(RPCError); + XCTAssertEqualObjects(RPCError.domain, FIRAuthErrorDomain); + XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingEmail); + XCTAssertNil(RPCResponse); +} + /** @fn testInvalidEmailError @brief This test checks for the INVALID_EMAIL error message from the backend. */ diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m index d5e6b0f..33af19e 100644 --- a/Firebase/Auth/Source/FIRAuth.m +++ b/Firebase/Auth/Source/FIRAuth.m @@ -723,7 +723,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; return; } if (![request.email length]) { - decoratedCallback(nil, [FIRAuthErrorUtils missingEmail]); + decoratedCallback(nil, [FIRAuthErrorUtils missingEmailErrorWithMessage:nil]); return; } [FIRAuthBackend signUpNewUser:request diff --git a/Firebase/Auth/Source/FIRAuthErrorUtils.h b/Firebase/Auth/Source/FIRAuthErrorUtils.h index 1dde98f..a857d4b 100644 --- a/Firebase/Auth/Source/FIRAuthErrorUtils.h +++ b/Firebase/Auth/Source/FIRAuthErrorUtils.h @@ -348,11 +348,12 @@ NS_ASSUME_NONNULL_BEGIN */ + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message; -/** @fn missingEmail +/** @fn missingEmailErrorWithMessage @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingEmail code. + @param message Error message from the backend, if any. @return The NSError instance associated with the given FIRAuthError. */ -+ (NSError *)missingEmail; ++ (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message; /** @fn missingPhoneNumberErrorWithMessage: @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingPhoneNumber code. diff --git a/Firebase/Auth/Source/FIRAuthErrorUtils.m b/Firebase/Auth/Source/FIRAuthErrorUtils.m index 5c5b10a..42fb543 100644 --- a/Firebase/Auth/Source/FIRAuthErrorUtils.m +++ b/Firebase/Auth/Source/FIRAuthErrorUtils.m @@ -525,7 +525,7 @@ static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) { case FIRAuthErrorCodeMissingContinueURI: return @"ERROR_MISSING_CONTINUE_URI"; case FIRAuthErrorCodeMissingEmail: - return @"MISSING_EMAIL"; + return @"ERROR_MISSING_EMAIL"; case FIRAuthErrorCodeMissingPhoneNumber: return @"ERROR_MISSING_PHONE_NUMBER"; case FIRAuthErrorCodeInvalidPhoneNumber: @@ -803,8 +803,8 @@ static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) { return[self errorWithCode:FIRAuthInternalErrorCodeMissingContinueURI message:message]; } -+ (NSError *)missingEmail { - return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail]; ++ (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message { + return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail message:message]; } + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message { diff --git a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m index 2cfa516..8eca6d5 100644 --- a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m +++ b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m @@ -234,6 +234,12 @@ static NSString *const kExpiredActionCodeErrorMessage = @"EXPIRED_OOB_CODE"; */ static NSString *const kInvalidActionCodeErrorMessage = @"INVALID_OOB_CODE"; +/** @var kMissingEmailErrorMessage + @brief This is the error message the server will respond with if the email address is missing + during a "send password reset email" attempt. + */ +static NSString *const kMissingEmailErrorMessage = @"MISSING_EMAIL"; + /** @var kInvalidSenderEmailErrorMessage @brief This is the error message the server will respond with if the sender email is invalid during a "send password reset email" attempt. @@ -936,6 +942,10 @@ static id<FIRAuthBackendImplementation> gBackendImplementation; return [FIRAuthErrorUtils invalidActionCodeErrorWithMessage:serverDetailErrorMessage]; } + if ([shortErrorMessage isEqualToString:kMissingEmailErrorMessage]) { + return [FIRAuthErrorUtils missingEmailErrorWithMessage:serverDetailErrorMessage]; + } + if ([shortErrorMessage isEqualToString:kInvalidSenderEmailErrorMessage]) { return [FIRAuthErrorUtils invalidSenderErrorWithMessage:serverDetailErrorMessage]; } |