Skip to content

Commit d4beb34

Browse files
authored
[Core] Fix API misnomer within FIRApp.m (#11648)
1 parent 45c3004 commit d4beb34

File tree

2 files changed

+51
-49
lines changed

2 files changed

+51
-49
lines changed

FirebaseCore/Sources/FIRApp.m

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,11 @@ - (void)checkExpectedBundleID {
573573
#pragma mark - private - App ID Validation
574574

575575
/**
576-
* Validates the format and fingerprint of the app ID contained in GOOGLE_APP_ID in the plist file.
577-
* This is the main method for validating app ID.
576+
* Validates the format of app ID and its included bundle ID hash contained in GOOGLE_APP_ID in the
577+
* plist file. This is the main method for validating app ID.
578578
*
579-
* @return YES if the app ID fulfills the expected format and fingerprint, NO otherwise.
579+
* @return YES if the app ID fulfills the expected format and contains a hashed bundle ID, NO
580+
* otherwise.
580581
*/
581582
- (BOOL)isAppIDValid {
582583
NSString *appID = _options.googleAppID;
@@ -597,7 +598,7 @@ - (BOOL)isAppIDValid {
597598

598599
+ (BOOL)validateAppID:(NSString *)appID {
599600
// Failing validation only occurs when we are sure we are looking at a V2 app ID and it does not
600-
// have a valid fingerprint, otherwise we just warn about the potential issue.
601+
// have a valid hashed bundle ID, otherwise we just warn about the potential issue.
601602
if (!appID.length) {
602603
return NO;
603604
}
@@ -627,7 +628,7 @@ + (BOOL)validateAppID:(NSString *)appID {
627628
return NO;
628629
}
629630

630-
if (![self validateAppIDFingerprint:appID withVersion:appIDVersion]) {
631+
if (![self validateBundleIDHashWithinAppID:appID forVersion:appIDVersion]) {
631632
return NO;
632633
}
633634

@@ -643,7 +644,7 @@ + (NSString *)actualBundleID {
643644
* The version must end in ":".
644645
*
645646
* For v1 app ids the format is expected to be
646-
* '<version #>:<project number>:ios:<fingerprint of bundle id>'.
647+
* '<version #>:<project number>:ios:<hashed bundle id>'.
647648
*
648649
* This method does not verify that the contents of the app id are correct, just that they fulfill
649650
* the expected format.
@@ -661,36 +662,36 @@ + (BOOL)validateAppIDFormat:(NSString *)appID withVersion:(NSString *)version {
661662
stringScanner.charactersToBeSkipped = nil;
662663

663664
// Skip version part
664-
// '*<version #>*:<project number>:ios:<fingerprint of bundle id>'
665+
// '*<version #>*:<project number>:ios:<hashed bundle id>'
665666
if (![stringScanner scanString:version intoString:NULL]) {
666667
// The version part is missing or mismatched
667668
return NO;
668669
}
669670

670671
// Validate version part (see part between '*' symbols below)
671-
// '<version #>*:*<project number>:ios:<fingerprint of bundle id>'
672+
// '<version #>*:*<project number>:ios:<hashed bundle id>'
672673
if (![stringScanner scanString:@":" intoString:NULL]) {
673674
// appIDVersion must be separated by ":"
674675
return NO;
675676
}
676677

677678
// Validate version part (see part between '*' symbols below)
678-
// '<version #>:*<project number>*:ios:<fingerprint of bundle id>'.
679+
// '<version #>:*<project number>*:ios:<hashed bundle id>'.
679680
NSInteger projectNumber = NSNotFound;
680681
if (![stringScanner scanInteger:&projectNumber]) {
681682
// NO project number found.
682683
return NO;
683684
}
684685

685686
// Validate version part (see part between '*' symbols below)
686-
// '<version #>:<project number>*:*ios:<fingerprint of bundle id>'.
687+
// '<version #>:<project number>*:*ios:<hashed bundle id>'.
687688
if (![stringScanner scanString:@":" intoString:NULL]) {
688689
// The project number must be separated by ":"
689690
return NO;
690691
}
691692

692693
// Validate version part (see part between '*' symbols below)
693-
// '<version #>:<project number>:*ios*:<fingerprint of bundle id>'.
694+
// '<version #>:<project number>:*ios*:<hashed bundle id>'.
694695
NSString *platform;
695696
if (![stringScanner scanUpToString:@":" intoString:&platform]) {
696697
return NO;
@@ -702,57 +703,57 @@ + (BOOL)validateAppIDFormat:(NSString *)appID withVersion:(NSString *)version {
702703
}
703704

704705
// Validate version part (see part between '*' symbols below)
705-
// '<version #>:<project number>:ios*:*<fingerprint of bundle id>'.
706+
// '<version #>:<project number>:ios*:*<hashed bundle id>'.
706707
if (![stringScanner scanString:@":" intoString:NULL]) {
707708
// The platform must be separated by ":"
708709
return NO;
709710
}
710711

711712
// Validate version part (see part between '*' symbols below)
712-
// '<version #>:<project number>:ios:*<fingerprint of bundle id>*'.
713-
unsigned long long fingerprint = NSNotFound;
714-
if (![stringScanner scanHexLongLong:&fingerprint]) {
715-
// Fingerprint part is missing
713+
// '<version #>:<project number>:ios:*<hashed bundle id>*'.
714+
unsigned long long bundleIDHash = NSNotFound;
715+
if (![stringScanner scanHexLongLong:&bundleIDHash]) {
716+
// Hashed bundleID part is missing
716717
return NO;
717718
}
718719

719720
if (!stringScanner.isAtEnd) {
720-
// There are not allowed characters in the fingerprint part
721+
// There are not allowed characters in the hashed bundle ID part
721722
return NO;
722723
}
723724

724725
return YES;
725726
}
726727

727728
/**
728-
* Validates that the fingerprint of the app ID string is what is expected based on the supplied
729-
* version.
729+
* Validates that the hashed bundle ID included in the app ID string is what is expected based on
730+
* the supplied version.
730731
*
731732
* Note that the v1 hash algorithm is not permitted on the client and cannot be fully validated.
732733
*
733734
* @param appID Contents of GOOGLE_APP_ID from the plist file.
734735
* @param version Indicates what version of the app id format this string should be.
735-
* @return YES if provided string fufills the expected fingerprint and the version is known, NO
736+
* @return YES if provided string fufills the expected hashed bundle ID and the version is known, NO
736737
* otherwise.
737738
*/
738-
+ (BOOL)validateAppIDFingerprint:(NSString *)appID withVersion:(NSString *)version {
739-
// Extract the supplied fingerprint from the supplied app ID.
740-
// This assumes the app ID format is the same for all known versions below. If the app ID format
741-
// changes in future versions, the tokenizing of the app ID format will need to take into account
742-
// the version of the app ID.
739+
+ (BOOL)validateBundleIDHashWithinAppID:(NSString *)appID forVersion:(NSString *)version {
740+
// Extract the hashed bundle ID from the given app ID.
741+
// This assumes the app ID format is the same for all known versions below.
742+
// If the app ID format changes in future versions, the tokenizing of the app
743+
// ID format will need to take into account the version of the app ID.
743744
NSArray *components = [appID componentsSeparatedByString:@":"];
744745
if (components.count != 4) {
745746
return NO;
746747
}
747748

748-
NSString *suppliedFingerprintString = components[3];
749-
if (!suppliedFingerprintString.length) {
749+
NSString *suppliedBundleIDHashString = components[3];
750+
if (!suppliedBundleIDHashString.length) {
750751
return NO;
751752
}
752753

753-
uint64_t suppliedFingerprint;
754-
NSScanner *scanner = [NSScanner scannerWithString:suppliedFingerprintString];
755-
if (![scanner scanHexLongLong:&suppliedFingerprint]) {
754+
uint64_t suppliedBundleIDHash;
755+
NSScanner *scanner = [NSScanner scannerWithString:suppliedBundleIDHashString];
756+
if (![scanner scanHexLongLong:&suppliedBundleIDHash]) {
756757
return NO;
757758
}
758759

FirebaseCore/Tests/Unit/FIRAppTest.m

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ + (BOOL)writeString:(NSString *)string toURL:(NSURL *)filePathURL;
5555
+ (void)logAppInfo:(NSNotification *)notification;
5656
+ (BOOL)validateAppID:(NSString *)appID;
5757
+ (BOOL)validateAppIDFormat:(NSString *)appID withVersion:(NSString *)version;
58-
+ (BOOL)validateAppIDFingerprint:(NSString *)appID withVersion:(NSString *)version;
58+
+ (BOOL)validateBundleIDHashWithinAppID:(NSString *)appID forVersion:(NSString *)version;
5959

6060
+ (nullable NSNumber *)readDataCollectionSwitchFromPlist;
6161
+ (nullable NSNumber *)readDataCollectionSwitchFromUserDefaultsForApp:(FIRApp *)app;
@@ -423,33 +423,34 @@ - (void)testOptionsLocking {
423423
#pragma mark - App ID v1
424424

425425
- (void)testAppIDV1 {
426-
// Missing separator between platform:fingerprint.
426+
// Missing separator between platform:hashed bundle ID.
427427
XCTAssertFalse([FIRApp validateAppID:@"1:1337:iosdeadbeef"]);
428428

429429
// Wrong platform "android".
430430
XCTAssertFalse([FIRApp validateAppID:@"1:1337:android:deadbeef"]);
431431

432-
// The fingerprint, aka 4th field, should only contain hex characters.
432+
// The hashed bundle ID, aka 4th field, should only contain hex characters.
433433
XCTAssertFalse([FIRApp validateAppID:@"1:1337:ios:123abcxyz"]);
434434

435-
// The fingerprint, aka 4th field, is not tested in V1, so a bad value shouldn't cause a failure.
435+
// The hashed bundle ID, aka 4th field, is not tested in V1, so a bad value shouldn't cause a
436+
// failure.
436437
XCTAssertTrue([FIRApp validateAppID:@"1:1337:ios:deadbeef"]);
437438
}
438439

439440
#pragma mark - App ID v2
440441

441442
- (void)testAppIDV2 {
442-
// Missing separator between platform:fingerprint.
443+
// Missing separator between platform:hashed bundle ID.
443444
XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios5e18052ab54fbfec"]);
444445

445446
// Unknown versions may contain anything.
446447
XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:123abcxyz"]);
447448
XCTAssertTrue([FIRApp validateAppID:@"2:thisdoesn'teven_m:a:t:t:e:r_"]);
448449

449-
// Known good fingerprint.
450+
// Known good hashed bundle ID.
450451
XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:5e18052ab54fbfec"]);
451452

452-
// Unknown fingerprint, not tested so shouldn't cause a failure.
453+
// Unknown hashed bundle ID, not tested so shouldn't cause a failure.
453454
XCTAssertTrue([FIRApp validateAppID:@"2:1337:ios:deadbeef"]);
454455
}
455456

@@ -571,36 +572,36 @@ - (void)testAppIDFormatInvalid {
571572
XCTAssertFalse([FIRApp validateAppIDFormat:@"1:1337:ios:deadbeef:ab" withVersion:kGoodVersionV1]);
572573
}
573574

574-
- (void)testAppIDFingerprintInvalid {
575+
- (void)testAppIDContainsInvalidBundleIDHash {
575576
OCMStub([self.appClassMock actualBundleID]).andReturn(@"com.google.bundleID");
576-
// Some direct tests of the validateAppIDFingerprint:withVersion: method.
577+
// Some direct tests of the validateBundleIDHashWithinAppID:forVersion: method.
577578
// Sanity checks first.
578579
NSString *const kGoodAppIDV1 = @"1:1337:ios:deadbeef";
579580
NSString *const kGoodVersionV1 = @"1";
580-
XCTAssertTrue([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:kGoodVersionV1]);
581+
XCTAssertTrue([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:kGoodVersionV1]);
581582

582583
NSString *const kGoodAppIDV2 = @"2:1337:ios:5e18052ab54fbfec";
583584
NSString *const kGoodVersionV2 = @"2";
584585
XCTAssertTrue([FIRApp validateAppIDFormat:kGoodAppIDV2 withVersion:kGoodVersionV2]);
585586

586587
// Nil or empty strings.
587-
XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:nil]);
588-
XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:@""]);
589-
XCTAssertFalse([FIRApp validateAppIDFingerprint:nil withVersion:kGoodVersionV1]);
590-
XCTAssertFalse([FIRApp validateAppIDFingerprint:@"" withVersion:kGoodVersionV1]);
591-
XCTAssertFalse([FIRApp validateAppIDFingerprint:nil withVersion:nil]);
592-
XCTAssertFalse([FIRApp validateAppIDFingerprint:@"" withVersion:@""]);
588+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:nil]);
589+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:@""]);
590+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:nil forVersion:kGoodVersionV1]);
591+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:@"" forVersion:kGoodVersionV1]);
592+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:nil forVersion:nil]);
593+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:@"" forVersion:@""]);
593594

594595
// App ID contains only the version prefix.
595-
XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodVersionV1 withVersion:kGoodVersionV1]);
596+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodVersionV1 forVersion:kGoodVersionV1]);
596597
// The version is the entire app ID.
597-
XCTAssertFalse([FIRApp validateAppIDFingerprint:kGoodAppIDV1 withVersion:kGoodAppIDV1]);
598+
XCTAssertFalse([FIRApp validateBundleIDHashWithinAppID:kGoodAppIDV1 forVersion:kGoodAppIDV1]);
598599
}
599600

600601
// Uncomment if you need to measure performance of [FIRApp validateAppID:].
601602
// It is commented because measures are heavily dependent on a build agent configuration,
602603
// so it cannot produce reliable resault on CI
603-
//- (void)testAppIDFingerprintPerfomance {
604+
//- (void)testAppIDValidationPerfomance {
604605
// [self measureBlock:^{
605606
// for (NSInteger i = 0; i < 100; ++i) {
606607
// [self testAppIDPrefix];

0 commit comments

Comments
 (0)