Skip to content
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

Initial config v2 support (partial) #13587

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions FirebaseAuth/Tests/Unit/AuthLifecycleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import FirebaseCore

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
class AuthLifecycleTests: XCTestCase {
private let kFakeAPIKey = "FAKE_API_KEY"
private let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")

private static let kFakeAPIKey = "FAKE_API_KEY"
private let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "",
apiKey: AuthLifecycleTests.kFakeAPIKey)
override func setUp() {
options.apiKey = kFakeAPIKey
FirebaseApp.resetApps()
FirebaseApp.configure(options: options)
}
Expand Down Expand Up @@ -56,7 +56,7 @@ class AuthLifecycleTests: XCTestCase {
*/
func testAppAPIKey() {
let auth = Auth.auth()
XCTAssertEqual(auth.requestConfiguration.apiKey, kFakeAPIKey)
XCTAssertEqual(auth.requestConfiguration.apiKey, AuthLifecycleTests.kFakeAPIKey)
}

/** @fn testAppAssociation
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Tests/Unit/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class AuthTests: RPCBaseTests {

override func setUp() {
super.setUp()
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.apiKey = AuthTests.kFakeAPIKey
options.projectID = "myProjectID"
let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "myProjectID",
apiKey: AuthTests.kFakeAPIKey)
let name = "test-AuthTests\(AuthTests.testNum)"
AuthTests.testNum = AuthTests.testNum + 1
FirebaseApp.configure(name: name, options: options)
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Tests/Unit/AuthUseUserAccessGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class UseUserAccessGroupTests: RPCBaseTests {

override class func setUp() {
let kFakeAPIKey = "FAKE_API_KEY"
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.apiKey = kFakeAPIKey
options.projectID = "myUserProjectID"
let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "myUserProjectID",
apiKey: kFakeAPIKey)
FirebaseApp.configure(name: "testUseUserAccessGroupTests", options: options)
let keychainStorageProvider = FakeAuthKeychainStorage()
auth = Auth(
Expand Down
10 changes: 4 additions & 6 deletions FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,10 @@ - (void)testObtainingOAuthCredentialWithIDToken {
*/
- (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";
FIROptions *options = [[FIROptions alloc] initWithAppID:@"0:0000000000000:ios:0000000000000000"
projectNumber:@"00000000000000000-00000000000-000000000"
projectID:@"myProjectID"
apiKey:kFakeAPIKey];
options.clientID = kFakeClientID;
[FIRApp configureWithName:@"objAppName" options:options];
FIRAuth *auth = [FIRAuth authWithApp:[FIRApp appNamed:@"objAppName"]];
Expand Down
6 changes: 4 additions & 2 deletions FirebaseAuth/Tests/Unit/IdentityToolkitRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ class IdentityToolkitRequestTests: XCTestCase {
@brief Tests the request correctly populated the tenant ID from a non default app.
*/
func testExpectedTenantIDWithNonDefaultFIRApp() {
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "myProjectID",
apiKey: kAPIKey)
options.apiKey = kAPIKey
let nonDefaultApp = FirebaseApp(instanceWithName: "nonDefaultApp", options: options)
let nonDefaultAuth = Auth(app: nonDefaultApp)
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Tests/Unit/MultiFactorResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import FirebaseCore
static var auth: Auth?
override class func setUp() {
let kFakeAPIKey = "FAKE_API_KEY"
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.apiKey = kFakeAPIKey
options.projectID = "myUserProjectID"
let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "myUserProjectID",
apiKey: kFakeAPIKey)
FirebaseApp.configure(name: "test-mfaResolver", options: options)
auth = Auth(
app: FirebaseApp.app(name: "test-mfaResolver")!
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Tests/Unit/OAuthProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ import FirebaseCore

private func initApp(_ functionName: String, useAppID: Bool = false, omitClientID: Bool = false,
scheme: String = OAuthProviderTests.kFakeReverseClientID) {
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.apiKey = OAuthProviderTests.kFakeAPIKey
options.projectID = "myProjectID"
let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "myProjectID",
apiKey: OAuthProviderTests.kFakeAPIKey)
if useAppID {
options.googleAppID = OAuthProviderTests.kFakeFirebaseAppID
}
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Tests/Unit/PhoneAuthProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,10 @@
testMode: Bool = false,
forwardingNotification: Bool = true,
fakeToken: Bool = false) {
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.apiKey = PhoneAuthProviderTests.kFakeAPIKey
options.projectID = "myProjectID"
let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "myProjectID",
apiKey: PhoneAuthProviderTests.kFakeAPIKey)
if useClientID {
options.clientID = PhoneAuthProviderTests.kFakeClientID
}
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Tests/Unit/UserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class UserTests: RPCBaseTests {
static var auth: Auth?

override class func setUp() {
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.apiKey = kFakeAPIKey
options.projectID = "myUserProjectID"
let options = FirebaseOptions(appID: "0:0000000000000:ios:0000000000000000",
projectNumber: "00000000000000000-00000000000-000000000",
projectID: "myUserProjectID",
apiKey: kFakeAPIKey)
FirebaseApp.configure(name: "test-UserTests", options: options)
#if (os(macOS) && !FIREBASE_AUTH_TESTING_USE_MACOS_KEYCHAIN) || SWIFT_PACKAGE
let keychainStorageProvider = FakeAuthKeychainStorage()
Expand Down
10 changes: 8 additions & 2 deletions FirebaseCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ Firebase Core includes FIRApp and FIROptions which provide central configuration

unit_tests.requires_app_host = true
unit_tests.dependency 'OCMock'
unit_tests.resources = 'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist'
unit_tests.resources = [
'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist',
'FirebaseCore/Tests/Unit/Resources/firebase-sdk-config-apple.json',
]
end

s.test_spec 'swift-unit' do |swift_unit_tests|
Expand All @@ -97,6 +100,9 @@ Firebase Core includes FIRApp and FIROptions which provide central configuration
}
swift_unit_tests.requires_app_host = true
swift_unit_tests.dependency 'OCMock'
swift_unit_tests.resources = 'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist'
swift_unit_tests.resources = [
'FirebaseCore/Tests/Unit/Resources/GoogleService-Info.plist',
'FirebaseCore/Tests/Unit/Resources/firebase-sdk-config-apple.json',
]
end
end
9 changes: 6 additions & 3 deletions FirebaseCore/Extension/FIROptionsInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ extern NSString *const kFIRBundleID;
extern NSString *const kFIRProjectID;

/**
* Keys for the plist file name
* Keys for the config file names.
*/
// TODO(next major): Rename from "kServiceInfo*" to "kPlist*"
extern NSString *const kServiceInfoFileName;

extern NSString *const kServiceInfoFileType;
extern NSString *const kJsonFileName;
extern NSString *const kJsonFileType;

/**
* This header file exposes the initialization of FirebaseOptions to internal use.
Expand Down Expand Up @@ -85,8 +87,9 @@ extern NSString *const kServiceInfoFileType;
*/
@property(nonatomic, readonly, copy) NSString *libraryVersionID;

// TODO(next major): Rename to usingOptionsFromDefaultConfig.
/**
* The flag indicating whether this object was constructed with the values in the default plist
* The flag indicating whether this object was constructed with the values in the default config
* file.
*/
@property(nonatomic) BOOL usingOptionsFromDefaultPlist;
Expand Down
32 changes: 16 additions & 16 deletions FirebaseCore/Sources/FIRApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
NSString *const kFirebaseCoreErrorDomain = @"com.firebase.core";

/**
* The URL to download plist files.
* The URL to download config files.
*/
static NSString *const kPlistURL = @"https://console.firebase.google.com/";
static NSString *const kConfigFileURL = @"https://console.firebase.google.com/";

@interface FIRApp ()

Expand All @@ -104,13 +104,13 @@ + (void)configure {
FIROptions *options = [FIROptions defaultOptions];
if (!options) {
#if DEBUG
[self findMisnamedGoogleServiceInfoPlist];
[self findMisnamedJsonConfig];
#endif // DEBUG
[NSException raise:kFirebaseCoreErrorDomain
format:@"`FirebaseApp.configure()` could not find "
@"a valid GoogleService-Info.plist in your project. Please download one "
@"from %@.",
kPlistURL];
@"a valid firebase-sdk-config-apple.json in your project. Please "
@"download one from %@.",
kConfigFileURL];
}
[FIRApp configureWithOptions:options];
}
Expand Down Expand Up @@ -541,7 +541,7 @@ - (void)checkExpectedBundleID {
@"plist file, you may change your app's bundle identifier to '%@'. Or you can "
@"download a new configuration file that matches your bundle identifier from %@ "
@"and replace the current one.",
kServiceInfoFileName, kServiceInfoFileType, expectedBundleID, kPlistURL);
kJsonFileName, kJsonFileType, expectedBundleID, kConfigFileURL);
}
}

Expand All @@ -560,13 +560,13 @@ - (BOOL)isAppIDValid {
if (!isValid) {
NSString *expectedBundleID = [self expectedBundleID];
FIRLogError(kFIRLoggerCore, @"I-COR000009",
@"The GOOGLE_APP_ID either in the plist file "
@"The GOOGLE_APP_ID either in the config file "
@"'%@.%@' or the one set in the customized options is invalid. If you are using "
@"the plist file, use the iOS version of bundle identifier to download the file, "
@"the config file, use the iOS version of bundle identifier to download the file, "
@"and do not manually edit the GOOGLE_APP_ID. You may change your app's bundle "
@"identifier to '%@'. Or you can download a new configuration file that matches "
@"your bundle identifier from %@ and replace the current one.",
kServiceInfoFileName, kServiceInfoFileType, expectedBundleID, kPlistURL);
kJsonFileName, kJsonFileType, expectedBundleID, kConfigFileURL);
};
return isValid;
}
Expand Down Expand Up @@ -624,7 +624,7 @@ + (NSString *)actualBundleID {
* This method does not verify that the contents of the app id are correct, just that they fulfill
* the expected format.
*
* @param appID Contents of GOOGLE_APP_ID from the plist file.
* @param appID Contents of GOOGLE_APP_ID from the config file.
* @param version Indicates what version of the app id format this string should be.
* @return YES if provided string fulfills the expected format, NO otherwise.
*/
Expand Down Expand Up @@ -706,7 +706,7 @@ + (BOOL)validateAppIDFormat:(NSString *)appID withVersion:(NSString *)version {
*
* Note that the v1 hash algorithm is not permitted on the client and cannot be fully validated.
*
* @param appID Contents of GOOGLE_APP_ID from the plist file.
* @param appID Contents of GOOGLE_APP_ID from the config file.
* @param version Indicates what version of the app id format this string should be.
* @return YES if provided string fulfills the expected hashed bundle ID and the version is known,
* NO otherwise.
Expand Down Expand Up @@ -747,7 +747,7 @@ - (NSString *)expectedBundleID {

// end App ID validation

#pragma mark - Reading From Plist & User Defaults
#pragma mark - Reading From Config file & User Defaults

/**
* Clears the data collection switch from the standard NSUserDefaults for easier testing and
Expand Down Expand Up @@ -866,11 +866,11 @@ - (void)appDidBecomeActive:(NSNotification *)notification {
}

#if DEBUG
+ (void)findMisnamedGoogleServiceInfoPlist {
+ (void)findMisnamedJsonConfig {
for (NSBundle *bundle in [NSBundle allBundles]) {
// Not recursive, but we're looking for misnames, not people accidentally
// hiding their config file in a subdirectory of their bundle.
NSArray *plistPaths = [bundle pathsForResourcesOfType:@"plist" inDirectory:nil];
NSArray *plistPaths = [bundle pathsForResourcesOfType:@"json" inDirectory:nil];
for (NSString *path in plistPaths) {
@autoreleasepool {
NSDictionary<NSString *, id> *contents = [NSDictionary dictionaryWithContentsOfFile:path];
Expand All @@ -883,7 +883,7 @@ + (void)findMisnamedGoogleServiceInfoPlist {
[NSException raise:kFirebaseCoreErrorDomain
format:@"`FirebaseApp.configure()` could not find the default "
@"configuration plist in your project, but did find one at "
@"%@. Please rename this file to GoogleService-Info.plist to "
@"%@. Please rename this file to firebase-sdk-config-apple.json to "
@"use it as the default configuration.",
path];
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseCore/Sources/FIRComponentContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ - (BOOL)isAppForARCore:(FIRApp *)app {
p1[7], p2[7], p1[8], p2[8], p1[9], p2[9], p1[10],
p2[10], p1[11], p2[11], p1[12], p2[12], '\0'};
NSString *gcmSenderID = [NSString stringWithUTF8String:gcmSenderIDKey];
return [app.options.GCMSenderID isEqualToString:gcmSenderID];
return [app.options.projectNumber isEqualToString:gcmSenderID];
}
return NO;
}
Expand Down
Loading
Loading