@@ -268,16 +268,16 @@ - (void)testObtainingOAuthProvider {
268
268
@brief Tests a successful invocation of @c getCredentialWithUIDelegte:completion:
269
269
*/
270
270
- (void )testGetCredentialWithUIDelegateWithClientID {
271
- OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
272
- _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
273
-
274
271
id mockBundle = OCMClassMock ([NSBundle class ]);
275
272
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
276
273
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
277
274
@{@" CFBundleURLSchemes" : @[ kFakeReverseClientID ]}
278
275
]);
279
276
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
280
277
278
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
279
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
280
+
281
281
OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
282
282
.andCallBlock2 (
283
283
^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
@@ -371,16 +371,16 @@ - (void)testGetCredentialWithUIDelegateWithClientID {
371
371
cancelation.
372
372
*/
373
373
- (void )testGetCredentialWithUIDelegateUserCancellationWithClientID {
374
- OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
375
- _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
376
-
377
374
id mockBundle = OCMClassMock ([NSBundle class ]);
378
375
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
379
376
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
380
377
@{@" CFBundleURLSchemes" : @[ kFakeReverseClientID ]}
381
378
]);
382
379
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
383
380
381
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
382
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
383
+
384
384
OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
385
385
.andCallBlock2 (
386
386
^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
@@ -471,16 +471,16 @@ - (void)testGetCredentialWithUIDelegateUserCancellationWithClientID {
471
471
failed network request within the web context.
472
472
*/
473
473
- (void )testGetCredentialWithUIDelegateNetworkRequestFailedWithClientID {
474
- OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
475
- _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
476
-
477
474
id mockBundle = OCMClassMock ([NSBundle class ]);
478
475
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
479
476
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
480
477
@{@" CFBundleURLSchemes" : @[ kFakeReverseClientID ]}
481
478
]);
482
479
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
483
480
481
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
482
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
483
+
484
484
OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
485
485
.andCallBlock2 (
486
486
^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
@@ -569,16 +569,16 @@ - (void)testGetCredentialWithUIDelegateNetworkRequestFailedWithClientID {
569
569
internal error within the web context.
570
570
*/
571
571
- (void )testGetCredentialWithUIDelegateInternalErrorWithClientID {
572
- OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
573
- _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
574
-
575
572
id mockBundle = OCMClassMock ([NSBundle class ]);
576
573
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
577
574
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
578
575
@{@" CFBundleURLSchemes" : @[ kFakeReverseClientID ]}
579
576
]);
580
577
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
581
578
579
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
580
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
581
+
582
582
OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
583
583
.andCallBlock2 (
584
584
^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
@@ -668,16 +668,16 @@ - (void)testGetCredentialWithUIDelegateInternalErrorWithClientID {
668
668
use of an invalid client ID.
669
669
*/
670
670
- (void )testGetCredentialWithUIDelegateInvalidClientID {
671
- OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
672
- _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
673
-
674
671
id mockBundle = OCMClassMock ([NSBundle class ]);
675
672
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
676
673
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
677
674
@{@" CFBundleURLSchemes" : @[ kFakeReverseClientID ]}
678
675
]);
679
676
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
680
677
678
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
679
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
680
+
681
681
OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
682
682
.andCallBlock2 (
683
683
^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
@@ -767,16 +767,16 @@ - (void)testGetCredentialWithUIDelegateInvalidClientID {
767
767
unknown error.
768
768
*/
769
769
- (void )testGetCredentialWithUIDelegateUnknownErrorWithClientID {
770
- OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
771
- _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
772
-
773
770
id mockBundle = OCMClassMock ([NSBundle class ]);
774
771
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
775
772
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
776
773
@{@" CFBundleURLSchemes" : @[ kFakeReverseClientID ]}
777
774
]);
778
775
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
779
776
777
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
778
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
779
+
780
780
OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
781
781
.andCallBlock2 (
782
782
^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
@@ -866,15 +866,119 @@ - (void)testGetCredentialWithUIDelegateUnknownErrorWithClientID {
866
866
@brief Tests a successful invocation of @c getCredentialWithUIDelegte:completion:
867
867
*/
868
868
- (void )testGetCredentialWithUIDelegateWithFirebaseAppID {
869
+ id mockBundle = OCMClassMock ([NSBundle class ]);
870
+ OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
871
+ OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
872
+ @{@" CFBundleURLSchemes" : @[ kFakeEncodedFirebaseAppID ]}
873
+ ]);
874
+ OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
875
+
869
876
_provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
870
877
878
+ OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
879
+ .andCallBlock2 (
880
+ ^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
881
+ XCTAssertNotNil (request);
882
+ dispatch_async (FIRAuthGlobalWorkQueue (), ^() {
883
+ id mockGetProjectConfigResponse = OCMClassMock ([FIRGetProjectConfigResponse class ]);
884
+ OCMStub ([mockGetProjectConfigResponse authorizedDomains ]).andReturn (@[
885
+ kFakeAuthorizedDomain
886
+ ]);
887
+ callback (mockGetProjectConfigResponse, nil );
888
+ });
889
+ });
890
+
891
+ id mockUIDelegate = OCMProtocolMock (@protocol (FIRAuthUIDelegate));
892
+
893
+ // Expect view controller presentation by UIDelegate.
894
+ OCMExpect ([_mockURLPresenter presentURL: OCMOCK_ANY
895
+ UIDelegate: mockUIDelegate
896
+ callbackMatcher: OCMOCK_ANY
897
+ completion: OCMOCK_ANY])
898
+ .andDo (^(NSInvocation *invocation) {
899
+ __unsafe_unretained id unretainedArgument;
900
+ // Indices 0 and 1 indicate the hidden arguments self and _cmd.
901
+ // `presentURL` is at index 2.
902
+ [invocation getArgument: &unretainedArgument atIndex: 2 ];
903
+ NSURL *presentURL = unretainedArgument;
904
+ XCTAssertEqualObjects (presentURL.scheme , @" https" );
905
+ XCTAssertEqualObjects (presentURL.host , kFakeAuthorizedDomain );
906
+ XCTAssertEqualObjects (presentURL.path , @" /__/auth/handler" );
907
+ NSDictionary *params = [FIRAuthWebUtils dictionaryWithHttpArgumentsString: presentURL.query];
908
+ XCTAssertEqualObjects (params[@" ibi" ], kFakeBundleID );
909
+ XCTAssertEqualObjects (params[@" appId" ], kFakeFirebaseAppID );
910
+ XCTAssertEqualObjects (params[@" apiKey" ], kFakeAPIKey );
911
+ XCTAssertEqualObjects (params[@" authType" ], @" signInWithRedirect" );
912
+ XCTAssertNotNil (params[@" v" ]);
913
+ // `callbackMatcher` is at index 4
914
+ [invocation getArgument: &unretainedArgument atIndex: 4 ];
915
+ FIRAuthURLCallbackMatcher callbackMatcher = unretainedArgument;
916
+ NSMutableString *redirectURL = [NSMutableString
917
+ stringWithString: [kFakeEncodedFirebaseAppID
918
+ stringByAppendingString: kFakeRedirectURLResponseURL ]];
919
+ // Add fake OAuthResponse to callback.
920
+ [redirectURL appendString: kFakeOAuthResponseURL ];
921
+ // Verify that the URL is rejected by the callback matcher without the event ID.
922
+ XCTAssertFalse (callbackMatcher ([NSURL URLWithString: redirectURL]));
923
+ [redirectURL appendString: @" %26e ventId%3D " ];
924
+ [redirectURL appendString: params[@" eventId" ]];
925
+ NSURLComponents *originalComponents = [[NSURLComponents alloc ] initWithString: redirectURL];
926
+ // Verify that the URL is accepted by the callback matcher with the matching event ID.
927
+ XCTAssertTrue (callbackMatcher ([originalComponents URL ]));
928
+ NSURLComponents *components = [originalComponents copy ];
929
+ components.query = @" https" ;
930
+ XCTAssertFalse (callbackMatcher ([components URL ]));
931
+ components = [originalComponents copy ];
932
+ components.host = @" badhost" ;
933
+ XCTAssertFalse (callbackMatcher ([components URL ]));
934
+ components = [originalComponents copy ];
935
+ components.path = @" badpath" ;
936
+ XCTAssertFalse (callbackMatcher ([components URL ]));
937
+ components = [originalComponents copy ];
938
+ components.query = @" badquery" ;
939
+ XCTAssertFalse (callbackMatcher ([components URL ]));
940
+
941
+ // `completion` is at index 5
942
+ [invocation getArgument: &unretainedArgument atIndex: 5 ];
943
+ FIRAuthURLPresentationCompletion completion = unretainedArgument;
944
+ dispatch_async (FIRAuthGlobalWorkQueue (), ^() {
945
+ completion (originalComponents.URL , nil );
946
+ });
947
+ });
948
+
949
+ XCTestExpectation *expectation = [self expectationWithDescription: @" callback" ];
950
+ [_provider
951
+ getCredentialWithUIDelegate: mockUIDelegate
952
+ completion: ^(FIRAuthCredential *_Nullable credential,
953
+ NSError *_Nullable error) {
954
+ XCTAssertTrue ([NSThread isMainThread ]);
955
+ XCTAssertNil (error);
956
+ XCTAssertTrue ([credential isKindOfClass: [FIROAuthCredential class ]]);
957
+ FIROAuthCredential *OAuthCredential = (FIROAuthCredential *)credential;
958
+ XCTAssertEqualObjects (kFakeOAuthResponseURL ,
959
+ OAuthCredential.OAuthResponseURLString );
960
+ [expectation fulfill ];
961
+ }];
962
+ [self waitForExpectationsWithTimeout: kExpectationTimeout handler: nil ];
963
+ OCMVerifyAll (_mockBackend);
964
+ }
965
+
966
+ /* * @fn testGetCredentialWithUIDelegateWithFirebaseAppIDWhileClientIdPresent
967
+ @brief Tests a successful invocation of @c getCredentialWithUIDelegte:completion: when the
968
+ client ID is present in the plist file, but the encoded app ID is the registered custom URL
969
+ scheme.
970
+ */
971
+ - (void )testGetCredentialWithUIDelegateWithFirebaseAppIDWhileClientIdPresent {
871
972
id mockBundle = OCMClassMock ([NSBundle class ]);
872
973
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
873
974
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
874
975
@{@" CFBundleURLSchemes" : @[ kFakeEncodedFirebaseAppID ]}
875
976
]);
876
977
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
877
978
979
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
980
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
981
+
878
982
OCMExpect ([_mockBackend getProjectConfig: [OCMArg any ] callback: [OCMArg any ]])
879
983
.andCallBlock2 (
880
984
^(FIRGetProjectConfigRequest *request, FIRGetProjectConfigResponseCallback callback) {
@@ -968,19 +1072,19 @@ - (void)testGetCredentialWithUIDelegateWithFirebaseAppID {
968
1072
emulator.
969
1073
*/
970
1074
- (void )testGetCredentialWithUIDelegateUseEmulator {
971
- OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
972
- NSString *emulatorHostAndPort =
973
- [NSString stringWithFormat: @" %@ :%@ " , kFakeEmulatorHost , kFakeEmulatorPort ];
974
- OCMStub ([_mockRequestConfiguration emulatorHostAndPort ]).andReturn (emulatorHostAndPort);
975
- _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
976
-
977
1075
id mockBundle = OCMClassMock ([NSBundle class ]);
978
1076
OCMStub (ClassMethod ([mockBundle mainBundle ])).andReturn (mockBundle);
979
1077
OCMStub ([mockBundle objectForInfoDictionaryKey: @" CFBundleURLTypes" ]).andReturn (@[
980
1078
@{@" CFBundleURLSchemes" : @[ kFakeReverseClientID ]}
981
1079
]);
982
1080
OCMStub ([mockBundle bundleIdentifier ]).andReturn (kFakeBundleID );
983
1081
1082
+ OCMStub ([_mockOptions clientID ]).andReturn (kFakeClientID );
1083
+ NSString *emulatorHostAndPort =
1084
+ [NSString stringWithFormat: @" %@ :%@ " , kFakeEmulatorHost , kFakeEmulatorPort ];
1085
+ OCMStub ([_mockRequestConfiguration emulatorHostAndPort ]).andReturn (emulatorHostAndPort);
1086
+ _provider = [FIROAuthProvider providerWithProviderID: kFakeProviderID auth: _mockAuth];
1087
+
984
1088
id mockUIDelegate = OCMProtocolMock (@protocol (FIRAuthUIDelegate));
985
1089
986
1090
// Expect view controller presentation by UIDelegate.
0 commit comments