aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example/Auth
diff options
context:
space:
mode:
authorGravatar Ivan <gonzalezivan@google.com>2017-10-23 11:38:29 -0700
committerGravatar Ivan <gonzalezivan@google.com>2017-10-23 11:38:29 -0700
commit9f6f9693345607198750d99892a21e2fdb77fc79 (patch)
tree1f2533b966e8ca8907a4d23ac4f9f0d1948593f4 /Example/Auth
parentb561342aa69f30fbd5e66927501def426ba8337e (diff)
handles unstructured errors on redirect URLs
Diffstat (limited to 'Example/Auth')
-rw-r--r--Example/Auth/Tests/FIRPhoneAuthProviderTests.m74
1 files changed, 74 insertions, 0 deletions
diff --git a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m
index 8283ff6..d99dc0e 100644
--- a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m
+++ b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m
@@ -162,6 +162,16 @@ static NSString *const kFakeRedirectURLStringUnknownError = @"com.googleusercont
"0invalid%2520or%2520does%2520not%2520match%2520the%2520specified%2520API%2520key.%2522%257D%26"
"authType%3DverifyApp";
+/** @var kFakeRedirectURLStringUnstructuredError
+ @brief The format for a fake redirect URL string with unstructured error response.
+ */
+static NSString *const kFakeRedirectURLStringUnstructuredError = @"com.googleusercontent.apps.1"
+ "23456://firebaseauth/link?deep_link_id=https%3A%2F%2Fexample.firebaseapp.com%2F__%2Fauth%2Fcal"
+ "lback%3FfirebaseError%3D%257B%2522unstructuredcode%2522%253A%2522auth%252Funknown-error-id%2522%252"
+ "C%2522unstructuredmessage%2522%253A%2522The%2520OAuth%2520client%2520ID%2520provided%2520is%2520either%252"
+ "0invalid%2520or%2520does%2520not%2520match%2520the%2520specified%2520API%2520key.%2522%257D%26"
+ "authType%3DverifyApp";
+
/** @var kTestTimeout
@brief A fake timeout value for waiting for push notification.
*/
@@ -721,6 +731,70 @@ static const NSTimeInterval kExpectationTimeout = 1;
OCMVerifyAll(_mockNotificationManager);
}
+/** @fn testVerifyPhoneNumberUIDelegateUnstructuredError
+ @brief Tests a invocation of @c verifyPhoneNumber:UIDelegate:completion: which results in an
+ invalid client ID.
+ */
+- (void)testVerifyPhoneNumberUIDelegateUnstructuredError {
+ id mockBundle = OCMClassMock([NSBundle class]);
+ OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
+ OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
+ .andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
+ OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
+
+ // Simulate missing app token error.
+ OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
+ .andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
+ OCMExpect([_mockAppCredentialManager credential]).andReturn(nil);
+ OCMExpect([_mockAPNSTokenManager getTokenWithCallback:OCMOCK_ANY])
+ .andCallBlock1(^(FIRAuthAPNSTokenCallback callback) {
+ NSError *error = [NSError errorWithDomain:FIRAuthErrorDomain
+ code:FIRAuthErrorCodeMissingAppToken
+ userInfo:nil];
+ callback(nil, error);
+ });
+ OCMExpect([_mockBackend getProjectConfig:[OCMArg any] callback:[OCMArg any]])
+ .andCallBlock2(^(FIRGetProjectConfigRequest *request,
+ FIRGetProjectConfigResponseCallback callback) {
+ XCTAssertNotNil(request);
+ dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
+ id mockGetProjectConfigResponse = OCMClassMock([FIRGetProjectConfigResponse class]);
+ OCMStub([mockGetProjectConfigResponse authorizedDomains]).
+ andReturn(@[ kFakeAuthorizedDomain]);
+ callback(mockGetProjectConfigResponse, nil);
+ });
+ });
+ id mockUIDelegate = OCMProtocolMock(@protocol(FIRAuthUIDelegate));
+
+ // Expect view controller presentation by UIDelegate.
+ OCMExpect([_mockURLPresenter presentURL:OCMOCK_ANY
+ UIDelegate:mockUIDelegate
+ callbackMatcher:OCMOCK_ANY
+ completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) {
+ __unsafe_unretained id unretainedArgument;
+ // Indices 0 and 1 indicate the hidden arguments self and _cmd.
+ // `completion` is at index 5
+ [invocation getArgument:&unretainedArgument atIndex:5];
+ FIRAuthURLPresentationCompletion completion = unretainedArgument;
+ dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
+ completion([NSURL URLWithString:kFakeRedirectURLStringUnstructuredError], nil);
+ });
+ });
+
+ XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
+ [_provider verifyPhoneNumber:kTestPhoneNumber
+ UIDelegate:mockUIDelegate
+ completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
+ XCTAssertTrue([NSThread isMainThread]);
+ XCTAssertEqual(error.code, FIRAuthErrorCodeAppVerificationUserInteractionFailure);
+ XCTAssertNil(verificationID);
+ [expectation fulfill];
+ }];
+ [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
+ OCMVerifyAll(_mockBackend);
+ OCMVerifyAll(_mockNotificationManager);
+}
+
/** @fn testVerifyPhoneNumberUIDelegateRaiseException
@brief Tests a invocation of @c verifyPhoneNumber:UIDelegate:completion: which results in an
exception.