-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix and Regression Test for FirebaseUI 1199 #13505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/* | ||
* Copyright 2017 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <TargetConditionals.h> | ||
#if TARGET_OS_IOS | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
@import FirebaseAuth; | ||
@import FirebaseCore; | ||
|
||
/** @var kExpectationTimeout | ||
@brief The maximum time waiting for expectations to fulfill. | ||
*/ | ||
static const NSTimeInterval kExpectationTimeout = 1; | ||
|
||
/** @var kFakeAuthorizedDomain | ||
@brief A fake authorized domain for the app. | ||
*/ | ||
static NSString *const kFakeAuthorizedDomain = @"test.firebaseapp.com"; | ||
|
||
/** @var kFakeBundleID | ||
@brief A fake bundle ID. | ||
*/ | ||
static NSString *const kFakeBundleID = @"com.firebaseapp.example"; | ||
|
||
/** @var kFakeAccessToken | ||
@brief A fake access token for testing. | ||
*/ | ||
static NSString *const kFakeAccessToken = @"fakeAccessToken"; | ||
|
||
/** @var kFakeIDToken | ||
@brief A fake ID token for testing. | ||
*/ | ||
static NSString *const kFakeIDToken = @"fakeIDToken"; | ||
|
||
/** @var kFakeProviderID | ||
@brief A fake provider ID for testing. | ||
*/ | ||
static NSString *const kFakeProviderID = @"fakeProviderID"; | ||
|
||
/** @var kFakeGivenName | ||
@brief A fake given name for testing. | ||
*/ | ||
static NSString *const kFakeGivenName = @"fakeGivenName"; | ||
|
||
/** @var kFakeFamilyName | ||
@brief A fake family name for testing. | ||
*/ | ||
static NSString *const kFakeFamilyName = @"fakeFamilyName"; | ||
|
||
/** @var kFakeAPIKey | ||
@brief A fake API key. | ||
*/ | ||
static NSString *const kFakeAPIKey = @"asdfghjkl"; | ||
|
||
/** @var kFakeEmulatorHost | ||
@brief A fake emulator host. | ||
*/ | ||
static NSString *const kFakeEmulatorHost = @"emulatorhost"; | ||
|
||
/** @var kFakeEmulatorPort | ||
@brief A fake emulator port. | ||
*/ | ||
static NSString *const kFakeEmulatorPort = @"12345"; | ||
|
||
/** @var kFakeClientID | ||
@brief A fake client ID. | ||
*/ | ||
static NSString *const kFakeClientID = @"123456.apps.googleusercontent.com"; | ||
|
||
/** @var kFakeReverseClientID | ||
@brief The dot-reversed version of the fake client ID. | ||
*/ | ||
static NSString *const kFakeReverseClientID = @"com.googleusercontent.apps.123456"; | ||
|
||
/** @var kFakeFirebaseAppID | ||
@brief A fake Firebase app ID. | ||
*/ | ||
static NSString *const kFakeFirebaseAppID = @"1:123456789:ios:123abc456def"; | ||
|
||
/** @var kFakeEncodedFirebaseAppID | ||
@brief A fake encoded Firebase app ID to be used as a custom URL scheme. | ||
*/ | ||
static NSString *const kFakeEncodedFirebaseAppID = @"app-1-123456789-ios-123abc456def"; | ||
|
||
/** @var kFakeTenantID | ||
@brief A fake tenant ID. | ||
*/ | ||
static NSString *const kFakeTenantID = @"tenantID"; | ||
|
||
/** @var kFakeOAuthResponseURL | ||
@brief A fake OAuth response URL used in test. | ||
*/ | ||
static NSString *const kFakeOAuthResponseURL = @"fakeOAuthResponseURL"; | ||
|
||
/** @var kFakeRedirectURLResponseURL | ||
@brief A fake callback URL (minus the scheme) containing a fake response URL. | ||
*/ | ||
|
||
@interface FIROAuthProviderTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation FIROAuthProviderTests | ||
|
||
/** @fn testObtainingOAuthCredentialNoIDToken | ||
@brief Tests the correct creation of an OAuthCredential without an IDToken. | ||
*/ | ||
- (void)testObtainingOAuthCredentialNoIDToken { | ||
FIRAuthCredential *credential = [FIROAuthProvider credentialWithProviderID:kFakeProviderID | ||
accessToken:kFakeAccessToken]; | ||
XCTAssertTrue([credential isKindOfClass:[FIROAuthCredential class]]); | ||
FIROAuthCredential *OAuthCredential = (FIROAuthCredential *)credential; | ||
XCTAssertEqualObjects(OAuthCredential.accessToken, kFakeAccessToken); | ||
XCTAssertEqualObjects(OAuthCredential.provider, kFakeProviderID); | ||
XCTAssertNil(OAuthCredential.IDToken); | ||
} | ||
|
||
/** @fn testObtainingOAuthCredentialWithFullName | ||
@brief Tests the correct creation of an OAuthCredential with a fullName. | ||
*/ | ||
- (void)testObtainingOAuthCredentialWithFullName { | ||
NSPersonNameComponents *fullName = [[NSPersonNameComponents alloc] init]; | ||
fullName.givenName = kFakeGivenName; | ||
fullName.familyName = kFakeFamilyName; | ||
FIRAuthCredential *credential = [FIROAuthProvider appleCredentialWithIDToken:kFakeIDToken | ||
rawNonce:nil | ||
fullName:fullName]; | ||
|
||
XCTAssertTrue([credential isKindOfClass:[FIROAuthCredential class]]); | ||
FIROAuthCredential *OAuthCredential = (FIROAuthCredential *)credential; | ||
XCTAssertEqualObjects(OAuthCredential.provider, @"apple.com"); | ||
XCTAssertEqualObjects(OAuthCredential.IDToken, kFakeIDToken); | ||
XCTAssertNil(OAuthCredential.accessToken); | ||
} | ||
|
||
/** @fn testObtainingOAuthCredentialWithIDToken | ||
@brief Tests the correct creation of an OAuthCredential with an IDToken | ||
*/ | ||
- (void)testObtainingOAuthCredentialWithIDToken { | ||
FIRAuthCredential *credential = [FIROAuthProvider credentialWithProviderID:kFakeProviderID | ||
IDToken:kFakeIDToken | ||
accessToken:kFakeAccessToken]; | ||
XCTAssertTrue([credential isKindOfClass:[FIROAuthCredential class]]); | ||
FIROAuthCredential *OAuthCredential = (FIROAuthCredential *)credential; | ||
XCTAssertEqualObjects(OAuthCredential.accessToken, kFakeAccessToken); | ||
XCTAssertEqualObjects(OAuthCredential.provider, kFakeProviderID); | ||
XCTAssertEqualObjects(OAuthCredential.IDToken, kFakeIDToken); | ||
} | ||
|
||
/** @fn testGetCredentialWithUIDelegateWithClientIDOnMainThread | ||
@brief Verifies @c getCredentialWithUIDelegate:completion: calls its completion handler on the | ||
main thread. Regression test for firebase/FirebaseUI-iOS#1199. | ||
*/ | ||
- (void)testGetCredentialWithUIDelegateWithClientIDOnMainThread { | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; | ||
|
||
FIROptions *options = | ||
[[FIROptions alloc] initWithGoogleAppID:@"0:0000000000000:ios:0000000000000000" | ||
GCMSenderID:@"00000000000000000-00000000000-000000000"]; | ||
options.APIKey = kFakeAPIKey; | ||
options.projectID = @"myProjectID"; | ||
options.clientID = kFakeClientID; | ||
[FIRApp configureWithName:@"objAppName" options:options]; | ||
FIRAuth *auth = [FIRAuth authWithApp:[FIRApp appNamed:@"objAppName"]]; | ||
[auth setMainBundleUrlTypes:@[ @{@"CFBundleURLSchemes" : @[ kFakeReverseClientID ]} ]]; | ||
|
||
FIROAuthProvider *provider = [FIROAuthProvider providerWithProviderID:kFakeProviderID auth:auth]; | ||
[provider getCredentialWithUIDelegate:nil | ||
completion:^(FIRAuthCredential *_Nullable credential, | ||
NSError *_Nullable error) { | ||
XCTAssertTrue([NSThread isMainThread]); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; | ||
} | ||
@end | ||
|
||
#endif // TARGET_OS_IOS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.