aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example/Auth/Tests
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2017-08-23 09:02:50 -0700
committerGravatar GitHub <noreply@github.com>2017-08-23 09:02:50 -0700
commit768c4058f3489917be7d433ad685b2f16d59aac4 (patch)
treea9ad6d452b03f518aae669316426eb3b3cbc45fa /Example/Auth/Tests
parent6e12c501f8dde3057d26149826e82489e114b2a1 (diff)
Adds reCAPTCHA Token (#211)
* Adds reCAPTCHA Token to the "send verification code" request.
Diffstat (limited to 'Example/Auth/Tests')
-rw-r--r--Example/Auth/Tests/FIRAuthBackendRPCImplementationTests.m18
-rw-r--r--Example/Auth/Tests/FIRSendVerificationCodeRequestTests.m7
-rw-r--r--Example/Auth/Tests/FIRSendVerificationCodeResponseTests.m45
3 files changed, 53 insertions, 17 deletions
diff --git a/Example/Auth/Tests/FIRAuthBackendRPCImplementationTests.m b/Example/Auth/Tests/FIRAuthBackendRPCImplementationTests.m
index b50e866..cf26546 100644
--- a/Example/Auth/Tests/FIRAuthBackendRPCImplementationTests.m
+++ b/Example/Auth/Tests/FIRAuthBackendRPCImplementationTests.m
@@ -747,23 +747,7 @@ static NSString *const kTestValue = @"TestValue";
XCTAssertNotNil(callbackError);
XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
- XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
-
- NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
- XCTAssertNotNil(underlyingError);
- XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
- XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
-
- NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
- XCTAssertNil(underlyingUnderlyingError);
-
- id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
- XCTAssertNotNil(deserializedResponse);
- XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
- XCTAssertNotNil(deserializedResponse[@"message"]);
-
- id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
- XCTAssertNil(dataResponse);
+ XCTAssertEqual(callbackError.code, FIRAuthErrorCodeCaptchaCheckFailed);
}
/** @fn testCaptchaRequiredInvalidPasswordResponse
diff --git a/Example/Auth/Tests/FIRSendVerificationCodeRequestTests.m b/Example/Auth/Tests/FIRSendVerificationCodeRequestTests.m
index 0f0b420..c908aad 100644
--- a/Example/Auth/Tests/FIRSendVerificationCodeRequestTests.m
+++ b/Example/Auth/Tests/FIRSendVerificationCodeRequestTests.m
@@ -42,6 +42,11 @@ static NSString *const kTestSecret = @"secret";
*/
static NSString *const kTestReceipt = @"receipt";
+/** @var kTestReCAPTCHAToken
+ @brief Fake reCAPTCHA token used for testing.
+ */
+static NSString *const kTestReCAPTCHAToken = @"reCAPTCHAToken";
+
/** @var kPhoneNumberKey
@brief The key for the "phone number" value in the request.
*/
@@ -101,10 +106,12 @@ static NSString *const kExpectedAPIURL =
FIRSendVerificationCodeRequest *request =
[[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:kTestPhoneNumber
appCredential:credential
+ reCAPTCHAToken:kTestReCAPTCHAToken
requestConfiguration:requestConfiguration];
XCTAssertEqualObjects(request.phoneNumber, kTestPhoneNumber);
XCTAssertEqualObjects(request.appCredential.receipt, kTestReceipt);
XCTAssertEqualObjects(request.appCredential.secret, kTestSecret);
+ XCTAssertEqualObjects(request.reCAPTCHAToken, kTestReCAPTCHAToken);
[FIRAuthBackend sendVerificationCode:request
callback:^(FIRSendVerificationCodeResponse *_Nullable response,
diff --git a/Example/Auth/Tests/FIRSendVerificationCodeResponseTests.m b/Example/Auth/Tests/FIRSendVerificationCodeResponseTests.m
index 6f917ce..8762007 100644
--- a/Example/Auth/Tests/FIRSendVerificationCodeResponseTests.m
+++ b/Example/Auth/Tests/FIRSendVerificationCodeResponseTests.m
@@ -59,6 +59,11 @@ static NSString *const kTestSecret = @"secret";
*/
static NSString *const kTestReceipt = @"receipt";
+/** @var kTestReCAPTCHAToken
+ @brief Fake reCAPTCHA token used for testing.
+ */
+static NSString *const kTestReCAPTCHAToken = @"reCAPTCHAToken";
+
/** @var kInvalidPhoneNumberErrorMessage
@brief This is the error message the server will respond with if an incorrectly formatted phone
number is provided.
@@ -77,6 +82,12 @@ static NSString *const kQuotaExceededErrorMessage = @"QUOTA_EXCEEDED";
*/
static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
+/** @var kCaptchaCheckFailedErrorMessage
+ @brief This is the error message the server will respond with if the reCAPTCHA token provided is
+ invalid.
+ */
+static NSString *const kCaptchaCheckFailedErrorMessage = @"CAPTCHA_CHECK_FAILED";
+
/** @class FIRSendVerificationCodeResponseTests
@brief Tests for @c FIRSendVerificationCodeResponseTests.
*/
@@ -120,6 +131,7 @@ static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
FIRSendVerificationCodeRequest *request =
[[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:kTestInvalidPhoneNumber
appCredential:credential
+ reCAPTCHAToken:nil
requestConfiguration:_requestConfiguration];
__block BOOL callbackInvoked;
__block FIRSendVerificationCodeResponse *RPCResponse;
@@ -148,6 +160,7 @@ static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
FIRSendVerificationCodeRequest *request =
[[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:kTestPhoneNumber
appCredential:credential
+ reCAPTCHAToken:nil
requestConfiguration:_requestConfiguration];
__block BOOL callbackInvoked;
__block FIRSendVerificationCodeResponse *RPCResponse;
@@ -177,6 +190,7 @@ static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
FIRSendVerificationCodeRequest *request =
[[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:kTestPhoneNumber
appCredential:credential
+ reCAPTCHAToken:nil
requestConfiguration:_requestConfiguration];
__block BOOL callbackInvoked;
__block FIRSendVerificationCodeResponse *RPCResponse;
@@ -196,6 +210,36 @@ static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
XCTAssertEqual(RPCError.code, FIRAuthErrorCodeAppNotVerified);
}
+/** @fn testSendVerificationCodeResponseCaptchaCheckFailedError
+ @brief Tests a failed attempt to send a verification code due to an invalid reCAPTCHA token
+ being provided in the request.
+ */
+- (void)testSendVerificationCodeResponseCaptchaCheckFailedError {
+ FIRAuthAppCredential *credential =
+ [[FIRAuthAppCredential alloc]initWithReceipt:kTestReceipt secret:kTestSecret];
+ FIRSendVerificationCodeRequest *request =
+ [[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:kTestPhoneNumber
+ appCredential:credential
+ reCAPTCHAToken:kTestReCAPTCHAToken
+ requestConfiguration:_requestConfiguration];
+ __block BOOL callbackInvoked;
+ __block FIRSendVerificationCodeResponse *RPCResponse;
+ __block NSError *RPCError;
+ [FIRAuthBackend sendVerificationCode:request
+ callback:^(FIRSendVerificationCodeResponse *_Nullable response,
+ NSError *_Nullable error) {
+ RPCResponse = response;
+ RPCError = error;
+ callbackInvoked = YES;
+ }];
+
+ [_RPCIssuer respondWithServerErrorMessage:kCaptchaCheckFailedErrorMessage];
+
+ XCTAssert(callbackInvoked);
+ XCTAssertNil(RPCResponse);
+ XCTAssertEqual(RPCError.code, FIRAuthErrorCodeCaptchaCheckFailed);
+}
+
/** @fn testSuccessfulSendVerificationCodeResponse
@brief Tests a succesful to send a verification code.
*/
@@ -205,6 +249,7 @@ static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
FIRSendVerificationCodeRequest *request =
[[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:kTestPhoneNumber
appCredential:credential
+ reCAPTCHAToken:nil
requestConfiguration:_requestConfiguration];
__block BOOL callbackInvoked;
__block FIRSendVerificationCodeResponse *RPCResponse;