aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2018-04-29 19:29:48 -0700
committerGravatar Paul Beusterien <paulbeusterien@google.com>2018-04-29 19:30:25 -0700
commitb6a84b6b61b8a1a0d8c0b79e4111a15e8bd35c53 (patch)
treed4d0b1363ee446e3e61f31ea67fef510dc674aab /Example
parentbd7d3b2a169c0c510cff8fccd00e75e8d86f4157 (diff)
Adds phone auth testing. (disableAppVerification) (#1192)
Diffstat (limited to 'Example')
-rw-r--r--Example/Auth/Sample/SettingsViewController.m17
-rw-r--r--Example/Auth/Tests/FIRPhoneAuthProviderTests.m75
2 files changed, 92 insertions, 0 deletions
diff --git a/Example/Auth/Sample/SettingsViewController.m b/Example/Auth/Sample/SettingsViewController.m
index 24a6513..4815f32 100644
--- a/Example/Auth/Sample/SettingsViewController.m
+++ b/Example/Auth/Sample/SettingsViewController.m
@@ -214,9 +214,26 @@ static NSString *truncatedString(NSString *string, NSUInteger length) {
[weakSelf loadTableView];
}],
]],
+ [StaticContentTableViewSection sectionWithTitle:@"Auth Settings" cells:@[
+ [StaticContentTableViewCell cellWithTitle:@"Disable App Verification (Phone)"
+ value:[AppManager auth].settings.
+ appVerificationDisabledForTesting ? @"Yes" : @"No"
+ action:^{
+ [weakSelf toggleDisableAppVerification];
+ [weakSelf loadTableView];
+ }],
+ ]],
]];
}
+/** @fn toggleDisableAppVerification
+ @brief Toggles the appVerificationDisabledForTesting flag on the current Auth instance.
+ */
+- (void)toggleDisableAppVerification {
+ [AppManager auth].settings.appVerificationDisabledForTesting =
+ ![AppManager auth].settings.appVerificationDisabledForTesting;
+}
+
/** @fn toggleAPIHostWithRequestClassName:
@brief Toggles the host name of the server that handles RPCs.
@param requestClassName The name of the RPC request class.
diff --git a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m
index e00fa1f..96432c7 100644
--- a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m
+++ b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m
@@ -31,6 +31,7 @@
#import "FIRAuthGlobalWorkQueue.h"
#import "FIRAuthNotificationManager.h"
#import "FIRAuthRequestConfiguration.h"
+#import "FIRAuthSettings.h"
#import "FIRAuthUIDelegate.h"
#import "FIRAuthURLPresenter.h"
#import "FIRAuthWebUtils.h"
@@ -362,6 +363,80 @@ static const NSTimeInterval kExpectationTimeout = 2;
OCMVerifyAll(_mockAppCredentialManager);
}
+/** @fn testVerifyPhoneNumberInTestMode
+ @brief Tests a successful invocation of @c verifyPhoneNumber:completion: when app verification
+ is disabled.
+ */
+- (void)testVerifyPhoneNumberInTestMode {
+ // Disable app verification.
+ FIRAuthSettings *settings = [[FIRAuthSettings alloc] init];
+ settings.appVerificationDisabledForTesting = YES;
+ OCMStub([_mockAuth settings]).andReturn(settings);
+ OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
+ .andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
+ OCMExpect([_mockBackend sendVerificationCode:[OCMArg any] callback:[OCMArg any]])
+ .andCallBlock2(^(FIRSendVerificationCodeRequest *request,
+ FIRSendVerificationCodeResponseCallback callback) {
+ XCTAssertEqualObjects(request.phoneNumber, kTestPhoneNumber);
+ // Assert that the app credential is nil when in test mode.
+ XCTAssertNil(request.appCredential);
+ dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
+ id mockSendVerificationCodeResponse = OCMClassMock([FIRSendVerificationCodeResponse class]);
+ OCMStub([mockSendVerificationCodeResponse verificationID]).andReturn(kTestVerificationID);
+ callback(mockSendVerificationCodeResponse, nil);
+ });
+ });
+
+ XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
+ [_provider verifyPhoneNumber:kTestPhoneNumber
+ completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
+ XCTAssertTrue([NSThread isMainThread]);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(verificationID, kTestVerificationID);
+ [expectation fulfill];
+ }];
+ [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
+ OCMVerifyAll(_mockBackend);
+ OCMVerifyAll(_mockNotificationManager);
+ OCMVerifyAll(_mockAppCredentialManager);
+}
+
+/** @fn testVerifyPhoneNumberInTestModeFailure
+ @brief Tests a failed invocation of @c verifyPhoneNumber:completion: when app verification
+ is disabled.
+ */
+- (void)testVerifyPhoneNumberInTestModeFailure {
+ // Disable app verification.
+ FIRAuthSettings *settings = [[FIRAuthSettings alloc] init];
+ settings.appVerificationDisabledForTesting = YES;
+ OCMStub([_mockAuth settings]).andReturn(settings);
+ OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
+ .andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
+ OCMExpect([_mockBackend sendVerificationCode:[OCMArg any] callback:[OCMArg any]])
+ .andCallBlock2(^(FIRSendVerificationCodeRequest *request,
+ FIRSendVerificationCodeResponseCallback callback) {
+ XCTAssertEqualObjects(request.phoneNumber, kTestPhoneNumber);
+ // Assert that the app credential is nil when in test mode.
+ XCTAssertNil(request.appCredential);
+ dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
+ callback(nil, [FIRAuthErrorUtils networkErrorWithUnderlyingError:[NSError new]]);
+ });
+ });
+
+ XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
+ [_provider verifyPhoneNumber:kTestPhoneNumber
+ completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
+ XCTAssertTrue([NSThread isMainThread]);
+ XCTAssertNil(verificationID);
+ XCTAssertEqual(error.code, FIRAuthErrorCodeNetworkError);
+ [expectation fulfill];
+ }];
+ [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
+ OCMVerifyAll(_mockBackend);
+ OCMVerifyAll(_mockNotificationManager);
+ OCMVerifyAll(_mockAppCredentialManager);
+}
+
/** @fn testVerifyPhoneNumberUIDelegate
@brief Tests a successful invocation of @c verifyPhoneNumber:UIDelegate:completion:.
*/